Skip to content

Commit

Permalink
ENH: Update CMake to decouple archives from example builds (#399)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbirdso authored Nov 14, 2022
1 parent 06cc158 commit 4ffdcb9
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 61 deletions.
56 changes: 43 additions & 13 deletions CMake/ITKSphinxExamplesMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,38 @@ include(CMakeParseArguments)
# the Sphinx documentation for an individual example. The Sphinx target will be
# called ${example_name}Doc.
macro(add_example example_name)
if(BUILD_DOCUMENTATION)
if(SPHINX_HTML_OUTPUT)
add_custom_target(${example_name}DownloadableArchive
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
${example_name} ${SPHINX_DESTINATION}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Creating downloadable archive for ${example_name}"
DEPENDS copy_sources
)
add_dependencies(CreateDownloadableArchives ${example_name}DownloadableArchive)
endif()
endif()

# Process the example's CMakeLists.txt
add_subdirectory(${example_name})
endmacro()

# Macro for adding module archives
macro(add_module_archives _module_name)
file(GLOB
${_module_name}_EXAMPLE_DIRS
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/${_module_name}/*/
)

if(BUILD_DOCUMENTATION AND SPHINX_HTML_OUTPUT)
foreach(_example_path ${${_module_name}_EXAMPLE_DIRS})
if(IS_DIRECTORY ${_example_path})
get_filename_component(_example_name ${_example_path} NAME)
get_filename_component(_example_parent_path ${_example_path} DIRECTORY)
get_filename_component(_example_parent_name ${_example_parent_path} NAME)
set(_archive_target ${_example_parent_name}_${_example_name}_DownloadableArchive)
add_custom_target(${_archive_target}
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
${_example_name} ${SPHINX_DESTINATION}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_example_parent_name}
COMMENT "Creating downloadable archive for ${_example_name}"
DEPENDS copy_sources
)
add_dependencies(CreateDownloadableArchives ${_archive_target})
endif()
endforeach()
endif()
endmacro()


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

macro(add_subdirectories_if_module_enabled _dirs_to_ignore)
file(GLOB
_current_subdirectories
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/*/
)
message(STATUS "Got subdirectories ${_current_subdirectories}")
foreach(_subdir ${_current_subdirectories})
get_filename_component(_subdir_name ${_subdir} NAME)
if(${_subdir_name} NOT IN ${_dirs_to_ignore})
add_subdirectory_if_module_enabled(${_subdir_name})
endif()
endforeach()
endmacro()

# Creates a test that compares the output image of an example to its baseline
# image.
#
Expand Down
9 changes: 9 additions & 0 deletions src/Bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
set(Bridge_MODULES
VtkGlue
NumPy
)

if(ENABLE_QUICKVIEW)
add_subdirectory_if_module_enabled(VtkGlue)
endif()

add_subdirectory_if_module_enabled( NumPy )

foreach(_module ${Bridge_MODULES})
add_module_archives(${_module})
endforeach()
23 changes: 15 additions & 8 deletions src/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
add_subdirectory_if_module_enabled(Common)
add_subdirectory_if_module_enabled(QuadEdgeMesh)
add_subdirectory_if_module_enabled(Mesh)
add_subdirectory_if_module_enabled(TestKernel)
add_subdirectory_if_module_enabled(Transform)
add_subdirectory_if_module_enabled(ImageFunction)
add_subdirectory_if_module_enabled(ImageAdaptors)
add_subdirectory_if_module_enabled(SpatialObjects)
set(Core_MODULES
Common
QuadEdgeMesh
Mesh
TestKernel
Transform
ImageFunction
ImageAdaptors
SpatialObjects
)

foreach(_module ${Core_MODULES})
add_subdirectory_if_module_enabled(${_module})
add_module_archives(${_module})
endforeach()
65 changes: 39 additions & 26 deletions src/Filtering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
add_subdirectory_if_module_enabled(BinaryMathematicalMorphology)
add_subdirectory_if_module_enabled(ImageGrid)
add_subdirectory_if_module_enabled(ImageFeature)
add_subdirectory_if_module_enabled(FastMarching)
add_subdirectory_if_module_enabled(Colormap)
add_subdirectory_if_module_enabled(ImageIntensity)
add_subdirectory_if_module_enabled(ImageFilterBase)
add_subdirectory_if_module_enabled(Thresholding)
add_subdirectory_if_module_enabled(QuadEdgeMeshFiltering)
add_subdirectory_if_module_enabled(ImageCompare)
add_subdirectory_if_module_enabled(MathematicalMorphology)
add_subdirectory_if_module_enabled(Smoothing)
# TODO: Need to re-enable ImageGraadient
# add_subdirectory_if_module_enabled(ImageGradient)
add_subdirectory_if_module_enabled(AnisotropicSmoothing)
add_subdirectory_if_module_enabled(FFT)
add_subdirectory_if_module_enabled(AntiAlias)
add_subdirectory_if_module_enabled(LabelMap)
add_subdirectory_if_module_enabled(ImageStatistics)
add_subdirectory_if_module_enabled(ImageFusion)
add_subdirectory_if_module_enabled(Convolution)
add_subdirectory_if_module_enabled(DistanceMap)
add_subdirectory_if_module_enabled(ImageCompose)
add_subdirectory_if_module_enabled(ImageLabel)
add_subdirectory_if_module_enabled(CurvatureFlow)
add_subdirectory_if_module_enabled(Path)
set(Filtering_MODULES
AnisotropicSmoothing
AntiAlias
BinaryMathematicalMorphology
Colormap
Convolution
CurvatureFlow
DistanceMap
FastMarching
FFT
ImageCompare
ImageCompose
ImageFeature
ImageFilterBase
ImageFusion
ImageGradient
ImageGrid
ImageIntensity
ImageLabel
ImageStatistics
LabelMap
MathematicalMorphology
Path
QuadEdgeMeshFiltering
Smoothing
Thresholding
)

set(Filtering_MODULES_IGNORED
# TODO: Fix ImageGradient examples and re-enable
ImageGradient
)

foreach(_module ${Filtering_MODULES})
if(NOT (${_module} IN_LIST Filtering_MODULES_IGNORED))
add_subdirectory_if_module_enabled(${_module})
endif()
add_module_archives(${_module})
endforeach()
14 changes: 14 additions & 0 deletions src/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
set(IO_MODULES
ImageBase
Mesh
TIFF
GDCM
TransformBase
TransformFactory
)

# Add subdirectories with corresponding ITK module names
add_subdirectory_if_module_enabled(ImageBase ITKIOImageBase)
add_subdirectory_if_module_enabled(Mesh ITKIOMesh)
add_subdirectory_if_module_enabled(TIFF ITKIOTIFF)
add_subdirectory_if_module_enabled(GDCM ITKGDCM)
add_subdirectory_if_module_enabled(TransformBase)
add_subdirectory_if_module_enabled(TransformFactory)

foreach(_module ${IO_MODULES})
add_module_archives(${_module})
endforeach()
1 change: 1 addition & 0 deletions src/Nonunit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory_if_module_enabled(Review)
add_module_archives(Review)
11 changes: 9 additions & 2 deletions src/Numerics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
add_subdirectory_if_module_enabled(Statistics)
add_subdirectory_if_module_enabled(Optimizers)
set(Numerics_MODULES
Optimizers
Statistics
)

foreach(_module ${Numerics_MODULES})
add_subdirectory_if_module_enabled(${_module})
add_module_archives(${_module})
endforeach()
11 changes: 9 additions & 2 deletions src/Registration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
add_subdirectory_if_module_enabled(Common)
add_subdirectory_if_module_enabled(Metricsv4)
set(Numerics_MODULES
Common
Metricsv4
)

foreach(_module ${Numerics_MODULES})
add_subdirectory_if_module_enabled(${_module})
add_module_archives(${_module})
endforeach()
1 change: 1 addition & 0 deletions src/Remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(Remote)
add_subdirectory_if_module_enabled(WikiExamples)
add_module_archives(WikiExamples)
31 changes: 21 additions & 10 deletions src/Segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
add_subdirectory_if_module_enabled(LevelSets)
add_subdirectory_if_module_enabled(LabelVoting)
add_subdirectory_if_module_enabled(Watersheds)
add_subdirectory_if_module_enabled(Classifiers)
add_subdirectory_if_module_enabled(Voronoi)
add_subdirectory_if_module_enabled(ConnectedComponents)
add_subdirectory_if_module_enabled(RegionGrowing)
if(ENABLE_QUICKVIEW)
add_subdirectory_if_module_enabled(KLMRegionGrowing)
endif()
set(Segmentation_MODULES
Classifiers
CMakeLists.txt
ConnectedComponents
index.rst
KLMRegionGrowing
LabelVoting
LevelSets
RegionGrowing
Voronoi
Watersheds
)

set(QUICKVIEW_MODULES KLMRegionGrowing)

foreach(_module ${Segmentation_MODULES})
if(ENABLE_QUICKVIEW OR NOT (${_module} IN_LIST QUICKVIEW_MODULES))
add_subdirectory_if_module_enabled(${_module})
endif()
add_module_archives(${_module})
endforeach()
1 change: 1 addition & 0 deletions src/Video/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory_if_module_enabled(BridgeOpenCV ITKVideoBridgeOpenCV)
add_module_archives(BridgeOpenCV)

1 comment on commit 4ffdcb9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.