forked from pfmephisto/ReUseX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
339 lines (260 loc) · 8.84 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
cmake_minimum_required(VERSION 3.8)
project(linkml)
set(LIB_PROJECT_NAME "${PROJECT_NAME}_lib")
set(PYBIND_PROJECT_NAME "${PROJECT_NAME}_py")
set(TEST_PROJECT_NAME "${PROJECT_NAME}_test")
# ===============================================
# global settings
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
option(CXX "enable C++ compilation" ON)
if(CXX)
enable_language(CXX)
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# ===============================================
# options
option(LIN_ENABLE_ASAN "if true, enables clang/MSVC address sanitizer" OFF)
option(LIN_ENABLE_MSAN "if true, enables clang/MSVC memory sanitizer" OFF)
option(LIN_ENABLE_UBSAN "if true, enables clang/MSVC undefined behaviour sanitizer" OFF)
option(LIN_ENABLE_TSAN "if true, enables clang/MSVC thread sanitizer" OFF)
option(OPENMP, "if true, enables ")
if (LIN_ENABLE_ASAN AND LIN_ENABLE_TSAN)
message(FATAL_ERROR "Can only enable one of TSan or ASan at a time")
endif()
if (LIN_ENABLE_ASAN AND LIN_ENABLE_MSAN)
message(FATAL_ERROR "Can only enable one of ASan or MSan at a time")
endif()
option(LIN_ENABLE_WERROR "if true, enables -Werror, /WX" OFF)
# enable tests
option(LINKML_SAMPLES_TESTS "if true, builds linkml tests" ON)
# ===============================================
# compiler and linker flags
set(COMMON_COMPILER_FLAGS "")
set(COMMON_LINKER_FLAGS "")
if (MSVC)
list(APPEND COMMON_COMPILER_FLAGS /MP)
list(APPEND COMMON_COMPILER_FLAGS /openmp)
if (LIN_ENABLE_WERROR)
list(APPEND COMMON_COMPILER_FLAGS /WX)
endif()
else()
list(APPEND COMMON_COMPILER_FLAGS -Wall -Wextra)
# Add support for OpenMP
list(APPEND COMMON_COMPILER_FLAGS -fopenmp -lgomp)
if (LIN_ENABLE_WERROR)
list(APPEND COMMON_COMPILER_FLAGS -Werror)
endif()
if (LIN_ENABLE_ASAN OR LIN_ENABLE_TSAN OR LIN_ENABLE_MSAN OR LIN_ENABLE_UBSAN)
list(APPEND COMMON_COMPILER_FLAGS -fno-omit-frame-pointer -g)
list(APPEND COMMON_LINKER_FLAGS -fno-omit-frame-pointer -g)
endif()
if (LIN_ENABLE_ASAN)
list(APPEND COMMON_COMPILER_FLAGS -fsanitize=address)
list(APPEND COMMON_LINKER_FLAGS -fsanitize=address)
endif()
if (LIN_ENABLE_TSAN)
list(APPEND COMMON_COMPILER_FLAGS -fsanitize=thread)
list(APPEND COMMON_LINKER_FLAGS -fsanitize=thread)
endif()
if (LIN_ENABLE_MSAN)
list(APPEND COMMON_COMPILER_FLAGS -fsanitize=memory)
list(APPEND COMMON_LINKER_FLAGS -fsanitize=memory)
endif()
if (LIN_ENABLE_UBSAN)
list(APPEND COMMON_COMPILER_FLAGS
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-sanitize=alignment,vptr
)
list(APPEND COMMON_LINKER_FLAGS
-fsanitize=undefined
-fno-sanitize-recover=all
-fno-sanitize=alignment,vptr
)
endif()
endif()
# ===============================================
# Bin dir
if(MSVC)
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin)
elseif(CMAKE_BUILD_TYPE STREQUAL "")
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin/Default)
else()
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BIN_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${BIN_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BIN_DIR})
# Set CMAKE_POSITION_INDEPENDENT_CODE to ON
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#set(GLOW_BIN_DIR ${CMAKE_SOURCE_DIR}/bin)
# REMOVED: this is not needed anymore
set(CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE On)
# ===============================================
# find packages
find_package( OpenCV REQUIRED )
if (OpenCV_FOUND)
message(STATUS "Using OpenCV - ${OpenCV_VERSION} - ${OpenCV_INCLUDE_DIRS}")
set("OPENCV_LOG_LEVEL" "WARNING")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})
add_definitions(${OpenCV_DEFINITIONS})
endif()
# CGAL and its components
find_package(CGAL REQUIRED)
# Boost and its components
find_package(Boost REQUIRED)
if(NOT Boost_FOUND)
message(
STATUS
"NOTICE: This project requires the Boost library, and will not be compiled."
)
return()
endif()
find_package(Eigen3 3.3 REQUIRED) #(requires 3.1.0 or greater)
include(CGAL_Eigen3_support)
if(NOT TARGET CGAL::Eigen3_support)
message(
STATUS
"NOTICE: This project requires Eigen 3.1 (or greater) and will not be compiled."
)
return()
endif()
find_package( TBB REQUIRED )
include(CGAL_TBB_support)
find_package(SCIP REQUIRED)
include(CGAL_SCIP_support)
find_package(embree 3.12.2 REQUIRED)
IF (EMBREE_ISPC_SUPPORT)
OPTION(ENABLE_ISPC_SUPPORT "Build ISPC version of find_embree tutorial." OFF)
# this configures the ADD_EMBREE_ISPC_EXECUTABLE from Embree
IF (ENABLE_ISPC_SUPPORT)
SET(ISPC_TARGETS "sse2;sse4;avx;avx2")
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../common/cmake" ${CMAKE_MODULE_PATH})
INCLUDE(ispc)
get_target_property(embree_include_dir embree INTERFACE_INCLUDE_DIRECTORIES)
INCLUDE_DIRECTORIES_ISPC(${embree_include_dir})
ADD_EMBREE_ISPC_EXECUTABLE(find_embree_ispc find_embree_ispc.cpp find_embree_ispc.ispc)
TARGET_LINK_LIBRARIES(find_embree_ispc embree)
ENDIF()
ENDIF()
find_package(GUROBI REQUIRED)
if (GUROBI_FOUND)
message(STATUS "Using Gurobi Solver")
add_compile_definitions(CGAL_USE_GUROBI=1)
include_directories(${GUROBI_INCLUDE_DIRS})
endif()
find_package(PCL REQUIRED PATHS /usr/local NO_DEFAULT_PATH)
if(PCL_FOUND)
message(STATUS "Using PCL - ${PCL_VERSION}")
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
endif()
# list(APPEND CMAKE_MODULE_PATH "./cmake/FindHDF5.cmake") # Replaces the bundled FindHDF5.cmake module
# find_package(HDF5 1.10 COMPONENTS C HL)
# ===============================================
# add submodules
add_subdirectory(extern/clean-core)
add_subdirectory(extern/ctracer)
add_subdirectory(extern/fmt)
add_subdirectory(extern/nexus)
add_subdirectory(extern/polymesh)
add_subdirectory(extern/polyscope)
add_subdirectory(extern/pybind11)
add_subdirectory(extern/reflector)
add_subdirectory(extern/rich-log)
add_subdirectory(extern/typed-geometry)
# ===============================================
# configure executable
file(GLOB_RECURSE LIB_SOURCES
"src/*.cc"
"src/*.cpp"
)
file(GLOB_RECURSE LIB_HEADERS
"src/*.hh"
)
list(FILTER LIB_SOURCES EXCLUDE REGEX ".*py.cpp")
# group sources according to folder structure
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${LIB_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${LIB_HEADERS})
## ===============================================
## add executable
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_library(${LIB_PROJECT_NAME} STATIC ${LIB_SOURCES} ${LIB_HEADERS})
set_target_properties(${LIB_PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
target_link_libraries(${LIB_PROJECT_NAME}
PRIVATE
pybind11::embed
optimized ${GUROBI_CXX_LIBRARY}
debug ${GUROBI_CXX_DEBUG_LIBRARY}
# HDF5::HDF5
)
target_link_libraries(${LIB_PROJECT_NAME} PUBLIC
clean-core
typed-geometry
ctracer
reflector
rich-log
polymesh
polyscope
embree
Eigen3::Eigen3
CGAL::Eigen3_support
CGAL::SCIP_support
CGAL::TBB_support
${GUROBI_LIBRARY}
${PCL_LIBRARIES}
${PCL_COMMON_LIBRARIES}
fmt
nexus
${OpenCV_LIBS}
${COMMON_LINKER_FLAGS}
)
# dependency grouping in the IDE
foreach(TARGET_NAME
clean-core
typed-geometry
ctracer
reflector
rich-log
polymesh
polyscope
)
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "Extern")
endforeach()
# ===============================================
# main libary
target_include_directories(${LIB_PROJECT_NAME} PUBLIC "src")
target_compile_options(${LIB_PROJECT_NAME} PUBLIC ${COMMON_COMPILER_FLAGS})
# ===============================================
# pyind11
pybind11_add_module("${PYBIND_PROJECT_NAME}" src/linkmlpy.cpp)
target_link_libraries("${PYBIND_PROJECT_NAME}" PRIVATE ${LIB_PROJECT_NAME})
# ===============================================
# tests
if (LINKML_SAMPLES_TESTS)
file(GLOB_RECURSE TEST_SOURCES
"tests/*.cc"
"tests/*.hh"
)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${TEST_SOURCES})
add_executable("${TEST_PROJECT_NAME}" ${TEST_SOURCES})
target_link_libraries("${TEST_PROJECT_NAME}" PUBLIC
${LIB_PROJECT_NAME}
nexus
)
target_include_directories("${TEST_PROJECT_NAME}" PUBLIC "tests")
if(MSVC)
target_compile_options("${TEST_PROJECT_NAME}" PUBLIC /MP /FC)
else()
target_compile_options("${TEST_PROJECT_NAME}" PUBLIC -Wall)
endif()
endif()