From 3aa5e0b2b1e39c434fcc36ed56848ef1bdebe247 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Thu, 17 Sep 2026 09:28:32 -0500 Subject: [PATCH 1/2] COMP: Link the test drivers with the keyword signature ITK creates ImpactTestDriver and links it with the keyword signature (ITKModuleTest.cmake), so impact_link_python_embed's plain-signature call makes CMake stop: "All uses of target_link_libraries with a target must be either all-keyword or all-plain". It only fires when ITK is built with ITK_WRAP_PYTHON=ON, since the function returns early otherwise. ImpactGTestDriver has the mirror of the problem: its own link is plain, so it breaks as soon as the function adds a keyword call. Its block runs even when Module_ITKGoogleTest is OFF, because ITK still exports a GTest::GTest target. --- test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 85659a1..def6d0f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,7 +48,7 @@ function(impact_link_python_embed target) set(_impact_pylib ${IMPACT_PYTHON_EMBED_LIBRARY}) endif() if(_impact_pylib) - target_link_libraries(${target} -Wl,--no-as-needed ${_impact_pylib} -Wl,--as-needed) + target_link_libraries(${target} PRIVATE -Wl,--no-as-needed ${_impact_pylib} -Wl,--as-needed) endif() endfunction() @@ -97,7 +97,7 @@ if(NOT TARGET GTest::GTest) endif() add_executable(ImpactGTestDriver itkImpactBackendGTest.cxx) -target_link_libraries(ImpactGTestDriver ${Impact-Test_LIBRARIES} Impact GTest::GTest) +target_link_libraries(ImpactGTestDriver PRIVATE ${Impact-Test_LIBRARIES} Impact GTest::GTest) impact_link_python_embed(ImpactGTestDriver) # The ImpactConvexAdam.RealLungCT* gtest runs on a real lung-CT pair (and the M258 model) # kept out of git. Fetch them via ITK ExternalData from the committed .sha512 content links From 38b400aed15d3d065a0798274ff4c3d8f1355de4 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Thu, 17 Sep 2026 09:28:32 -0500 Subject: [PATCH 2/2] COMP: Keep --no-as-needed off linkers that reject it Apple's linker fails with "ld: unknown option: --no-as-needed", so the Python-embed link breaks on macOS once it is reached. The flag exists to stop GNU ld dropping libpython, which Apple's linker never does, so pass it only where it is understood. --- test/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index def6d0f..874c6ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,7 +48,13 @@ function(impact_link_python_embed target) set(_impact_pylib ${IMPACT_PYTHON_EMBED_LIBRARY}) endif() if(_impact_pylib) - target_link_libraries(${target} PRIVATE -Wl,--no-as-needed ${_impact_pylib} -Wl,--as-needed) + # --no-as-needed is GNU-ld only; Apple's linker rejects it outright and + # never drops a needed library anyway. + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT APPLE AND NOT MSVC) + target_link_libraries(${target} PRIVATE -Wl,--no-as-needed ${_impact_pylib} -Wl,--as-needed) + else() + target_link_libraries(${target} PRIVATE ${_impact_pylib}) + endif() endif() endfunction()