Skip to content

Commit 4ffdcb9

Browse files
authored
ENH: Update CMake to decouple archives from example builds (#399)
Addresses issue where archives were not build for examples without an `add_example()` call, resulting in broken download links on `examples.itk.org`. New behavior packages example archives for all examples to accompany Sphinx documentation. Also cleans up `CMakeLists.txt` for several module groups.
1 parent 06cc158 commit 4ffdcb9

File tree

11 files changed

+162
-61
lines changed

11 files changed

+162
-61
lines changed

CMake/ITKSphinxExamplesMacros.cmake

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,38 @@ include(CMakeParseArguments)
1515
# the Sphinx documentation for an individual example. The Sphinx target will be
1616
# called ${example_name}Doc.
1717
macro(add_example example_name)
18-
if(BUILD_DOCUMENTATION)
19-
if(SPHINX_HTML_OUTPUT)
20-
add_custom_target(${example_name}DownloadableArchive
21-
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
22-
${example_name} ${SPHINX_DESTINATION}
23-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
24-
COMMENT "Creating downloadable archive for ${example_name}"
25-
DEPENDS copy_sources
26-
)
27-
add_dependencies(CreateDownloadableArchives ${example_name}DownloadableArchive)
28-
endif()
29-
endif()
30-
3118
# Process the example's CMakeLists.txt
3219
add_subdirectory(${example_name})
3320
endmacro()
3421

22+
# Macro for adding module archives
23+
macro(add_module_archives _module_name)
24+
file(GLOB
25+
${_module_name}_EXAMPLE_DIRS
26+
CONFIGURE_DEPENDS
27+
${CMAKE_CURRENT_SOURCE_DIR}/${_module_name}/*/
28+
)
29+
30+
if(BUILD_DOCUMENTATION AND SPHINX_HTML_OUTPUT)
31+
foreach(_example_path ${${_module_name}_EXAMPLE_DIRS})
32+
if(IS_DIRECTORY ${_example_path})
33+
get_filename_component(_example_name ${_example_path} NAME)
34+
get_filename_component(_example_parent_path ${_example_path} DIRECTORY)
35+
get_filename_component(_example_parent_name ${_example_parent_path} NAME)
36+
set(_archive_target ${_example_parent_name}_${_example_name}_DownloadableArchive)
37+
add_custom_target(${_archive_target}
38+
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
39+
${_example_name} ${SPHINX_DESTINATION}
40+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_example_parent_name}
41+
COMMENT "Creating downloadable archive for ${_example_name}"
42+
DEPENDS copy_sources
43+
)
44+
add_dependencies(CreateDownloadableArchives ${_archive_target})
45+
endif()
46+
endforeach()
47+
endif()
48+
endmacro()
49+
3550

3651
# Macro if the corresponding module is enabled when ITK was built
3752
# Pass in the module directory path. Also pass the module name as the second
@@ -48,6 +63,21 @@ macro(add_subdirectory_if_module_enabled _dir)
4863
endif()
4964
endmacro()
5065

66+
macro(add_subdirectories_if_module_enabled _dirs_to_ignore)
67+
file(GLOB
68+
_current_subdirectories
69+
CONFIGURE_DEPENDS
70+
${CMAKE_CURRENT_SOURCE_DIR}/*/
71+
)
72+
message(STATUS "Got subdirectories ${_current_subdirectories}")
73+
foreach(_subdir ${_current_subdirectories})
74+
get_filename_component(_subdir_name ${_subdir} NAME)
75+
if(${_subdir_name} NOT IN ${_dirs_to_ignore})
76+
add_subdirectory_if_module_enabled(${_subdir_name})
77+
endif()
78+
endforeach()
79+
endmacro()
80+
5181
# Creates a test that compares the output image of an example to its baseline
5282
# image.
5383
#

src/Bridge/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
set(Bridge_MODULES
2+
VtkGlue
3+
NumPy
4+
)
5+
16
if(ENABLE_QUICKVIEW)
27
add_subdirectory_if_module_enabled(VtkGlue)
38
endif()
49

510
add_subdirectory_if_module_enabled( NumPy )
11+
12+
foreach(_module ${Bridge_MODULES})
13+
add_module_archives(${_module})
14+
endforeach()

src/Core/CMakeLists.txt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
add_subdirectory_if_module_enabled(Common)
2-
add_subdirectory_if_module_enabled(QuadEdgeMesh)
3-
add_subdirectory_if_module_enabled(Mesh)
4-
add_subdirectory_if_module_enabled(TestKernel)
5-
add_subdirectory_if_module_enabled(Transform)
6-
add_subdirectory_if_module_enabled(ImageFunction)
7-
add_subdirectory_if_module_enabled(ImageAdaptors)
8-
add_subdirectory_if_module_enabled(SpatialObjects)
1+
set(Core_MODULES
2+
Common
3+
QuadEdgeMesh
4+
Mesh
5+
TestKernel
6+
Transform
7+
ImageFunction
8+
ImageAdaptors
9+
SpatialObjects
10+
)
11+
12+
foreach(_module ${Core_MODULES})
13+
add_subdirectory_if_module_enabled(${_module})
14+
add_module_archives(${_module})
15+
endforeach()

src/Filtering/CMakeLists.txt

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
add_subdirectory_if_module_enabled(BinaryMathematicalMorphology)
2-
add_subdirectory_if_module_enabled(ImageGrid)
3-
add_subdirectory_if_module_enabled(ImageFeature)
4-
add_subdirectory_if_module_enabled(FastMarching)
5-
add_subdirectory_if_module_enabled(Colormap)
6-
add_subdirectory_if_module_enabled(ImageIntensity)
7-
add_subdirectory_if_module_enabled(ImageFilterBase)
8-
add_subdirectory_if_module_enabled(Thresholding)
9-
add_subdirectory_if_module_enabled(QuadEdgeMeshFiltering)
10-
add_subdirectory_if_module_enabled(ImageCompare)
11-
add_subdirectory_if_module_enabled(MathematicalMorphology)
12-
add_subdirectory_if_module_enabled(Smoothing)
13-
# TODO: Need to re-enable ImageGraadient
14-
# add_subdirectory_if_module_enabled(ImageGradient)
15-
add_subdirectory_if_module_enabled(AnisotropicSmoothing)
16-
add_subdirectory_if_module_enabled(FFT)
17-
add_subdirectory_if_module_enabled(AntiAlias)
18-
add_subdirectory_if_module_enabled(LabelMap)
19-
add_subdirectory_if_module_enabled(ImageStatistics)
20-
add_subdirectory_if_module_enabled(ImageFusion)
21-
add_subdirectory_if_module_enabled(Convolution)
22-
add_subdirectory_if_module_enabled(DistanceMap)
23-
add_subdirectory_if_module_enabled(ImageCompose)
24-
add_subdirectory_if_module_enabled(ImageLabel)
25-
add_subdirectory_if_module_enabled(CurvatureFlow)
26-
add_subdirectory_if_module_enabled(Path)
1+
set(Filtering_MODULES
2+
AnisotropicSmoothing
3+
AntiAlias
4+
BinaryMathematicalMorphology
5+
Colormap
6+
Convolution
7+
CurvatureFlow
8+
DistanceMap
9+
FastMarching
10+
FFT
11+
ImageCompare
12+
ImageCompose
13+
ImageFeature
14+
ImageFilterBase
15+
ImageFusion
16+
ImageGradient
17+
ImageGrid
18+
ImageIntensity
19+
ImageLabel
20+
ImageStatistics
21+
LabelMap
22+
MathematicalMorphology
23+
Path
24+
QuadEdgeMeshFiltering
25+
Smoothing
26+
Thresholding
27+
)
28+
29+
set(Filtering_MODULES_IGNORED
30+
# TODO: Fix ImageGradient examples and re-enable
31+
ImageGradient
32+
)
33+
34+
foreach(_module ${Filtering_MODULES})
35+
if(NOT (${_module} IN_LIST Filtering_MODULES_IGNORED))
36+
add_subdirectory_if_module_enabled(${_module})
37+
endif()
38+
add_module_archives(${_module})
39+
endforeach()

src/IO/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
set(IO_MODULES
2+
ImageBase
3+
Mesh
4+
TIFF
5+
GDCM
6+
TransformBase
7+
TransformFactory
8+
)
9+
10+
# Add subdirectories with corresponding ITK module names
111
add_subdirectory_if_module_enabled(ImageBase ITKIOImageBase)
212
add_subdirectory_if_module_enabled(Mesh ITKIOMesh)
313
add_subdirectory_if_module_enabled(TIFF ITKIOTIFF)
414
add_subdirectory_if_module_enabled(GDCM ITKGDCM)
515
add_subdirectory_if_module_enabled(TransformBase)
616
add_subdirectory_if_module_enabled(TransformFactory)
17+
18+
foreach(_module ${IO_MODULES})
19+
add_module_archives(${_module})
20+
endforeach()

src/Nonunit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory_if_module_enabled(Review)
2+
add_module_archives(Review)

src/Numerics/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
add_subdirectory_if_module_enabled(Statistics)
2-
add_subdirectory_if_module_enabled(Optimizers)
1+
set(Numerics_MODULES
2+
Optimizers
3+
Statistics
4+
)
5+
6+
foreach(_module ${Numerics_MODULES})
7+
add_subdirectory_if_module_enabled(${_module})
8+
add_module_archives(${_module})
9+
endforeach()

src/Registration/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
add_subdirectory_if_module_enabled(Common)
2-
add_subdirectory_if_module_enabled(Metricsv4)
1+
set(Numerics_MODULES
2+
Common
3+
Metricsv4
4+
)
5+
6+
foreach(_module ${Numerics_MODULES})
7+
add_subdirectory_if_module_enabled(${_module})
8+
add_module_archives(${_module})
9+
endforeach()

src/Remote/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(Remote)
22
add_subdirectory_if_module_enabled(WikiExamples)
3+
add_module_archives(WikiExamples)

src/Segmentation/CMakeLists.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
add_subdirectory_if_module_enabled(LevelSets)
2-
add_subdirectory_if_module_enabled(LabelVoting)
3-
add_subdirectory_if_module_enabled(Watersheds)
4-
add_subdirectory_if_module_enabled(Classifiers)
5-
add_subdirectory_if_module_enabled(Voronoi)
6-
add_subdirectory_if_module_enabled(ConnectedComponents)
7-
add_subdirectory_if_module_enabled(RegionGrowing)
8-
if(ENABLE_QUICKVIEW)
9-
add_subdirectory_if_module_enabled(KLMRegionGrowing)
10-
endif()
1+
set(Segmentation_MODULES
2+
Classifiers
3+
CMakeLists.txt
4+
ConnectedComponents
5+
index.rst
6+
KLMRegionGrowing
7+
LabelVoting
8+
LevelSets
9+
RegionGrowing
10+
Voronoi
11+
Watersheds
12+
)
13+
14+
set(QUICKVIEW_MODULES KLMRegionGrowing)
15+
16+
foreach(_module ${Segmentation_MODULES})
17+
if(ENABLE_QUICKVIEW OR NOT (${_module} IN_LIST QUICKVIEW_MODULES))
18+
add_subdirectory_if_module_enabled(${_module})
19+
endif()
20+
add_module_archives(${_module})
21+
endforeach()

0 commit comments

Comments
 (0)