-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
222 lines (190 loc) · 6.55 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
cmake_minimum_required(VERSION 3.25.0)
project(gbs LANGUAGES C CXX)
# c++ conf
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if ( MSVC )
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast /arch:AVX512")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast /arch:AVX2")
endif( MSVC )
# Set installation directories (CMAKE_INSTALL_INCLUDEDIR, CMAKE_INSTALL_BINDIR, CMAKE_INSTALL_LIBDIR)
include(GNUInstallDirs)
message("-- CMake install prefix: " ${CMAKE_INSTALL_PREFIX})
message(" -> binaries: " ${CMAKE_INSTALL_BINDIR})
message(" -> libs: " ${CMAKE_INSTALL_LIBDIR})
message(" -> includes: " ${CMAKE_INSTALL_INCLUDEDIR})
link_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
link_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
function(INSTALL_HEADERS REQUIRED_ARG)
# copy headers keeping file structure
string(TOLOWER ${REQUIRED_ARG} inc_sub_dir)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/${inc_sub_dir}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/gbs"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "curves"
PATTERN "surfaces"
PATTERN "cmake" EXCLUDE
PATTERN "tests" EXCLUDE
PATTERN "build*" EXCLUDE
PATTERN "python" EXCLUDE
PATTERN "xml" EXCLUDE
PATTERN "doc" EXCLUDE
PATTERN "recipe" EXCLUDE
PATTERN ".*" EXCLUDE
)
endfunction()
#
# set output dirs (vs is a pain)
#
function(SET_OUT_DIR REQUIRED_ARG)
list(GET ARGV 0 TARGET_NAME)
list(GET ARGV 1 OUT_DIR)
# message(${TARGET_NAME})
# message(${OUT_DIR})
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set_property(TARGET ${TARGET_NAME} PROPERTY RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
set_property(TARGET ${TARGET_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
set_property(TARGET ${TARGET_NAME} PROPERTY ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${OUT_DIR} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
endfunction()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
# Boost
find_package(Boost REQUIRED)
# NLOPT
find_package(NLopt REQUIRED)
# Eigen
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})
# TBB
if(UNIX)
find_package(TBB REQUIRED)
endif()
# libIGES
include_directories(${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/iges/)
# Python Dev
find_package (Python3 COMPONENTS Interpreter Development)
# VTK
find_package(VTK COMPONENTS
CommonCore
CommonColor
CommonDataModel
FiltersSources
FiltersGeneral
InteractionStyle
InteractionWidgets
RenderingCore
RenderingFreeType
RenderingOpenGL2
RenderingAnnotation
ChartsCore
RenderingContext2D
RenderingContextOpenGL2
ViewsContext2D
RenderingGL2PSOpenGL2
IOXML
PythonInterpreter
WrappingPythonCore
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# ill detected
# https://stackoverflow.com/questions/71565682/returning-a-rapidjsongenericvalue-from-a-function
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0")
message(FATAL_ERROR "Insufficient clang version")
endif()
add_definitions(-DRAPIDJSON_HAS_CXX11_RVALUE_REFS)
set(USING_CLANG ON)
endif()
INSTALL_HEADERS(${PROJECT_NAME})
INSTALL_HEADERS("inc")
#Define defaults
if(NOT DEFINED USE_PYTHON_BINDINGS)
set(USE_PYTHON_BINDINGS ON)
message(STATUS "USE_PYTHON_BINDINGS default set to " ${USE_PYTHON_BINDINGS})
endif()
if(NOT DEFINED USE_RENDER)
set(USE_RENDER OFF)
message(STATUS "USE_RENDER default set to " ${USE_RENDER})
endif()
if(NOT DEFINED USE_CUDA)
set(USE_CUDA OFF)
message(STATUS "USE_CUDA default set to " ${USE_CUDA})
endif()
if(NOT DEFINED GBS_BUILD_TESTS)
set(GBS_BUILD_TESTS ON)
message(STATUS "GBS_BUILD_TESTS set to " ${GBS_BUILD_TESTS})
endif()
# Tests
if(${GBS_BUILD_TESTS})
message(STATUS "Configurig tests.")
# Google Tests #
if(DEFINED ENV{CONDA_BUILD} OR DEFINED ENV{PREFIX} OR DEFINED ENV{BUILD_PREFIX} OR DEFINED USING_CLANG) # Clang issue with google test compilation
message(STATUS "Detected Conda build environment.")
find_package(GTest REQUIRED)
message(STATUS "gtest include dirs: " ${GTEST_INCLUDE_DIRS})
message(STATUS "gtest lib dirs: " ${GTEST_LIBRARIES})
include_directories(${GTEST_INCLUDE_DIRS})
link_directories(${GTEST_LIBRARIES})
else() # Local source code is required to build safly in debug mode
message(STATUS "Building outside of Conda environment.")
include_directories(googletest/include)
add_subdirectory(googletest)
endif()
add_subdirectory(tests)
if(${GBS_BUILD_TESTS_3RDLIBS})
add_subdirectory(tests_3rdlibs)
endif(${GBS_BUILD_TESTS_3RDLIBS})
endif()
if(${USE_CUDA})
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 20)
if(%{CUDA_ARCHITECTURES})
set(CMAKE_CUDA_ARCHITECTURES %{CUDA_ARCHITECTURES})
else()
set(CMAKE_CUDA_ARCHITECTURES 61) # Max 61 for SB2
endif()
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
# Rendering module
if(USE_RENDER OR GBS_BUILD_TESTS OR USE_PYTHON_BINDINGS)
set(USE_RENDER ON)
endif()
if(${USE_RENDER})
message("Configure rendering lib " ${USE_RENDER})
add_subdirectory(gbs-render)
endif(${USE_RENDER})
if(${USE_CUDA})
message("Configure CUDA implemetation " ${USE_CUDA})
add_subdirectory(gbs-cuda)
endif(${USE_CUDA})
add_subdirectory(gbs-io)
add_subdirectory(gbs-mesh)
add_subdirectory(tools)
# occt
if(${USE_OCCT_UTILS})
message("Configure occt bridge " ${USE_OCCT_UTILS})
find_package(OpenCASCADE REQUIRED)
link_directories(${OpenCASCADE_LIBRARY_DIR})
include_directories(${OpenCASCADE_INCLUDE_DIR})
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) # occt interators seems to be old
add_subdirectory(gbs-occt)
endif(${USE_OCCT_UTILS})
# Python bindings
if(${USE_PYTHON_BINDINGS})
message("Configure python binding " ${USE_PYTHON_BINDINGS})
add_subdirectory(python)
endif(${USE_PYTHON_BINDINGS})
if(${BUILD_DOC})
add_subdirectory(docs)
endif(${BUILD_DOC})
# add_executable(main main.cpp)
# SET_TARGET_PROPERTIES(main PROPERTIES LINK_FLAGS "/PROFILE")