From cfca4368b9cd78849e067f116ccfc9b68eb45a0c Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Mon, 15 Dec 2025 20:16:32 +0000 Subject: [PATCH 1/2] COMP: Set CMake output directories as normal variables Normal CMake variable take priority over cache variables. The implemented logic is if ITK_WRAP is enabled then always set the output directories to known paths. Otherwise, if not user provided cache variable exists set the normal cmake variable to the default. This ignores user settings when wrapping is enabled, but restores then with wrapping is disabled. Remove cache variable setting of the following: - CMAKE_RUNTIME_OUTPUT_DIRECTORY - CMAKE_LIBRARY_OUTPUT_DIRECTORY - CMAKE_ARCHIVE_OUTPUT_DIRECTORY - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY Not force setting cmake output directories enables better usage with ITK as a FetchContent library. --- CMake/ITKModuleExternal.cmake | 51 +++++--------------------------- CMake/WrappingConfigCommon.cmake | 38 ++---------------------- CMakeLists.txt | 45 +++++++--------------------- Wrapping/CMakeLists.txt | 9 ++---- 4 files changed, 22 insertions(+), 121 deletions(-) diff --git a/CMake/ITKModuleExternal.cmake b/CMake/ITKModuleExternal.cmake index 0aa1b236f31..c750c7d65c0 100644 --- a/CMake/ITKModuleExternal.cmake +++ b/CMake/ITKModuleExternal.cmake @@ -75,55 +75,18 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") endif() -# The default path when not wrapping. Restore standard build location -# if python wrapping is turned on, and then turned off. +# When Wrapping is enabled the CMAKE_*_OUTPUT_DIRECTORY(s) will be explicitly set +include(WrappingConfigCommon) + +# Only set default if not prior configured by wrapping or the user if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) - set( - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - CACHE PATH - "Shared library directory" - ) -else() - set( - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - CACHE PATH - "Shared library directory" - ) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) - set( - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${ITK_BINARY_DIR}/bin - CACHE PATH - "Shared library directory" - ) -else() - set( - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - CACHE PATH - "Shared library directory" - ) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/bin) endif() - -include(WrappingConfigCommon) -# Setup build locations for shared libraries ----STOP - if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) - set( - CMAKE_ARCHIVE_OUTPUT_DIRECTORY - ${ITK_DIR}/${CMAKE_INSTALL_LIBDIR} - CACHE PATH - "Static library install directory" - ) - set( - CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY} - CACHE PATH - "Runtime library directory" - ) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() # ITK installation structure diff --git a/CMake/WrappingConfigCommon.cmake b/CMake/WrappingConfigCommon.cmake index 84d1e576dae..3ab2272840e 100644 --- a/CMake/WrappingConfigCommon.cmake +++ b/CMake/WrappingConfigCommon.cmake @@ -41,40 +41,8 @@ if(ITK_WRAPPING) # When wrapping, the multi-config generators can only be used in degraded state # of allowing only a single element int the CMAKE_CONFIGURATION_TYPES and enforcing # that CMAKE_BUILD_TYPE match that type (see Wrapping/CMakeLists.txt enforcement) - set( - CMAKE_LIBRARY_OUTPUT_DIRECTORY - "$<1:${ITK_PYTHON_PACKAGE_DIR}>" - CACHE PATH - "Shared library directory with generator override" - FORCE - ) - set( - CMAKE_RUNTIME_OUTPUT_DIRECTORY - "$<1:${ITK_PYTHON_PACKAGE_DIR}>" - CACHE PATH - "Shared library directory with generator override" - FORCE - ) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${ITK_PYTHON_PACKAGE_DIR}>") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "$<1:${ITK_PYTHON_PACKAGE_DIR}>") endif() -else() - set( - CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY} - CACHE PATH - "Shared library directory" - ) - set( - CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY} - CACHE PATH - "Runtime library directory" - ) endif() -mark_as_advanced( - FORCE - CMAKE_RUNTIME_OUTPUT_DIRECTORY - CMAKE_LIBRARY_OUTPUT_DIRECTORY - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - Python3_ROOT_DIR -) +mark_as_advanced(FORCE Python3_ROOT_DIR) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8050af1e14a..988ea72ad77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,44 +345,22 @@ if(NOT DEFINED CMAKE_FIND_USE_PACKAGE_REGISTRY) set(CMAKE_FIND_USE_PACKAGE_REGISTRY 0) endif() -# Setup build locations for shared libraries ----START -# ITK/CMakeLists.txt -- use ITK_BINARY_DIR as root -# ITK/CMake/ITKModuleExternal.cmake -- use ITK_DIR as root +# Setup build locations for libraries ----START # -# The default path when not wrapping. Restore standard build location -# if python wrapping is turned on, and then turned off. +# When Wrapping is enabled the CMAKE_*_OUTPUT_DIRECTORY(s) will be explicitly set +include(WrappingConfigCommon) + +# Only set default is not prior configured by wrapping or the user if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) - set( - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR} - CACHE PATH - "Shared library directory" - ) -else() - set( - NO_WRAP_CMAKE_LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - CACHE PATH - "Shared library directory" - ) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) - set( - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${ITK_BINARY_DIR}/bin - CACHE PATH - "Shared library directory" - ) -else() - set( - NO_WRAP_CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - CACHE PATH - "Shared library directory" - ) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/bin) +endif() +if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() -include(WrappingConfigCommon) # Setup build locations for shared libraries ----STOP if(CMAKE_CONFIGURATION_TYPES AND ITK_WRAPPING) @@ -399,9 +377,6 @@ if(CMAKE_CONFIGURATION_TYPES AND ITK_WRAPPING) ) endif() -if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ITK_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) -endif() set(ITK_MODULES_DIR "${ITK_BINARY_DIR}/${ITK_INSTALL_PACKAGE_DIR}/Modules") #----------------------------------------------------------------------------- diff --git a/Wrapping/CMakeLists.txt b/Wrapping/CMakeLists.txt index 2e4f2b59020..beed9ff489c 100644 --- a/Wrapping/CMakeLists.txt +++ b/Wrapping/CMakeLists.txt @@ -60,13 +60,8 @@ set( ) if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) - # See ITK/CMakeLists.txt for rational for overwriting multi-config default behavior of appending $ - set( - CMAKE_LIBRARY_OUTPUT_DIRECTORY - "$<1:${WrapITK_BINARY_DIR}/lib>" - CACHE INTERNAL - "Single output directory for building all libraries." - ) + # See ITK/WrappingConfigCommon.cmake for rational for overwriting multi-config default behavior of appending $ + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${WrapITK_BINARY_DIR}/lib>") endif() if(NOT EXECUTABLE_OUTPUT_PATH) From ffaa0c946e3fa3381c238aa7ff286b5e01928944 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Thu, 18 Dec 2025 16:13:35 +0000 Subject: [PATCH 2/2] ENH: Remove legacy and unused Wrapping EXECUTE_OUTPUT_PATH CMake document this as "Old executable location variable". And the RUNTIME_OUTPUT_DIRECTORY target property supersedes this variable. Additionally the CXX_TEST_PATH variable was not used. --- Wrapping/CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Wrapping/CMakeLists.txt b/Wrapping/CMakeLists.txt index beed9ff489c..1f4d8c95cd3 100644 --- a/Wrapping/CMakeLists.txt +++ b/Wrapping/CMakeLists.txt @@ -64,15 +64,6 @@ if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "$<1:${WrapITK_BINARY_DIR}/lib>") endif() -if(NOT EXECUTABLE_OUTPUT_PATH) - set( - EXECUTABLE_OUTPUT_PATH - ${WrapITK_BINARY_DIR}/bin - CACHE INTERNAL - "Single output directory for building all executables." - ) -endif() - # Set WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER to a non-null value, like # "Wrapping", which will be inserted into the wrapping install component name. # This can be used to split installation package components. @@ -92,12 +83,9 @@ endif() mark_as_advanced( CMAKE_LIBRARY_OUTPUT_DIRECTORY - EXECUTABLE_OUTPUT_PATH WRAP_ITK_INSTALL_PREFIX ) -set(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) - ############################################################################### # Additional files for installation ###############################################################################