From 936d538edb53f37366637180c4e0ed205489ed2d Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 22 Sep 2026 13:51:41 -0500 Subject: [PATCH] BUG: Give the installed itkTestDriver an RPATH to ITK's libraries ITK's libraries are installed with @rpath install names, but the installed itkTestDriver carries no RPATH, so on macOS it fails to load libITKTestKernel from /lib and every external module test that runs through ITK_TEST_DRIVER aborts unless DYLD_LIBRARY_PATH is set. Set the install RPATH to the library directory relative to the runtime directory, which also covers Linux installs that do not add /lib to the loader path. --- Modules/Core/TestKernel/src/CMakeLists.txt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Modules/Core/TestKernel/src/CMakeLists.txt b/Modules/Core/TestKernel/src/CMakeLists.txt index 966d3d19963..64cce78bff3 100644 --- a/Modules/Core/TestKernel/src/CMakeLists.txt +++ b/Modules/Core/TestKernel/src/CMakeLists.txt @@ -22,6 +22,41 @@ if(NOT DO_NOT_BUILD_ITK_TEST_DRIVER) ) if(NOT DO_NOT_INSTALL_ITK_TEST_DRIVER) # used only by vcpkg + if( + IS_ABSOLUTE + "${ITK_INSTALL_RUNTIME_DIR}" + OR + IS_ABSOLUTE + "${ITK_INSTALL_LIBRARY_DIR}" + ) + # ITKModuleMacros assumes relative too, so the install tree is already + # wrong by this point (issue #6896). + message( + FATAL_ERROR + "ITK_INSTALL_RUNTIME_DIR ('${ITK_INSTALL_RUNTIME_DIR}') and ITK_INSTALL_LIBRARY_DIR ('${ITK_INSTALL_LIBRARY_DIR}') must be relative to CMAKE_INSTALL_PREFIX." + ) + else() + file( + RELATIVE_PATH + _itk_test_driver_rpath + "${CMAKE_INSTALL_PREFIX}/${ITK_INSTALL_RUNTIME_DIR}" + "${CMAKE_INSTALL_PREFIX}/${ITK_INSTALL_LIBRARY_DIR}" + ) + if(APPLE) + set(_itk_test_driver_rpath "@loader_path/${_itk_test_driver_rpath}") + else() + set(_itk_test_driver_rpath "$ORIGIN/${_itk_test_driver_rpath}") + endif() + set_property( + TARGET + itkTestDriver + APPEND + PROPERTY + INSTALL_RPATH + "${_itk_test_driver_rpath}" + ) + unset(_itk_test_driver_rpath) + endif() itk_module_target_install(itkTestDriver) endif() endif()