|
| 1 | +#----------------------------------------------------------------------------- |
| 2 | +# Get and build ITK using FetchContent |
| 3 | + |
| 4 | +include(FetchContent) |
| 5 | + |
| 6 | +# Set ITK Git repository and tag |
| 7 | +set(ITK_GIT_REPOSITORY "https://github.com/InsightSoftwareConsortium/ITK.git") |
| 8 | +set(ITK_GIT_TAG "main") |
| 9 | + |
| 10 | +if(NOT DEFINED ITK_BUILD_DEFAULT_MODULES) |
| 11 | + set(ITK_BUILD_DEFAULT_MODULES ON) |
| 12 | +endif() |
| 13 | + |
| 14 | +# Configure ITK-specific options that need to be set before FetchContent_Declare |
| 15 | +if(NOT BUILD_SHARED_LIBS) |
| 16 | + set(CMAKE_C_VISIBILITY_PRESET "hidden") |
| 17 | + set(CMAKE_CXX_VISIBILITY_PRESET "hidden") |
| 18 | + set(ITK_TEMPLATE_VISIBILITY_DEFAULT OFF) |
| 19 | +endif() |
| 20 | + |
| 21 | +set(Module_ITKReview ON CACHE INTERNAL "") |
| 22 | + |
| 23 | +# Set ITK build options |
| 24 | +set(ITK_USE_KWSTYLE OFF) |
| 25 | +set(BUILD_TESTING OFF) |
| 26 | +set(BUILD_EXAMPLES OFF) |
| 27 | + |
| 28 | +FetchContent_Declare( |
| 29 | + ITK |
| 30 | + GIT_REPOSITORY "${ITK_GIT_REPOSITORY}" |
| 31 | + GIT_TAG "${ITK_GIT_TAG}" |
| 32 | + EXCLUDE_FROM_ALL |
| 33 | + FIND_PACKAGE_ARGS |
| 34 | + NAMES |
| 35 | + ITK |
| 36 | +) |
| 37 | + |
| 38 | +FetchContent_MakeAvailable(ITK) |
| 39 | + |
| 40 | +# Check if FetchContent used find_package() or fetched from source |
| 41 | +FetchContent_GetProperties(ITK) |
| 42 | +if(ITK_SOURCE_DIR) |
| 43 | + message(STATUS "ITK fetched from repository and built from source") |
| 44 | + message(STATUS " Source directory: ${ITK_SOURCE_DIR}") |
| 45 | + message(STATUS " Binary directory: ${ITK_BINARY_DIR}") |
| 46 | + set(ITK_DIR "${ITK_BINARY_DIR}") |
| 47 | + |
| 48 | + include(${ITK_DIR}/ITKConfig.cmake) |
| 49 | +elseif(DEFINED ITK_FOUND) |
| 50 | + message(STATUS "ITK found via find_package()") |
| 51 | + # ITK_DIR should already be set by find_package() |
| 52 | +else() |
| 53 | + message(FATAL_ERROR "ITK configuration failed - no targets available") |
| 54 | +endif() |
| 55 | + |
| 56 | +# These ITK options conflict with ITKSphinxExamples build options. |
| 57 | +# Allow ITKSphinxExamples' cache variables to be respected. |
| 58 | +unset(BUILD_TESTING) |
| 59 | +unset(BUILD_EXAMPLES) |
0 commit comments