-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
421 lines (374 loc) · 12.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
421 lines (374 loc) · 12.3 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#=========================================================
# RTK : Reconstruction Toolkit
#=========================================================
# Respect the CMAKE_CXX_STANDARD flags when building for
# ITKv5 or C++11.
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
## Only policies introduced after the cmake_minimum_required
## version need to explicitly be set to NEW.
## Refer to https://cmake.org/cmake/help/v3.11/manual/cmake-policies.7.html
set(CMAKE_POLICIES CMP0135)
foreach(p ${CMAKE_POLICIES})
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()
#=========================================================
# Help function to debug CMake
macro(DD in)
message(${in}=[${${in}}])
endmacro()
#=========================================================
project(RTK)
## RTK Version
set(RTK_VERSION_MAJOR "2")
set(RTK_VERSION_MINOR "7")
set(RTK_VERSION_PATCH "0")
set(RTK_VERSION_STRING "${RTK_VERSION_MAJOR}.${RTK_VERSION_MINOR}")
set(RTK_LIBRARIES RTK)
#=========================================================
# Installation variables
#=========================================================
if(NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib)
endif()
if(NOT RTK_INSTALL_RUNTIME_DIR)
set(RTK_INSTALL_RUNTIME_DIR bin)
endif()
if(NOT RTK_INSTALL_LIB_DIR)
set(RTK_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT RTK_INSTALL_ARCHIVE_DIR)
set(RTK_INSTALL_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT RTK_INSTALL_INCLUDE_DIR)
set(RTK_INSTALL_INCLUDE_DIR include/RTK)
endif()
if(NOT RTK_INSTALL_PACKAGE_DIR)
set(RTK_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/RTK")
endif()
#Set position independent code for Unix (-fPIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#=========================================================
# Remove some MS Visual c++ flags
if(MSVC)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_DEPRECATE
-D_SCL_SECURE_NO_WARNINGS
)
endif()
#=========================================================
# Remove some Intel compiler warnings
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
string(REPLACE "-Wno-unused-parameter" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qwd1268")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd1268")
endif()
endif()
include(cmake/rtkCompilerFlags.cmake)
# --------------------------------------------------------
# Find ITK (required)
if(NOT ITK_SOURCE_DIR)
find_package(ITK 5.1 REQUIRED)
endif()
# --------------------------------------------------------
# Shared libraries option
if(NOT ITK_SOURCE_DIR)
set(RTK_BUILD_SHARED_LIBS ${ITK_BUILD_SHARED})
else()
set(RTK_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
endif()
# ----------------------------------------------------------------------------
# Set RTK_DATA_ROOT
# Internally used by XRadRawToAttenuationImageFilter to set the path for its
# flat and dark headers.
if(NOT ITK_SOURCE_DIR)
set(
RTK_DATA_ROOT
${CMAKE_BINARY_DIR}/ExternalData/test
CACHE PATH
"Path of the data root"
FORCE
)
else()
file(RELATIVE_PATH RTK_RELATIVE_PATH ${ITK_SOURCE_DIR} ${RTK_SOURCE_DIR})
set(
RTK_DATA_ROOT
${ExternalData_BINARY_ROOT}/${RTK_RELATIVE_PATH}/test
CACHE PATH
"Path of the data root"
FORCE
)
endif()
mark_as_advanced(RTK_DATA_ROOT)
# --------------------------------------------------------
# Initialization
if(NOT ITK_SOURCE_DIR)
include(itk-module-init.cmake)
if(RTK_BUILD_SHARED_LIBS)
set(ITK_LIBRARY_BUILD_TYPE "SHARED")
else()
set(ITK_LIBRARY_BUILD_TYPE "STATIC")
endif()
endif()
#=========================================================
# If choose to build documentation, then search for Doxygen/Sphinx executables.
option(RTK_BUILD_DOXYGEN "Build Doxygen Documentation" OFF)
if(RTK_BUILD_DOXYGEN)
add_subdirectory(documentation/Doxygen)
endif()
option(RTK_BUILD_SPHINX "Build Sphinx Documentation" OFF)
if(RTK_BUILD_SPHINX)
add_subdirectory(documentation/docs)
endif()
# Setup build locations.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(
CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
# Python builds CI workflows expects archives to be placed in the ITK lib
# directory. This makes sure that other remote modules that depends on RTK
# can link against the RTK libraries.
if(WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER STREQUAL "PythonWheel")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_DIR}/${CMAKE_INSTALL_LIBDIR})
else()
set(
CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
endif()
endif()
#=========================================================
# lp_solve library
#=========================================================
add_subdirectory(utilities/lp_solve)
if("${ITK_VERSION_MAJOR}" VERSION_LESS "6")
set(
LPSOLVE_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/utilities/lp_solve
${PROJECT_SOURCE_DIR}/utilities/lp_solve/shared
${PROJECT_SOURCE_DIR}/utilities/lp_solve/bfp
${PROJECT_SOURCE_DIR}/utilities/lp_solve/bfp/bfp_LUSOL
${PROJECT_SOURCE_DIR}/utilities/lp_solve/bfp/bfp_LUSOL/LUSOL
${PROJECT_SOURCE_DIR}/utilities/lp_solve/colamd
)
list(APPEND RTK_INCLUDE_DIRS "${LPSOLVE_INCLUDE_DIRS}")
endif()
#=========================================================
# Generate RTKConfig.cmake for the build tree.
set(RTK_MODULE_PATH_CONFIG ${CMAKE_MODULE_PATH})
# Add option to control the generation of RTK applications
option(RTK_BUILD_APPLICATIONS "Build RTK applications" ON)
#-----------------------------------------------------------------------------
# Common revision info between applications
# ITK_CMAKE_DIR is needed to find GetGitRevisionDescription
if(NOT ITK_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
endif()
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
if(GIT_SHA1 MATCHES ".*NOTFOUND")
set(RTK_VERSION_HASH "")
else()
set(RTK_VERSION_HASH ", git hash ${GIT_SHA1}")
endif()
set(
RTK_EXPORT_CODE_BUILD
"
# The RTK version number
set(RTK_VERSION_MAJOR ${RTK_VERSION_MAJOR})
set(RTK_VERSION_MINOR ${RTK_VERSION_MINOR})
set(RTK_VERSION_PATCH ${RTK_VERSION_PATCH})
# Whether the compiled version of RTK uses CUDA
set(RTK_USE_CUDA ${RTK_USE_CUDA})
# Whether RTK applications were built
set(RTK_BUILD_APPLICATIONS ${RTK_BUILD_APPLICATIONS})
if(RTK_USE_CUDA)
find_package(CUDAToolkit)
set(RTK_CUDA_PROJECTIONS_SLAB_SIZE \"16\" CACHE STRING \"Number of projections processed simultaneously in CUDA forward and back projections\")
endif()
"
)
set(
RTK_EXPORT_CODE_INSTALL
"
# The RTK version number
set(RTK_VERSION_MAJOR ${RTK_VERSION_MAJOR})
set(RTK_VERSION_MINOR ${RTK_VERSION_MINOR})
set(RTK_VERSION_PATCH ${RTK_VERSION_PATCH})
# Whether the compiled version of RTK uses CUDA
set(RTK_USE_CUDA ${RTK_USE_CUDA})
# Whether RTK applications were built
set(RTK_BUILD_APPLICATIONS ${RTK_BUILD_APPLICATIONS})
if(RTK_USE_CUDA)
find_package(CUDAToolkit)
set(RTK_CUDA_PROJECTIONS_SLAB_SIZE \"16\" CACHE STRING \"Number of projections processed simultaneously in CUDA forward and back projections\")
endif()
"
)
#=========================================================
# Configure and build ITK external module
#=========================================================
if(NOT ITK_SOURCE_DIR)
if(NOT EXISTS ${ITK_CMAKE_DIR}/ITKModuleMacros.cmake)
message(
FATAL_ERROR
"Modules can only be built against an ITK build tree; they cannot be built against an ITK install tree."
)
endif()
include(ITKModuleExternal)
# Add third party to RTK build targets.
# This must be done after RTK has been loaded by ITK to make sure
# ${itk-module} variables are defined for RTK.
itk_module_target(lpsolve55)
if(${ITK_VERSION} VERSION_LESS 5.3)
## Set the default target properties for RTK
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14) # Supported values are ``11``, ``14``, and ``17``.
endif()
if(NOT CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
## Default to release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
endif()
else()
itk_module_impl()
endif()
# Propagate cmake options in a header file
# Must be done after the external module configuration to make sure CudaCommon_VERSION is defined
# The file is generated in the same folder as RTKExport.h
if(ITK_SOURCE_DIR)
set(_configuration_header_file "${ITKCommon_BINARY_DIR}/rtkConfiguration.h")
else()
set(_configuration_header_file "${RTK_BINARY_DIR}/include/rtkConfiguration.h")
endif()
configure_file(
${RTK_SOURCE_DIR}/rtkConfiguration.h.in
${_configuration_header_file}
)
# Install lpsolve headers
install(
FILES
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_bit.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_crash.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_explicit.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_fortify.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_Hash.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_lib.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_matrix.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_MDO.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_mipbb.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_MPS.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_presolve.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_price.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_pricePSE.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_report.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_rlp.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_scale.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_simplex.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_solveDLL.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_SOS.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_types.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_utils.h
${RTK_SOURCE_DIR}/utilities/lp_solve/lp_wlp.h
DESTINATION ${RTK_INSTALL_INCLUDE_DIR}/lpsolve
COMPONENT Development
)
if("${ITK_VERSION_MAJOR}" VERSION_LESS "6")
target_include_directories(
lpsolve55
PUBLIC
$<INSTALL_INTERFACE:${RTK_INSTALL_INCLUDE_DIR}/lpsolve>
)
endif()
# Install configuration file
install(
FILES
${_configuration_header_file}
DESTINATION ${RTK_INSTALL_INCLUDE_DIR}
)
install(
FILES
${RTK_SOURCE_DIR}/cmake/FindGengetopt.cmake
DESTINATION ${ITK_INSTALL_PACKAGE_DIR}
)
if(NOT ITK_SOURCE_DIR)
install(
CODE
"MESSAGE(FATAL_ERROR \"Cannot install, RTK is compiled separately from ITK. Installation is only functional if RTK is compiled within ITK.\")"
)
endif()
#=========================================================
# Build applications
#=========================================================
option(
RTK_PROBE_EACH_FILTER
"Probe each RTK filter in a global object and report times and memory used in RTK applications"
OFF
)
if(RTK_BUILD_APPLICATIONS)
add_subdirectory(applications)
endif()
# --------------------------------------------------------
# Setup KWStyle from ITK
if(ITK_USE_KWSTYLE)
find_package(Git)
if(GIT_FOUND AND EXISTS "${RTK_SOURCE_DIR}/.git/config")
execute_process(
COMMAND
${GIT_EXECUTABLE} config hooks.KWStyle.path "${KWSTYLE_EXECUTABLE}"
WORKING_DIRECTORY ${RTK_SOURCE_DIR}
)
endif()
endif()
# --------------------------------------------------------
# Setup ClangFormat from ITK
if(ITK_USE_CLANGFORMAT)
find_package(Git)
if(GIT_FOUND AND EXISTS "${RTK_SOURCE_DIR}/.git/config")
execute_process(
COMMAND
${GIT_EXECUTABLE} config clangFormat.binary "${CLANG_FORMAT_EXECUTABLE}"
WORKING_DIRECTORY ${RTK_SOURCE_DIR}
)
endif()
endif()
#=========================================================
# Install pre-commit hook
#=========================================================
if(
EXISTS
"${RTK_SOURCE_DIR}/.git/config"
AND
NOT
EXISTS
"${RTK_SOURCE_DIR}/.git/hooks/pre-commit"
)
# Silently ignore the error if the hooks directory is read-only.
execute_process(
COMMAND
${CMAKE_COMMAND} -E copy ${RTK_SOURCE_DIR}/cmake/Hooks/pre-commit
${RTK_SOURCE_DIR}/.git/hooks/pre-commit
OUTPUT_VARIABLE _output
ERROR_VARIABLE _output
RESULT_VARIABLE _result
)
if(_result AND NOT "${_output}" MATCHES "Error copying file")
message("${_output}")
endif()
endif()