-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
224 lines (193 loc) · 7.14 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
cmake_minimum_required(VERSION 3.11.0)
cmake_policy(SET CMP0015 NEW) # Link Directory Pathing
set(CMAKE_DEBUG_POSTFIX _d)
if (APPLE OR WIN32)
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()
project(xmsextractorlib 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(PYTHON_TARGET_VERSION 3.10 CACHE STRING "Version of python to link to for python wrapping.")
set(CONDA_PREFIX "" CACHE PATH "Path to the conda environment used to build.")
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")
add_definitions(-DXMS_VERSION=\"${XMS_VERSION}\")
if(IS_CONDA_BUILD)
include(${CMAKE_CURRENT_LIST_DIR}/condabuildinfo.cmake)
else() # If we are not using conda, we are using conan
# 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)
if(USE_TYPEDEF_WCHAR_T)
message("Treating wchar_t as a typedef.")
add_definitions(/Zc:wchar_t-)
else()
message("Treating wchar_t as a built-in type.")
add_definitions(/Zc:wchar_t)
endif()
add_definitions(/D BOOST_ALL_NO_LIB)
endif()
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)
message("PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS}")
message("PYTHON_LIBS: ${PYTHON_LIBRARIES}")
list(APPEND EXT_INCLUDE_DIRS
${PYTHON_INCLUDE_DIRS}
)
endif()
message("External Include Dirs: ${EXT_INCLUDE_DIRS}")
message("External Lib Dirs: ${EXT_LIB_DIRS}")
message("Extneral Libs: ${EXT_LIBS}")
include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${EXT_INCLUDE_DIRS})
link_directories(${EXT_LIB_DIRS})
# Static library sources
set(xmsextractor_sources
xmsextractor/extractor/XmUGrid2dDataExtractor.cpp
xmsextractor/extractor/XmUGrid2dPolylineDataExtractor.cpp
xmsextractor/ugrid/XmElementEdge.cpp
xmsextractor/ugrid/XmUGridTriangles2d.cpp
xmsextractor/ugrid/XmUGridTriangulator.cpp
xmsextractor/ugrid/XmUGridTriangulatorBase.cpp
)
set(xmsextractor_headers
xmsextractor/extractor/XmUGrid2dDataExtractor.h
xmsextractor/extractor/XmUGrid2dPolylineDataExtractor.h
xmsextractor/ugrid/XmElementEdge.h
xmsextractor/ugrid/XmElementMidpointInfo.h
xmsextractor/ugrid/XmUGridTriangles2d.h
xmsextractor/ugrid/XmUGridTriangulator.h
xmsextractor/ugrid/XmUGridTriangulatorBase.h
)
# Pybind11 sources
set(xmsextractor_py
xmsextractor/python/xmsextractor_py.cpp
#extractor
xmsextractor/python/extractor/extractor_py.cpp
xmsextractor/python/extractor/XmUGrid2dDataExtractor_py.cpp
xmsextractor/python/extractor/XmUGrid2dPolylineDataExtractor_py.cpp
)
set(xmsextractor_py_headers
xmsextractor/python/extractor/extractor_py.h
)
# Tests
if (BUILD_TESTING)
add_definitions(-DXMS_TEST_PATH="${XMS_TEST_PATH}/")
add_definitions(-DCXX_TEST -DCXXTEST4)
list(APPEND xmsextractor_sources
xmsextractor/extractor/XmUGrid2dDataExtractor.t.h
xmsextractor/extractor/XmUGrid2dPolylineDataExtractor.t.h
xmsextractor/ugrid/XmUGridTriangles2d.t.h
)
find_package(CxxTest)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
enable_testing()
set(CXXTEST_TESTGEN_ARGS --xunit-printer --have-eh)
file(GLOB_RECURSE test_headers ${CMAKE_CURRENT_LIST_DIR}/xmsextractor/*.t.h)
CXXTEST_ADD_TEST(
runner runner.cpp ${test_headers}
)
target_link_libraries(runner ${PROJECT_NAME})
endif()
endif ()
# Static library
add_library(${PROJECT_NAME} STATIC
${xmsextractor_sources} ${xmsextractor_headers}
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/>
${Boost_INCLUDE_DIR}
)
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()
if(IS_PYTHON_BUILD)
pybind11_add_module(_xmsextractor
${xmsextractor_py} ${xmsextractor_py_headers}
)
target_include_directories(_xmsextractor
PRIVATE
${EXT_LIBS}
${PYTHON_INCLUDE_DIRS}
)
target_link_libraries(_xmsextractor
PRIVATE
${EXT_LIBS}
${PROJECT_NAME}
)
set_target_properties(_xmsextractor PROPERTIES
LINKER_LANGUAGE CXX
)
# Install recipe
install(
TARGETS _xmsextractor
ARCHIVE DESTINATION "_package/xms/extractor"
LIBRARY DESTINATION "_package/xms/extractor"
)
install(DIRECTORY "_package/" DESTINATION "_package"
FILES_MATCHING PATTERN "*.py"
PATTERN "_package/tests" EXCLUDE)
endif()
# Disable Optimization for GCC6 for now... Report issue to gcc and pybind
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND IS_PYTHON_BUILD)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7)
Message("Disabling Optimization for GCC 6...")
STRING(REPLACE "-O3" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "-O3" "" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
endif()
endif()
# Install recipe
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
foreach (header IN LISTS xmsextractor_headers xmsextractor_py_headers)
get_filename_component(subdir "${header}" DIRECTORY)
install(
FILES "${header}"
DESTINATION "include/${subdir}"
)
endforeach ()