Skip to content

COMP: Fix the test link when ITK is built with wrapping enabled - #1

Merged
vboussot merged 2 commits into
mainfrom
comp-itk6-wrapping-test-link
Sep 17, 2026
Merged

vboussot merged 2 commits into
mainfrom
comp-itk6-wrapping-test-link

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Configuring against an ITK built with ITK_WRAP_PYTHON=ON fails in test/CMakeLists.txt, and the link it sets up is rejected by Apple's linker. Two CMake-only fixes; no C++ changes.

1. Plain vs keyword target_link_libraries

ITK creates the driver and links it with the keyword signature
(ITKModuleTest.cmake), so the plain call in impact_link_python_embed stops
configure:

CMake Error at test/CMakeLists.txt:51 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with
  the target "ImpactTestDriver".  All uses of target_link_libraries with a
  target must be either all-keyword or all-plain.
   * .../ITK/CMake/ITKModuleTest.cmake:84 (target_link_libraries)

ImpactGTestDriver is the mirror image: its own link is plain, so it fails as
soon as the function adds a keyword call. That block runs even with
Module_ITKGoogleTest=OFF, because ITK still exports a GTest::GTest target.

Both now use PRIVATE.

2. --no-as-needed on linkers that reject it
ld: unknown option: --no-as-needed

The flag keeps GNU ld from dropping libpython, which Apple's linker never does.
It is now passed only where it is understood.

Why this is not visible in CI today

impact_link_python_embed returns early unless ITK_WRAP_PYTHON is set, so the
failure needs an ITK built with wrapping enabled.

Verified in a downstream build matrix, macOS arm64, LibTorch from the torch
Python package:

ITK wrapping module source result
main (6.0.0) ON unmodified configure fails
main (6.0.0) ON with this PR builds, 51/51 tests pass
release-5.4 OFF unmodified builds, 51/51 tests pass

The 5.4 column is why this reads as a wrapping-enabled issue rather than an
ITK 6 one.

https://claude.ai/code/session_01S5zzoU6yyUwdLEvjM2s6iS

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.
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.
@hjmjohnson
hjmjohnson marked this pull request as ready for review September 17, 2026 14:59
@hjmjohnson
hjmjohnson requested a review from vboussot September 17, 2026 15:01
@vboussot

Copy link
Copy Markdown
Collaborator

Thanks!

@vboussot
vboussot merged commit 87263de into main Sep 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants