-
Notifications
You must be signed in to change notification settings - Fork 67
/
CMakeLists.txt
341 lines (306 loc) · 13 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
# ==== Define cmake build policies that affect compilation and linkage default behaviors
#
# Set the ITKEX_NEWEST_VALIDATED_POLICIES_VERSION string to the newest cmake version
# policies that provide successful builds. By setting ITKEX_NEWEST_VALIDATED_POLICIES_VERSION
# to a value greater than the oldest policies, all policies between
# ITKEX_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION (used for this build)
# are set to their NEW behaivor, thereby suppressing policy warnings related to policies
# between the ITKEX_OLDEST_VALIDATED_POLICIES_VERSION and CMAKE_VERSION.
#
# CMake versions greater than the ITKEX_NEWEST_VALIDATED_POLICIES_VERSION policies will
# continue to generate policy warnings "CMake Warning (dev)...Policy CMP0XXX is not set:"
#
set(ITKEX_OLDEST_VALIDATED_POLICIES_VERSION "3.16.3")
set(ITKEX_NEWEST_VALIDATED_POLICIES_VERSION "3.19.7")
cmake_minimum_required(VERSION ${ITKEX_OLDEST_VALIDATED_POLICIES_VERSION} FATAL_ERROR)
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${ITKEX_NEWEST_VALIDATED_POLICIES_VERSION}")
#Set and use the newest available cmake policies that are validated to work
set(ITK_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
else()
set(ITK_CMAKE_POLICY_VERSION "${ITKEX_NEWEST_VALIDATED_POLICIES_VERSION}")
endif()
cmake_policy(VERSION ${ITK_CMAKE_POLICY_VERSION})
#
# Now enumerate specific policies newer than ITKEX_NEWEST_VALIDATED_POLICIES_VERSION
# that may need to be individually set to NEW/OLD
#
foreach(pnew "") # Currently Empty
if(POLICY ${pnew})
cmake_policy(SET ${pnew} NEW)
endif()
endforeach()
foreach(pold "") # Currently Empty
if(POLICY ${pold})
cmake_policy(SET ${pold} OLD)
endif()
endforeach()
# ==== Define language standard configurations requiring at least c++14 standard
if(CMAKE_CXX_STANDARD EQUAL "98" OR CMAKE_CXX_STANDARD LESS "14")
message(FATAL_ERROR "C++98 to C++11 are no longer supported in ITK version 5.3 and greater.")
endif()
#####
## Set the default target properties for ITK
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14) # Supported values are ``14``, ``17``, and ``20``.
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()
project(ITKSphinxExamples)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "-Qunused-arguments ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-Qunused-arguments ${CMAKE_C_FLAGS}")
endif()
if(CMAKE_HOST_WIN32)
string(LENGTH "${ITKSphinxExamples_SOURCE_DIR}" source_len)
if(${source_len} GREATER 30)
message(FATAL_ERROR
"The source directory is currently too long, ${source_len} characters. "
"Please move the Examples source directory to a shorter path."
)
endif()
string(LENGTH "${ITKSphinxExamples_BINARY_DIR}" binary_len)
if(${binary_len} GREATER 30)
message(FATAL_ERROR
"The build directory is currently too long, ${binary_len} characters. "
"Please set the Examples build directory to a shorter path."
)
endif()
endif()
#Optional if we are building as an ITK module, these variables will be pre-defined
if(NOT ITK_VERSION)
# To get the ITK version information from external package when building
# stand alone, ITK is required.
find_package(ITK 5.3.0 REQUIRED)
endif()
set(ITKSphinxExamples_VERSION_MAJOR ${ITK_VERSION_MAJOR})
set(ITKSphinxExamples_VERSION_MINOR ${ITK_VERSION_MINOR})
set(ITKSphinxExamples_VERSION_PATCH ${ITK_VERSION_PATCH})
set(ITKSphinxExamples_VERSION
"${ITKSphinxExamples_VERSION_MAJOR}.${ITKSphinxExamples_VERSION_MINOR}"
)
set(ITKSphinxExamples_RELEASE_VERSION
"${ITKSphinxExamples_VERSION_MAJOR}.${ITKSphinxExamples_VERSION_MINOR}.${ITKSphinxExamples_VERSION_PATCH}"
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ITKSphinxExamples_BINARY_DIR}/bin)
include(CTest)
# Tests are added with add_test() can be run with the 'ctest' command line program.
enable_testing()
configure_file(CMake/CTestCustom.cmake.in CTestCustom.cmake)
# ExternalData setup. We use the CMake ExternalData features to download binary
# files from a configurable location(s) -- including the local filesystem -- to
# avoid storing the potentially large files in the Git history.
set(CMAKE_MODULE_PATH ${ITKSphinxExamples_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})
# The CMake magic to download the data.
set(ExternalData_SOURCE_ROOT "${ITKSphinxExamples_SOURCE_DIR}")
set(ExternalData_BINARY_ROOT "${ITKSphinxExamples_BINARY_DIR}")
include(ITKSphinxExamplesExternalData)
set(_RootSubDirs
CMake
Formatting
Utilities
src
Documentation
Superbuild
)
set(content_links)
# By default we copy all the content links in the source tree to their
# corresponding locations in the binary tree.
foreach(_dir ${_RootSubDirs})
file(GLOB_RECURSE ${_dir}_content_links
RELATIVE "${ITKSphinxExamples_SOURCE_DIR}" "${_dir}/*.cid")
set(content_links ${content_links} ${${_dir}_content_links})
endforeach()
foreach(link ${content_links})
string(REGEX REPLACE "\\.cid$" "" link ${link})
ExternalData_Expand_Arguments(ITKSphinxExamplesData
link_location
DATA{${link}}
)
endforeach()
ExternalData_Add_Target(ITKSphinxExamplesData)
set(PYTHON_REQUIRED_VERSION 3.7)
set(Python_ADDITIONAL_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7)
if(BUILD_TESTING OR ITK_BUILD_DOCUMENTATION OR ITK_WRAP_PYTHON)
if(ITK_WRAP_PYTHON)
# Use the same Python interpreter as ITK to run the tests.
find_package(Python3 ${ITK_WRAP_PYTHON_VERSION} EXACT COMPONENTS Interpreter REQUIRED)
mark_as_advanced(Python3_EXECUTABLE)
else()
find_package(Python3 ${PYTHON_REQUIRED_VERSION} COMPONENTS Interpreter)
endif()
endif()
if(Python3_EXECUTABLE AND NOT ITK_WRAP_PYTHON)
# See if external ITK python packages are installed for this python environment
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import itk"
RESULT_VARIABLE _have_itk_return_code
OUTPUT_QUIET
ERROR_QUIET
)
if(_have_itk_return_code EQUAL 0)
set(ITK_WRAP_PYTHON 1)
endif()
endif()
# Build the documentation?
option(BUILD_DOCUMENTATION "Build the examples documentation." OFF)
if(BUILD_DOCUMENTATION)
# -------------------------------------------------------------------------
# Check to make sure the submodules are available
find_package(Git)
# The UPDATING_SUBMODULES variable can be set to prevent CMake from running
# 'git submodule update' when attempting change the commit a submodule points
# to.
option(UPDATING_SUBMODULES
"Set to ON when updating one of the Git submodules." OFF)
if(EXISTS "${ITKSphinxExamples_SOURCE_DIR}/.git" AND GIT_EXECUTABLE AND NOT "${UPDATING_SUBMODULES}")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY "${ITKSphinxExamples_SOURCE_DIR}"
OUTPUT_QUIET
)
endif()
if(NOT EXISTS "${ITKSphinxExamples_SOURCE_DIR}/Utilities/SphinxExtensions/breathelink/.git")
message(SEND_ERROR "The git submodules are not available. Please run
git submodule update --init --recursive"
)
endif()
# -------------------------------------------------------------------------
# We must also duplicate the source tree since the images need to be present
# with the source.
add_custom_target(copy_sources ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ITKSphinxExamples_SOURCE_DIR}/src" "${ITKSphinxExamples_BINARY_DIR}/src"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ITKSphinxExamples_SOURCE_DIR}/Documentation" "${ITKSphinxExamples_BINARY_DIR}/Documentation"
COMMAND ${CMAKE_COMMAND} -E copy "${ITKSphinxExamples_SOURCE_DIR}/index.rst" "${ITKSphinxExamples_BINARY_DIR}/index.rst"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ITKSphinxExamples_SOURCE_DIR}/Formatting"
"${ITKSphinxExamples_BINARY_DIR}/Formatting"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ITKSphinxExamples_SOURCE_DIR}/Utilities"
"${ITKSphinxExamples_BINARY_DIR}/Utilities"
COMMENT "Copying sources"
)
# For unknown reasons, this was the only effective way to ensure ITKSphinxExamplesData
# was built before build_html.
add_dependencies(copy_sources ITKSphinxExamplesData)
# A high level target that the individual targets depend on.
add_custom_target(CreateDownloadableArchives ALL
${CMAKE_COMMAND} -E echo "Done creating individual example downloadable archives..."
)
if(NOT ITKDoxygenXML_DIR)
include(${ITKSphinxExamples_SOURCE_DIR}/CMake/ITKDoxygenXML.cmake)
endif()
if(NOT ITKDoxygenTAG_DIR)
include(${ITKSphinxExamples_SOURCE_DIR}/CMake/ITKDoxygenTAG.cmake)
endif()
# Builds the documentation.
find_package(Sphinx REQUIRED)
find_program(PANDOC_BIN pandoc REQUIRED)
set(SPHINX_CONF_DIR ${ITKSphinxExamples_BINARY_DIR}/Formatting)
set(SPHINX_INPUT_DIR ${ITKSphinxExamples_BINARY_DIR})
set(SPHINX_DESTINATION ${ITKSphinxExamples_BINARY_DIR})
set(SPHINX_DEPENDENCIES ITKDoxygenXML ITKSphinxExamplesData ITKDoxygenTAG CreateDownloadableArchives)
option(DOC_WITH_LOCAL_DOXYGEN "Generate documentation with local doxygen" OFF)
mark_as_advanced(DOC_WITH_LOCAL_DOXYGEN)
set(sphinx_target_base_name build)
Sphinx_add_targets(${sphinx_target_base_name} ${SPHINX_CONF_DIR} ${SPHINX_INPUT_DIR} ${SPHINX_DESTINATION} ${SPHINX_DEPENDENCIES})
if(${SPHINX_HTML_OUTPUT})
install(DIRECTORY ${SPHINX_DESTINATION}/html
DESTINATION share/ITKSphinxExamples/doc
COMPONENT Doc
PATTERN "${SPHINX_DESTINATION}/html/*"
)
add_custom_command(TARGET ${sphinx_target_base_name}_html
POST_BUILD
COMMAND ${Python3_EXECUTABLE}
${ITKSphinxExamples_SOURCE_DIR}/Utilities/DocumentationTarball.py
${SPHINX_DESTINATION}/html
${ITKSphinxExamples_BINARY_DIR}/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}-html
WORKING_DIRECTORY ${ITKSphinxExamples_BINARY_DIR}/html
COMMENT "Creating html tarballs..."
)
install(FILES
${ITKSphinxExamples_BINARY_DIR}/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}-html.tar.gz
${ITKSphinxExamples_BINARY_DIR}/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}-html.zip
DESTINATION share/ITKSphinxExamples/doc/html
COMPONENT Doc
)
endif()
if(${SPHINX_LATEX_OUTPUT})
set(DOC_WITH_LOCAL_DOXYGEN OFF)
# Build the PDF with pdflatex
find_package(LATEX)
if(NOT PDFLATEX_COMPILER)
message("pdflatex compiler was not found. Please pass to advanced mode and provide its full path")
else()
# Needs to be executed twice to get table of contents.
add_custom_command(TARGET ${sphinx_target_base_name}_latex
POST_BUILD
COMMAND ${PDFLATEX_COMPILER}
${SPHINX_DESTINATION}/latex/ITKSphinxExamples.tex
-output-directory ${SPHINX_DESTINATION}/latex
COMMAND ${MAKEINDEX_COMPILER}
ITKSphinxExamples.idx
COMMAND ${PDFLATEX_COMPILER}
${SPHINX_DESTINATION}/latex/ITKSphinxExamples.tex
-output-directory ${SPHINX_DESTINATION}/latex
COMMAND ${CMAKE_COMMAND} -E copy
${SPHINX_DESTINATION}/latex/ITKSphinxExamples.pdf
${SPHINX_DESTINATION}/html/Documentation/Download/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}.pdf
WORKING_DIRECTORY ${SPHINX_DESTINATION}/latex
COMMENT "Building PDF"
)
install(FILES ${SPHINX_DESTINATION}/html/Documentation/Download/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}.pdf
DESTINATION share/ITKSphinxExamples/doc/pdf
COMPONENT Doc
)
endif()
endif()
if(${SPHINX_EPUB_OUTPUT})
add_custom_command(TARGET ${sphinx_target_base_name}_epub
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${SPHINX_DESTINATION}/epub/sphinx.epub
${SPHINX_DESTINATION}/html/Documentation/Download/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}.epub
COMMENT "Copying EPUB"
)
install(FILES ${SPHINX_DESTINATION}/html/Documentation/Download/ITKSphinxExamples-${ITKSphinxExamples_RELEASE_VERSION}.epub
DESTINATION share/ITKSphinxExamples/doc/epub
COMPONENT Doc
)
endif()
if(DOC_WITH_LOCAL_DOXYGEN)
set(ITKDoxygen_LINK_ADDRESS ${ITKDoxygen_DIR})
set(SPHINX_DEPENDENCIES ${SPHINX_DEPENDENCIES} ITKDoxygen)
if(NOT ITKDoxygen_DIR)
include(${CMAKE_SOURCE_DIR}/CMake/ITKDoxygen.cmake)
endif()
else()
set(ITKDoxygen_LINK_ADDRESS "https://itk.org/Doxygen/html")
endif()
add_subdirectory(Formatting)
add_subdirectory(Documentation)
else()
# Copy the cookiecutter directory
# Achieved with copy_sources target when BUILD_DOCUMENTATION enabled
add_custom_target(copy_cookiecutter ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${ITKSphinxExamples_SOURCE_DIR}/Utilities/CookieCutter"
"${ITKSphinxExamples_BINARY_DIR}/Utilities/CookieCutter"
COMMENT "Copy CookieCutter"
)
endif()
# Configure the CreateNewExamples.py Python Script
configure_file("${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateNewExample.py.in"
"${ITKSphinxExamples_BINARY_DIR}/Utilities/CreateNewExample.py"
@ONLY)
# Build the example executables?
option(BUILD_EXECUTABLES "Build the example executables." ON)
if(COMMAND itk_module_impl)
itk_module_impl()
else()
if(BUILD_EXECUTABLES)
add_subdirectory(src)
endif()
add_subdirectory(Utilities)
include(CPack)
endif()