forked from Harvard-Neutrino/SIREN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
257 lines (235 loc) · 8.24 KB
/
CMakeLists.txt
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)
cmake_policy(VERSION 3.3.2)
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()
# point to appropriate cmake file locations
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_CURRENT_LIST_DIR}/cmake/Packages)
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
set(CIBUILDWHEEL $ENV{CIBUILDWHEEL})
message(STATUS "CIBUILDWHEEL: ${CIBUILDWHEEL}")
if(${CIBUILDWHEEL})
set(CI_INSTALL_PREFIX $ENV{CI_INSTALL_PREFIX})
message(STATUS "CI_INSTALL_PREFIX: ${CI_INSTALL_PREFIX}")
endif()
# parse pyproject.toml for the version
include(pyproject)
project(siren VERSION ${SIREN_VERSION} LANGUAGES CXX)
# include cmake dependencies
include(GNUInstallDirs)
include(ExternalProject)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_C_STANDARD 99)
# set the build type and appropriate flags
option(CMAKE_BUILD_TYPE "" "Release")
set(_FLAGS "-O2 -Wall -fPIC")
set(_FLAGS_DEBUG "-g -O0 -Wall -fPIC")
set(_FLAGS_RELEASE "-O2 -Wall -fPIC -s")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(_FLAGS "${_FLAGS} -stdlib=libc++")
set(_FLAGS_DEBUG "${_FLAGS_DEBUG} -stdlib=libc++")
set(_FLAGS_RELEASE "${_FLAGS_RELEASE} -stdlib=libc++")
endif()
set(CMAKE_CXX_FLAGS ${_FLAGS})
set(CMAKE_CXX_FLAGS_DEBUG ${_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_RELEASE ${_FLAGS_RELEASE})
# override install locations when building python extensions
if(DEFINED SKBUILD)
cmake_path(RELATIVE_PATH SKBUILD_HEADERS_DIR BASE_DIRECTORY ${SKBUILD_PLATLIB_DIR} OUTPUT_VARIABLE CMAKE_INSTALL_INCLUDEDIR)
cmake_path(RELATIVE_PATH SKBUILD_PLATLIB_DIR BASE_DIRECTORY ${SKBUILD_PLATLIB_DIR} OUTPUT_VARIABLE CMAKE_INSTALL_LIBDIR)
message(STATUS "Setting include dir to: ${CMAKE_INSTALL_INCLUDEDIR}")
message(STATUS "Setting lib dir to: ${CMAKE_INSTALL_LIBDIR}")
set(SIREN_INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
set(SIREN_INSTALL_LIBDIR ${SKBUILD_PLATLIB_DIR})
else()
set(SIREN_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(SIREN_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
endif()
# load python and pybind11
include(Python)
include(pybind11)
# load project dependencies
include(rk)
include(cereal)
include(delabella)
include(CFITSIO)
include(photospline)
include(googletest)
include(NamedType)
# load macros for googletest
include(testing)
# add individual source folders
add_subdirectory(projects/utilities)
add_subdirectory(projects/serialization)
add_subdirectory(projects/math)
add_subdirectory(projects/dataclasses)
add_subdirectory(projects/geometry)
add_subdirectory(projects/detector)
add_subdirectory(projects/interactions)
add_subdirectory(projects/distributions)
add_subdirectory(projects/injection)
# define the target library
add_library(SIREN SHARED)
set_property(TARGET SIREN PROPERTY POSITION_INDEPENDENT_CODE ON)
if(${MACOSX})
if(CMAKE_VERSION VERSION_LESS 3.13)
target_link_libraries(SIREN PUBLIC "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
else()
target_link_options(SIREN PUBLIC "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
endif()
target_link_libraries(SIREN
PRIVATE
PUBLIC
delabella_shared
photospline
SIREN_utilities
SIREN_serialization
SIREN_math
SIREN_dataclasses
SIREN_geometry
SIREN_detector
SIREN_interactions
SIREN_distributions
SIREN_injection
)
else()
target_link_libraries(SIREN
PRIVATE
PUBLIC
photospline
delabella_shared
SIREN_utilities
SIREN_serialization
SIREN_math
SIREN_dataclasses
SIREN_geometry
SIREN_detector
SIREN_interactions
SIREN_distributions
SIREN_injection
)
endif()
# define the install path normally or for python package
if(DEFINED SKBUILD)
set_target_properties(SIREN PROPERTIES
BUILD_WITH_INSTALL_RPATH FALSE
LINK_FLAGS "-Wl,-rpath,\\\$ORIGIN")
if(${CIBUILDWHEEL})
message(STATUS "Setting SIREN install lib dir to: ${CI_INSTALL_PREFIX}/lib")
message(STATUS "Setting SIREN install include dir to: ${CI_INSTALL_PREFIX}/include")
install(TARGETS SIREN
delabella_shared
SIREN_utilities
SIREN_serialization
SIREN_math
SIREN_dataclasses
SIREN_geometry
SIREN_detector
SIREN_interactions
SIREN_distributions
SIREN_injection
EXPORT ${PROJECT_NAME}Config
LIBRARY DESTINATION "${CI_INSTALL_PREFIX}/lib"
PUBLIC_HEADER DESTINATION "${CI_INSTALL_PREFIX}/include")
else()
install(TARGETS SIREN
delabella_shared
SIREN_utilities
SIREN_serialization
SIREN_math
SIREN_dataclasses
SIREN_geometry
SIREN_detector
SIREN_interactions
SIREN_distributions
SIREN_injection
EXPORT ${PROJECT_NAME}Config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren.libs
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
else()
install(TARGETS SIREN
delabella_shared
SIREN_utilities
SIREN_serialization
SIREN_math
SIREN_dataclasses
SIREN_geometry
SIREN_detector
SIREN_interactions
SIREN_distributions
SIREN_injection
EXPORT ${PROJECT_NAME}Config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
# optionally package runtime dependencies
if((DEFINED SKBUILD) AND (PACKAGE_SHARED_DEPS))
install(CODE "set(SIREN_LIB_FILE \"${PROJECT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}SIREN${CMAKE_SHARED_MODULE_SUFFIX}\")")
install(CODE "set(PYTHON_DEP_LIB_DESTINATION \"${SKBUILD_PLATLIB_DIR}/siren.libs/\")")
install(CODE [[
file(GET_RUNTIME_DEPENDENCIES
LIBRARIES ${SIREN_LIB_FILE}
RESOLVED_DEPENDENCIES_VAR _r_deps
UNRESOLVED_DEPENDENCIES_VAR _u_deps
)
foreach(_file ${_r_deps})
file(INSTALL
DESTINATION "${PYTHON_DEP_LIB_DESTINATION}"
TYPE SHARED_LIBRARY
FOLLOW_SYMLINK_CHAIN
FILES "${_file}"
)
endforeach()
list(LENGTH _u_deps _u_length)
if("${_u_length}" GREATER 0)
message(WARNING "Unresolved dependencies detected!")
endif()
]]
)
endif()
# install the python extensions
if(DEFINED SKBUILD)
install(TARGETS utilities
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS math
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS dataclasses
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS geometry
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS detector
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS interactions
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS distributions
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(TARGETS injection
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/python/
DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/resources
DESTINATION ${CMAKE_INSTALL_LIBDIR}/siren)
endif()
# Export targets for use in downstream CMake projects
# -----------------------------------------------------------------------------
include(CMakePackageConfigHelpers)
# Make importable from build directory
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${PROJECT_NAME}Config FILE ${PROJECT_NAME}Config.cmake)
# Make importable from install location
set(_config_dir share/${PROJECT_NAME}/cmake)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${_config_dir}
)
install(EXPORT ${PROJECT_NAME}Config
DESTINATION ${_config_dir}
)
MESSAGE("")
MESSAGE("Done!")
MESSAGE("Run `make` then `make install`")