-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathCMakeLists.txt
371 lines (313 loc) · 15.4 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
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
cmake_minimum_required(VERSION 3.19)
# Use new policy for 'install_name' and RPATH on macOS (use `cmake --help-policy CMP0068` for details)
cmake_policy(SET CMP0068 NEW)
# Use new policy for `FindOpenGL` to prefer GLVND by default when available on linux.
# (use `cmake --help-policy CMP0072` for details).
cmake_policy(SET CMP0072 NEW)
# Use new policy for 'Honor visibility properties for all target types'.
# (use `cmake --help-policy CMP0063` for details)
cmake_policy(SET CMP0063 NEW)
# Adds support for the new IN_LIST operator.
cmake_policy(SET CMP0057 NEW)
# Use new policy to use CMAKE_CXX_STANDARD in try_compile() macro
cmake_policy(SET CMP0067 NEW)
# Use old policy for Documentation to add cache variables and find VTK documentation dependent packages.
# (Needed for doxygen..)
cmake_policy(SET CMP0106 OLD)
# Use new policy for CMAKE_MSVC_DEBUG_INFORMATION_FORMAT
cmake_policy(SET CMP0141 NEW)
# Use old policy for now because of openCV
cmake_policy(SET CMP0146 OLD)
if(${CMAKE_VERSION} VERSION_GREATER "3.25.0")
# Transform the ``DEPFILE`` after running the custom command for Ninja generator.
cmake_policy(SET CMP0116 OLD)
endif()
# On Windows, if the user doesn't specify a value,
# 'CMAKE_BUILD_TYPE' is automatically initialized to 'Debug' after 'project()'.
# So we need to check this variable at this point.
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING
"Choose the type of build, options are: Debug, Release, RelWithDebInfo"
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT CMAKE_BUILD_TYPE STREQUAL
"RelWithDebInfo"
)
message(
FATAL_ERROR
"Invalid value for CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}' (required Debug, Release, RelWithDebInfo)"
)
endif()
project(
sight
VERSION 24.0.0
DESCRIPTION "Surgical Image Guidance and Healthcare Toolkit"
HOMEPAGE_URL "https://git.ircad.fr/sight/sight"
)
if(APPLE)
message(FATAL_ERROR "macOS is not supported.")
endif()
enable_testing()
include(CheckVariableExists)
include(CMakeParseArguments)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
option(SIGHT_ENABLE_PCH "Use pre-compiled headers to speedup the compilation" ON)
option(SIGHT_VERBOSE_PCH "Display debug messages to help debugging PCH" OFF)
mark_as_advanced(SIGHT_ENABLE_PCH)
mark_as_advanced(SIGHT_VERBOSE_PCH)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build/flags.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build/macros.cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/build/linux/modules)
# We find VTK to know its version so we can enable PCL or not
find_package(VTK CONFIG QUIET REQUIRED)
########################################################################################################################
# User options
########################################################################################################################
# Tests build / run options
option(SIGHT_BUILD_TESTS "Configures projects associated tests (<project>Test projects)" ON)
option(SIGHT_TESTS_XML_OUTPUT "Tests will generate an xml output, suitable for CI integration" ON)
mark_as_advanced(SIGHT_TESTS_XML_OUTPUT)
set(SIGHT_TESTS_FILTER "" CACHE STRING "Allows to only build/run tests whose path contains the filter string.")
mark_as_advanced(SIGHT_TESTS_FILTER)
if(UNIX)
option(SIGHT_ENABLE_GDB
"Test scripts will attach GDB, allowing to generate core file and print backtrace in case of crash." OFF
)
mark_as_advanced(SIGHT_ENABLE_GDB)
if(SIGHT_ENABLE_GDB)
find_program(GDB NAMES "gdb" REQUIRED)
endif()
endif()
# Use clang-tidy linter
option(SIGHT_ENABLE_CLANG_TIDY "Enable Clang Tidy checks" OFF)
mark_as_advanced(SIGHT_ENABLE_CLANG_TIDY)
if(SIGHT_ENABLE_CLANG_TIDY)
# cmake-lint: disable=C0301
find_program(CLANG_TIDY NAMES "clang-tidy" "clang-tidy-14" REQUIRED)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY};--use-color;--export-fixes=.clang-tidy-fixes.yaml)
# Also generate compile_commands.json which is useful when launching clang-tidy by "hand"
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
# QML_IMPORT_PATH allows qtCreator to find the qml modules created in our modules
set(QML_IMPORT_PATH "" CACHE STRING "Path of the Qml modules." FORCE)
mark_as_advanced(QML_IMPORT_PATH)
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "List of supported configurations." FORCE)
endif()
# Use solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER automoc)
# Make Realsense optional
option(SIGHT_ENABLE_REALSENSE "Enable RealSense" OFF)
# Make samples/tutorials build optional
option(SIGHT_BUILD_EXAMPLES "Build examples and tutorials" ON)
option(SIGHT_BUILD_MANPAGES "Generate man pages for applications" OFF)
########################################################################################################################
# Warn user of install dir isn't empty
########################################################################################################################
file(GLOB_RECURSE INSTALL_DIR_CONTENT ${CMAKE_INSTALL_PREFIX}/*)
list(LENGTH INSTALL_DIR_CONTENT CONTENT)
if(NOT CONTENT EQUAL 0)
# DIR isn't empty, warn user.
message(WARNING "CMAKE_INSTALL_PREFIX (${CMAKE_INSTALL_PREFIX}) isn't empty."
"Please select another folder or clean it before running install command."
)
endif()
########################################################################################################################
# External libraries management
########################################################################################################################
set(FWCMAKE_RESOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
# Append our 'FindPackages.cmake' to CMAKE_MODULE_PATH
list(APPEND CMAKE_MODULE_PATH ${FWCMAKE_RESOURCE_PATH}/modules)
if(UNIX)
list(APPEND CMAKE_PREFIX_PATH ${FWCMAKE_RESOURCE_PATH}/modules)
list(APPEND CMAKE_FIND_ROOT_PATH ${FWCMAKE_RESOURCE_PATH}/modules)
if(UNIX)
list(APPEND CMAKE_PREFIX_PATH /usr/share/OGRE/cmake/modules)
endif()
set(SIGHT_EXTERNAL_LIBRARIES CACHE PATH "External libraries location")
mark_as_advanced(SIGHT_EXTERNAL_LIBRARIES)
# Use directly SIGHT_EXTERNAL_LIBRARIES if set, otherwise, download and install sight-deps package
# Comment out this if one need to include a dependency from sight-deps one day
#if(NOT SIGHT_EXTERNAL_LIBRARIES AND SIGHT_ENABLE_LIBRARY)
# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build/download_deps.cmake)
#endif()
if(SIGHT_EXTERNAL_LIBRARIES)
get_filename_component(ABSOLUTE_SIGHT_EXTERNAL_LIBRARIES ${SIGHT_EXTERNAL_LIBRARIES} REALPATH)
set(SIGHT_EXTERNAL_LIBRARIES ${ABSOLUTE_SIGHT_EXTERNAL_LIBRARIES})
unset(ABSOLUTE_SIGHT_EXTERNAL_LIBRARIES)
list(APPEND CMAKE_PREFIX_PATH ${SIGHT_EXTERNAL_LIBRARIES})
list(APPEND CMAKE_MODULE_PATH ${SIGHT_EXTERNAL_LIBRARIES}/lib/cmake/)
list(APPEND CMAKE_FIND_ROOT_PATH ${SIGHT_EXTERNAL_LIBRARIES})
# To be added into LD_LIBRARY_PATH in our "launch" scripts.
set(SIGHT_EXTERNAL_LIBRARIES_LIB_PATH ${SIGHT_EXTERNAL_LIBRARIES}/lib/)
endif()
endif()
# We always need CppUnit, no need to put that in subdirectories
find_package(CppUnit QUIET REQUIRED)
########################################################################################################################
# Default paths settings for libraries, modules and resources
########################################################################################################################
set(FW_INSTALL_PATH_SUFFIX "${PROJECT_NAME}")
set(SIGHT_MODULE_RC_PREFIX "${CMAKE_INSTALL_DATADIR}/${FW_INSTALL_PATH_SUFFIX}")
if(WIN32)
set(SIGHT_MODULE_LIB_PREFIX "${CMAKE_INSTALL_BINDIR}")
else()
set(SIGHT_MODULE_LIB_PREFIX "${CMAKE_INSTALL_LIBDIR}")
endif()
set(FWCONFIG_PACKAGE_LOCATION lib/cmake/sight)
set_property(GLOBAL PROPERTY ${PROJECT_NAME}_COMPONENTS "")
# Define the path 'FW_SIGHT_EXTERNAL_LIBRARIES_DIR' used to find external libraries required by our applications
set_external_libraries_dir()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(SIGHT_VCPKG_ROOT_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug")
else()
set(SIGHT_VCPKG_ROOT_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}")
set(EXCLUDE_PATTERN ".*/debug/.*")
endif()
sight_configure_pch()
add_subdirectory(libs)
add_subdirectory(modules)
add_subdirectory(configs)
add_subdirectory(activities)
add_subdirectory(utils)
add_subdirectory(apps)
if(SIGHT_BUILD_EXAMPLES)
add_subdirectory(tutorials)
add_subdirectory(examples)
endif()
add_subdirectory(3rd-party)
########################################################################################################################
# Export and install targets
########################################################################################################################
# Will export COMPONENTS: list of all available components ordered by dependency (no dependency first).
sight_generate_component_list(COMPONENTS)
# Create the sightConfigVersion file
configure_file(${CMAKE_SOURCE_DIR}/cmake/build/sightConfig.cmake.in ${CMAKE_BINARY_DIR}/cmake/sightConfig.cmake @ONLY)
write_basic_package_version_file(
"${CMAKE_BINARY_DIR}/cmake/sightConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion
)
# Install a special xvfb-run wrapper script to workaround bugs withe the system xvfb-run launcher script
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/install/linux/safe-xvfb-run ${CMAKE_CURRENT_BINARY_DIR}/bin/safe-xvfb-run
COPYONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/install/linux/exec_gui_tests.sh ${CMAKE_CURRENT_BINARY_DIR}/bin/exec_gui_tests.sh
COPYONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/install/windows/exec_gui_tests.bat
${CMAKE_CURRENT_BINARY_DIR}/bin/exec_gui_tests.bat COPYONLY
)
# Install the sightConfig.cmake and sightConfigVersion.cmake
install(
FILES "${CMAKE_BINARY_DIR}/cmake/sightConfig.cmake" "${CMAKE_BINARY_DIR}/cmake/sightConfigVersion.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/macros.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/linux/modules/FindFilesystem.cmake"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}
COMPONENT dev
)
# install CppUnitConfig.cmake in a modules folder.
install(FILES "${CMAKE_SOURCE_DIR}/cmake/modules/CppUnitConfig.cmake" DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/modules
COMPONENT dev
)
# Install some files needed for the build
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/build/configure_file.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/flags.cmake"
"${FWCMAKE_RESOURCE_PATH}/build/cppunit_main.cpp.in"
"${FWCMAKE_RESOURCE_PATH}/build/pch.cpp"
"${CMAKE_SOURCE_DIR}/cmake/build/config.hpp.in"
"${CMAKE_SOURCE_DIR}/cmake/build/plugin_config.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/plugin_config_command.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/profile_config.cmake"
"${CMAKE_SOURCE_DIR}/cmake/build/profile.xml.in"
"${CMAKE_SOURCE_DIR}/cmake/build/registerServices.cpp.in"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/build
COMPONENT dev
)
# Install some files needed for the install
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/install/generic_install.cmake"
"${CMAKE_SOURCE_DIR}/cmake/install/get_git_rev.cmake"
"${CMAKE_SOURCE_DIR}/cmake/install/helper.cmake"
"${CMAKE_SOURCE_DIR}/cmake/install/install_imported.cmake.in"
"${CMAKE_SOURCE_DIR}/cmake/install/pre_package.cmake"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install
COMPONENT dev
)
if(WIN32)
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/build/windows/template.bat.in"
"${CMAKE_SOURCE_DIR}/cmake/build/windows/template_exe.bat.in"
"${CMAKE_SOURCE_DIR}/cmake/build/windows/template_test.bat.in"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/build/windows
COMPONENT dev
)
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/install/windows/package.cmake"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/install_plugins.cmake"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/template.bat.in"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/template_exe.bat.in"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/setpath.bat.in"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/windows_fixup.cmake.in"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/windows
COMPONENT dev
)
install(FILES "${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/NSIS.InstallOptions.ini.in"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/NSIS.template.in"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/windows/NSIS/
)
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/rc/banner_nsis.bmp"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/rc/dialog_nsis.bmp"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/rc/app.ico"
"${CMAKE_SOURCE_DIR}/cmake/install/windows/NSIS/rc/license.rtf"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/windows/NSIS/rc/
)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/cmake/install/windows/exec_gui_tests.bat"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/windows COMPONENT dev
)
elseif(UNIX)
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/build/linux/template.sh.in"
"${CMAKE_SOURCE_DIR}/cmake/build/linux/template_exe.sh.in"
"${CMAKE_SOURCE_DIR}/cmake/build/linux/template_test.sh.in"
"${CMAKE_SOURCE_DIR}/cmake/build/linux/manpage.cmake"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/build/linux
COMPONENT dev
)
install(FILES "${CMAKE_SOURCE_DIR}/cmake/install/linux/package.cmake"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/linux COMPONENT dev
)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/cmake/install/linux/safe-xvfb-run"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/linux COMPONENT dev
)
install(PROGRAMS "${CMAKE_SOURCE_DIR}/cmake/install/linux/exec_gui_tests.sh"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/linux COMPONENT dev
)
install(
FILES "${CMAKE_SOURCE_DIR}/cmake/install/linux/template.sh.in"
"${CMAKE_SOURCE_DIR}/cmake/install/linux/template_exe.sh.in"
"${CMAKE_SOURCE_DIR}/cmake/install/linux/linux_fixup.cmake.in"
DESTINATION ${FWCONFIG_PACKAGE_LOCATION}/install/linux
COMPONENT dev
)
endif()
########################################################################################################################
# Misc generators
########################################################################################################################
# Doxygen documentation
option(SIGHT_BUILD_DOC "Build the doxygen documentation" OFF)
if(SIGHT_BUILD_DOC)
option(SIGHT_BUILD_DOCSET "Build a Dash/Zeal/XCode docset" OFF)
include(${FWCMAKE_RESOURCE_PATH}doxygen/doxygen_generator.cmake)
doxygengenerator(${PROJECT_LIST})
if(SIGHT_BUILD_DOCSET)
docsetgenerator(${PROJECT_LIST})
endif()
else()
unset(SIGHT_BUILD_DOCSET CACHE)
endif()
sight_create_package_targets("${COMPONENTS}" "")