-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
301 lines (264 loc) · 8.59 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
cmake_minimum_required(VERSION 3.11.0)
cmake_policy(SET CMP0015 NEW) # Link Directory Pathing
set(CMAKE_DEBUG_POSTFIX _d)
project(xmscorelib C CXX)
set(BUILD_TESTING NO CACHE BOOL "Enable/Disable testing")
set(IS_CONDA_BUILD NO CACHE BOOL "Set this if you want to make a conda package.")
set(IS_EMSCRIPTEN_BUILD NO CACHE BOOL "Set this to build with emscripten using cmake.")
set(XMS_BUILD NO CACHE BOOL "Set this if you want to use this package with XMS.")
set(PYTHON_TARGET_VERSION 3.10 CACHE STRING "Version of python to link to for python wrapping.")
set(IS_PYTHON_BUILD NO CACHE BOOL "Set this if you want to build the python bindings.")
set(XMS_TEST_PATH ${PROJECT_SOURCE_DIR}/test_files/ CACHE PATH "Path to test files for testing")
set(XMS_VERSION "99.99.99" CACHE STRING "Library Version")
if (APPLE OR WIN32 OR IS_EMSCRIPTEN_BUILD)
# Target C++17 on MacOS and Windows. If building with version of Visual Studio without
# support, has no effect.
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 11)
endif()
if (APPLE)
set(CMAKE_POSITION_INDEPENDENT_CODE False)
add_compile_definitions(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
else()
set(CMAKE_POSITION_INDEPENDENT_CODE True)
endif()
if(IS_PYTHON_BUILD AND BUILD_TESTING)
message(FATAL_ERROR "Cannot build python module when testing is enabled")
endif()
add_definitions(-DXMS_VERSION=\"${XMS_VERSION}\")
if(IS_CONDA_BUILD)
include(${CMAKE_CURRENT_LIST_DIR}/condabuildinfo.cmake)
elseif(IS_EMSCRIPTEN_BUILD)
include(${CMAKE_CURRENT_LIST_DIR}/emscriptenbuildinfo.cmake)
else() # If we are not using conda or emscripten, we are using conan
# C++11 Support
# Conan setup
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(EXT_INCLUDE_DIRS ${CONAN_INCLUDE_DIRS})
set(EXT_LIB_DIRS ${CONAN_LIB_DIRS})
set(EXT_LIBS ${CONAN_LIBS})
ENDIF(IS_CONDA_BUILD)
if(WIN32)
string(COMPARE EQUAL "${CONAN_SETTINGS_COMPILER_RUNTIME}" "MT" USES_MT)
if(NOT USES_MT)
string(COMPARE EQUAL "${CONAN_SETTINGS_COMPILER_RUNTIME}" "MTd" USES_MT)
endif()
if(USE_TYPEDEF_WCHAR_T)
add_definitions(/Zc:wchar_t-) # Treat wchar_t as a typedef
endif()
add_definitions(/D BOOST_ALL_NO_LIB)
if(USES_MT)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
endif()
message(STATUS "External Include Dirs: ${EXT_INCLUDE_DIRS}")
message(STATUS "External Lib Dirs: ${EXT_LIB_DIRS}")
message(STATUS "Extneral Libs: ${EXT_LIBS}")
if(IS_PYTHON_BUILD)
# Pybind11 module
if(IS_CONDA_BUILD)
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Tools.cmake")
else()
list(APPEND CMAKE_MODULE_PATH "${CONAN_PYBIND11_ROOT}/share/cmake/pybind11")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Tools.cmake")
endif()
list(APPEND EXT_INCLUDE_DIRS
${pybind11_INCLUDE_DIR}
)
find_package(PythonLibsNew ${PYTHON_TARGET_VERSION} EXACT REQUIRED)
# Have to add this after conda because it doesn't get the path for pybind if we don't.
list(APPEND EXT_INCLUDE_DIRS
${PYTHON_INCLUDE_DIRS}
)
endif()
message("External Lib Includes: ${EXT_INCLUDE_DIRS}")
include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${EXT_INCLUDE_DIRS})
link_directories(${EXT_LIB_DIRS})
# Sources
set(xmscore_sources
xmscore/dataio/daStreamIo.cpp
xmscore/math/math.cpp
xmscore/misc/DynBitset.cpp
xmscore/misc/HeaderCheck.cpp
xmscore/misc/Observer.cpp
xmscore/misc/Progress.cpp
xmscore/misc/Singleton.cpp
xmscore/misc/StringUtil.cpp
xmscore/misc/XmError.cpp
xmscore/misc/XmLog.cpp
xmscore/points/functors.cpp
xmscore/points/pt.cpp
xmscore/stl/vector.cpp
xmscore/time/TimeConversion.cpp)
set(xmscore_headers
xmscore/dataio/daStreamIo.h
xmscore/math/math.h
xmscore/misc/base_macros.h
xmscore/misc/boost_defines.h
xmscore/misc/carray.h
xmscore/misc/color_defines.h
xmscore/misc/DynBitset.h
xmscore/misc/environment.h
xmscore/misc/Observer.h
xmscore/misc/Progress.h
xmscore/misc/Singleton.h
xmscore/misc/StringUtil.h
xmscore/misc/XmConst.h
xmscore/misc/XmError.h
xmscore/misc/XmLog.h
xmscore/misc/xmstype.h
xmscore/points/functors.h
xmscore/points/pt.h
xmscore/points/ptsfwd.h
xmscore/stl/deque.h
xmscore/stl/list.h
xmscore/stl/map.h
xmscore/stl/set.h
xmscore/stl/utility.h
xmscore/stl/vector.h
xmscore/time/TimeConversion.h)
# Tests
if(BUILD_TESTING)
add_definitions(-DXMS_TEST_PATH="${XMS_TEST_PATH}/")
add_definitions(-DCXX_TEST -DCXXTEST4)
list(APPEND xmscore_headers
xmscore/dataio/daStreamIo.t.h
xmscore/math/math.t.h
xmscore/misc/Observer.t.h
xmscore/misc/Progress.t.h
xmscore/misc/StringUtil.t.h
xmscore/misc/XmError.t.h
xmscore/misc/XmLog.t.h
xmscore/points/functors.t.h
xmscore/points/pt.t.h
xmscore/time/TimeConversion.t.h
xmscore/testing/TestTools.h
)
list(APPEND xmscore_sources
xmscore/testing/TestTools.cpp
)
find_package(CxxTest)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIRS})
enable_testing()
set(CXXTEST_TESTGEN_ARGS --xunit-printer)
file(GLOB_RECURSE test_headers ${CMAKE_CURRENT_LIST_DIR}/xmscore/*.t.h)
CXXTEST_ADD_TEST(
runner runner.cpp ${test_headers}
)
target_link_libraries(runner ${PROJECT_NAME})
if(WIN32)
set(RUNNERNAME "runner.exe")
else()
set(RUNNERNAME "runner")
endif()
endif()
endif()
if(IS_PYTHON_BUILD)
list(APPEND xmscore_sources
xmscore/python/misc/PyUtils.cpp
)
list(APPEND xmscore_headers
xmscore/python/misc/PyUtils.h
)
endif()
# Static library
add_library(${PROJECT_NAME} STATIC
${xmscore_sources} ${xmscore_headers}
)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME}
${EXT_LIBS}
)
target_link_libraries(${PROJECT_NAME}
${CMAKE_THREAD_LIBS_INIT}
)
if(UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_NAME} rt)
endif()
#Pybind11
if(IS_PYTHON_BUILD)
# Pybind11 sources
set(xmscore_py
xmscore/python/xmscore_py.cpp
# Misc
xmscore/python/misc/detail/Listener.cpp
xmscore/python/misc/detail/PublicProgressListener.cpp
xmscore/python/misc/misc_py.cpp
xmscore/python/misc/observer_py.cpp
xmscore/python/misc/PyUtils.cpp
xmscore/python/misc/progress_listener_py.cpp
xmscore/python/time/time_py.cpp
xmscore/python/time/TimeConversion_py.cpp
)
set(xmscore_py_headers
xmscore/python/misc/detail/Listener.h
xmscore/python/misc/misc_py.h
xmscore/python/misc/PyUtils.h
xmscore/python/misc/PublicObserver.h
xmscore/python/misc/PublicProgressListener.h
xmscore/python/misc/PyObserver.h
xmscore/python/misc/PyProgressListener.h
xmscore/python/time/time_py.h
)
message(STATUS "PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS}")
message(STATUS "PYTHON_LIBS: ${PYTHON_LIBRARIES}")
pybind11_add_module(_xmscore
${xmscore_py} ${xmscore_py_headers}
)
target_include_directories(_xmscore
PRIVATE
${EXT_INCLUDE_DIRS}
)
target_link_libraries(_xmscore
PRIVATE
${EXT_LIBS}
${PROJECT_NAME}
)
set_target_properties(_xmscore PROPERTIES
LINKER_LANGUAGE CXX
)
# Install recipe
install(
TARGETS _xmscore
ARCHIVE DESTINATION "_package/xms/core"
LIBRARY DESTINATION "_package/xms/core"
)
install(DIRECTORY "_package/" DESTINATION "_package"
FILES_MATCHING PATTERN "*.py"
PATTERN "_package/tests" EXCLUDE)
endif()
# Install recipe
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
foreach (header IN LISTS xmscore_headers xmscore_py_headers)
get_filename_component(subdir "${header}" DIRECTORY)
install(
FILES "${header}"
DESTINATION "include/${subdir}"
)
endforeach ()