-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
130 lines (108 loc) · 3.48 KB
/
CMakeLists.txt
File metadata and controls
130 lines (108 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
cmake_minimum_required(VERSION 3.12)
include(CMakePackageConfigHelpers)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
project(codegen VERSION 0.1.0)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_library(codegen INTERFACE)
target_compile_definitions(
codegen
INTERFACE
WITH_CODEGEN
)
target_include_directories(
codegen
INTERFACE
# Add source include files to target's interface include directories for projects using add_subdirectory()
$<BUILD_INTERFACE:${codegen_SOURCE_DIR}/include>
)
set(setup_command_args "")
list(APPEND setup_command_args
"${Python3_EXECUTABLE}" "${codegen_SOURCE_DIR}/setup.py" "sdist" "-d" "${codegen_BINARY_DIR}/dist"
)
set(package_file_name "codegen-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.tar.gz")
set(package_file "${codegen_BINARY_DIR}/dist/${package_file_name}")
add_custom_target(
codegen_sdist
ALL
COMMAND
${setup_command_args}
WORKING_DIRECTORY
"${codegen_SOURCE_DIR}"
)
add_dependencies(codegen codegen_sdist)
#
# If we're told to, make install targets
#
option(CODEGEN_GENERATE_INSTALL_TARGETS "Make codegen install targets" ON)
if (CODEGEN_GENERATE_INSTALL_TARGETS)
# Install the CMake Module
install(
DIRECTORY "${codegen_SOURCE_DIR}/cmake"
DESTINATION "share"
)
# Install the python package
install(
FILES "${package_file}"
DESTINATION "share/codegen/"
)
# Install the project headers
install(
DIRECTORY "${codegen_SOURCE_DIR}/include/codegen"
DESTINATION include
)
set(version_config_file "${codegen_BINARY_DIR}/codegenConfigVersion.cmake")
set(config_file "${codegen_BINARY_DIR}/codegenConfig.cmake")
set(config_install_dir "lib/cmake/codegen")
# Associate target with export
install(
TARGETS codegen
EXPORT codegenTargets
INCLUDES DESTINATION include # Added to INTERFACE_INCLUDE_DIRECTORIES
)
# Install the target config files
install(
EXPORT codegenTargets
NAMESPACE "codegen::"
DESTINATION "${config_install_dir}"
)
# Generate version config file
write_basic_package_version_file(
"${version_config_file}"
COMPATIBILITY SameMajorVersion
)
# Generate config file
configure_package_config_file(
"Config.cmake.in"
"${config_file}"
INSTALL_DESTINATION "lib/cmake/codegen"
)
# Install the config files
install(
FILES "${config_file}" "${version_config_file}"
DESTINATION ${config_install_dir}
)
endif()
#
# If we're told to, build the python package at configure time
#
if (CODEGEN_BUILD_PACKAGE_DURING_CONFIGURE)
message(STATUS "Building CodeGen Package")
execute_process(
COMMAND
${setup_command_args}
WORKING_DIRECTORY
"${codegen_SOURCE_DIR}"
RESULT_VARIABLE setup_result
)
if (NOT setup_result EQUAL 0)
message(FATAL_ERROR "Failed to setup CodeGen package during configure time")
endif()
# Copy the built package to a place we can easily find it from parent projects
file(COPY "${package_file}" DESTINATION "${codegen_BINARY_DIR}")
file(RENAME "${codegen_BINARY_DIR}/${package_file_name}" "${codegen_BINARY_DIR}/codegen.tar.gz")
set(CODEGEN_PACKAGE "${codegen_BINARY_DIR}/codegen.tar.gz" CACHE FILEPATH "")
endif()
# Include module functions for the parent project as well
include(cmake/Modules/codegen.cmake)