From 896f9f4993ed8c6148ceaa8f57fa44d7860b794b Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Wed, 17 Jun 2026 16:53:12 -0500 Subject: [PATCH] COMP: Wrap build-tree system include dirs in BUILD_INTERFACE A module's _SYSTEM_INCLUDE_DIRS entries are added to the module target's interface include directories verbatim, on the assumption that they are stable external/system paths present at both build and install time. A module that fetches a header-only dependency into its own build tree (for example a remote module using FetchContent) exposes a build-directory path here. install(EXPORT ITKTargets) then records an unrelocatable build-directory path in the interface and, under CMake 4.x, fails generation with "INTERFACE_INCLUDE_DIRECTORIES property contains path which is prefixed in the build directory". Wrap only build-tree-prefixed system include paths in $ so they apply to the build and are dropped from the install interface. Stable system paths are passed through unchanged, so behavior for the common case (e.g. an installed Eigen) is unaffected. --- CMake/ITKModuleMacros.cmake | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMake/ITKModuleMacros.cmake b/CMake/ITKModuleMacros.cmake index 81421133f4f..a0bac29ae09 100644 --- a/CMake/ITKModuleMacros.cmake +++ b/CMake/ITKModuleMacros.cmake @@ -275,7 +275,18 @@ endif() # and thus do not have separate install interface paths. if(${itk-module}_SYSTEM_INCLUDE_DIRS) foreach(_dir ${${itk-module}_SYSTEM_INCLUDE_DIRS}) - list(APPEND ${itk-module}_SYSTEM_GENEX_INCLUDE_DIRS ${_dir}) + # Build-tree paths (e.g. fetched header-only deps) are build-only; wrap for install(EXPORT). + string(FIND "${_dir}" "${CMAKE_BINARY_DIR}" _itk_bin_prefix) + string(FIND "${_dir}" "${PROJECT_BINARY_DIR}" _itk_proj_prefix) + if(_itk_bin_prefix EQUAL 0 OR _itk_proj_prefix EQUAL 0) + list( + APPEND + ${itk-module}_SYSTEM_GENEX_INCLUDE_DIRS + "$" + ) + else() + list(APPEND ${itk-module}_SYSTEM_GENEX_INCLUDE_DIRS ${_dir}) + endif() endforeach() endif()