-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
253 lines (207 loc) · 9.45 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
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ViennaLS
LANGUAGES CXX
VERSION 4.1.0)
# --------------------------------------------------------------------------------------------------------
# Library options
# --------------------------------------------------------------------------------------------------------
option(VIENNALS_USE_VTK "Build with VTK file support" ON)
option(VIENNALS_PRECOMPILE_HEADERS "Build template specialisations for shorter compile times" OFF)
option(VIENNALS_STATIC_BUILD "Build dependencies as static libraries" OFF)
option(VIENNALS_ENABLE_SANITIZER "Enable Sanitizers" OFF)
option(VIENNALS_VTK_PYTHON_LIBS "Build against shared libraries shipped by VTKs Python library" OFF)
option(VIENNALS_PACKAGE_PYTHON "Build python bindings with intent to publish wheel" OFF)
option(VIENNALS_BUILD_PYTHON "Build python bindings" OFF)
option(VIENNALS_BUILD_EXAMPLES "Build examples" OFF)
option(VIENNALS_BUILD_TESTS "Build tests" OFF)
# --------------------------------------------------------------------------------------------------------
# Global CMake Configuration
# └ See: https://github.com/ViennaTools/ViennaPS/blob/c76e371817a797dfe2800691f00cb93317b731fa/CMakeLists.txt#L30
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_VTK_PYTHON_LIBS AND VIENNALS_PACKAGE_PYTHON)
message(
STATUS "[ViennaLS] Disabling `VIENNALS_PACKAGE_PYTHON` in favor of `VIENNALS_VTK_PYTHON_LIBS`")
set(VIENNALS_PACKAGE_PYTHON OFF)
endif()
if(VIENNALS_PACKAGE_PYTHON)
message(
STATUS
"[ViennaLS] Using remote VTK due to 'VIENNALS_PACKAGE_PYTHON', the build will take a long time!"
)
# CIBUILDWHEEL is absolutely cursed and won't work when this is turned on.
# I don't know why...
if(NOT VIENNALS_IS_CI)
set(CPM_DOWNLOAD_ALL ON)
endif()
set(VIENNALS_BUILD_PYTHON ON)
endif()
if(VIENNALS_BUILD_PYTHON)
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON)
endif()
# --------------------------------------------------------------------------------------------------------
# Configuration
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_BUILD_PYTHON)
message(STATUS "[ViennaLS] Using VTK for python bindings")
set(VIENNALS_USE_VTK ON)
endif()
if(VIENNALS_STATIC_BUILD)
message(STATUS "[ViennaLS] Enabling precompiled headers for static build")
set(VIENNALS_PRECOMPILE_HEADERS ON)
set(BUILD_SHARED_LIBS OFF)
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Library
# --------------------------------------------------------------------------------------------------------
add_library(${PROJECT_NAME} INTERFACE)
add_library(ViennaTools::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
set_target_properties(
${PROJECT_NAME}
PROPERTIES CXX_STANDARD 17
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON)
if(MSVC)
# https://learn.microsoft.com/cpp/c-runtime-library/math-constants
# TODO: In case C++20 is adpoted any time soon: https://cppreference.com/w/cpp/numeric/constants
target_compile_definitions(${PROJECT_NAME} INTERFACE _USE_MATH_DEFINES=1)
endif()
# --------------------------------------------------------------------------------------------------------
# Include directories
# --------------------------------------------------------------------------------------------------------
target_include_directories(
${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/viennals>
$<INSTALL_INTERFACE:include/viennals-${PROJECT_VERSION}>)
# --------------------------------------------------------------------------------------------------------
# Setup Dependencies
# --------------------------------------------------------------------------------------------------------
include(cmake/cpm.cmake)
include(cmake/vtk.cmake)
CPMAddPackage(
NAME ViennaCore
VERSION 1.1.0
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaCore"
OPTIONS "VIENNACORE_FORMAT_EXCLUDE docs/"
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON})
CPMAddPackage(
NAME PackageProject
VERSION 1.11.2
GIT_REPOSITORY "https://github.com/TheLartians/PackageProject.cmake"
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON})
CPMFindPackage(
NAME ViennaHRLE
VERSION 0.4.0
GIT_REPOSITORY "https://github.com/ViennaTools/ViennaHRLE"
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON})
find_package(OpenMP REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE OpenMP::OpenMP_CXX ViennaHRLE ViennaCore)
if(VIENNALS_USE_VTK AND VIENNALS_VTK_PYTHON_LIBS)
import_vtk_python()
target_link_libraries(${PROJECT_NAME} INTERFACE VTK::PythonLibs)
elseif(VIENNALS_USE_VTK)
enable_language(C)
CPMFindPackage(
NAME VTK
# TODO: Change to 9.3.1 as soon as it's released
# (https://github.com/ViennaTools/ViennaLS/pull/99#issuecomment-1832053715)
GIT_TAG 99bd602bdbe8024c55e8382f7cf1013d42a14601
VERSION 9.0.0
GIT_REPOSITORY "https://gitlab.kitware.com/vtk/vtk"
EXCLUDE_FROM_ALL ${VIENNALS_BUILD_PYTHON}
OPTIONS "VTK_LEGACY_REMOVE ON"
"VTK_SMP_IMPLEMENTATION_TYPE \"OpenMP\""
"VTK_GROUP_ENABLE_Rendering NO"
"VTK_GROUP_ENABLE_Imaging NO"
"VTK_GROUP_ENABLE_Views NO"
"TK_GROUP_ENABLE_Web NO"
"VTK_GROUP_ENABLE_Qt NO"
"VTK_GROUP_ENABLE_MPI NO"
"VTK_ENABLE_WRAPPING NO"
"VTK_MODULE_ENABLE_VTK_libproj NO"
"VTK_MODULE_ENABLE_VTK_CommonExecutionModel YES"
"VTK_MODULE_ENABLE_VTK_CommonMisc YES"
"VTK_MODULE_ENABLE_VTK_CommonSystem YES"
"VTK_MODULE_ENABLE_VTK_CommonMath YES"
"VTK_MODULE_ENABLE_VTK_CommonCore YES"
"VTK_MODULE_ENABLE_VTK_CommonTransforms YES"
"VTK_MODULE_ENABLE_VTK_CommonComputationalGeometry YES"
"VTK_MODULE_ENABLE_VTK_IOCore YES"
"VTK_MODULE_ENABLE_VTK_IOXMLParser YES"
"VTK_MODULE_ENABLE_VTK_IOXML YES"
"VTK_MODULE_ENABLE_VTK_FiltersCore YES"
"VTK_MODULE_ENABLE_VTK_FiltersGeneral YES"
"VTK_MODULE_ENABLE_VTK_FiltersGeometry YES"
# This fixes an issue with the install script that causes find_package to fail.
"CMAKE_PROJECT_NAME VTK")
target_compile_definitions(${PROJECT_NAME} INTERFACE VIENNALS_USE_VTK=1)
target_link_libraries(
${PROJECT_NAME}
INTERFACE VTK::CommonExecutionModel
VTK::CommonMisc
VTK::CommonSystem
VTK::CommonMath
VTK::CommonCore
VTK::CommonTransforms
VTK::CommonComputationalGeometry
VTK::IOCore
VTK::IOXMLParser
VTK::IOXML
VTK::FiltersCore
VTK::FiltersGeneral
VTK::FiltersGeometry)
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Sanitizer
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_ENABLE_SANITIZER)
viennacore_enable_sanitizer()
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Shared/Static Library
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_PRECOMPILE_HEADERS)
set(VIENNALS_LINKAGE SHARED)
if(VIENNALS_STATIC_BUILD)
set(VIENNALS_LINKAGE STATIC)
endif()
add_library(${PROJECT_NAME}Lib ${VIENNALS_LINKAGE})
add_library(${PROJECT_NAME}::Lib ALIAS ${PROJECT_NAME}Lib)
target_link_libraries(${PROJECT_NAME}Lib PUBLIC ${PROJECT_NAME})
target_sources(${PROJECT_NAME}Lib PUBLIC "lib/specialisations.cpp")
set_target_properties(${PROJECT_NAME}Lib PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Examples
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_BUILD_EXAMPLES)
message(STATUS "[ViennaLS] Building Examples")
add_subdirectory(examples)
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Tests
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_BUILD_TESTS)
message(STATUS "[ViennaLS] Building Tests")
enable_testing()
add_subdirectory(tests)
endif()
# --------------------------------------------------------------------------------------------------------
# Setup Python Bindings
# --------------------------------------------------------------------------------------------------------
if(VIENNALS_BUILD_PYTHON)
message(STATUS "[ViennaLS] Building Python Bindings")
add_subdirectory(python)
return()
endif()
# --------------------------------------------------------------------------------------------------------
# Install Target
# --------------------------------------------------------------------------------------------------------
packageProject(
NAME ${PROJECT_NAME} NAMESPACE ViennaTools
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include/viennals
INCLUDE_DESTINATION include/viennals-${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
DEPENDENCIES "VTK 9.0.0;ViennaHRLE 0.4.0")