Skip to content

Address namespace issue with GoogleTest libraries#5789

Draft
blowekamp wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
blowekamp:gtest_alias_compatibility
Draft

Address namespace issue with GoogleTest libraries#5789
blowekamp wants to merge 3 commits intoInsightSoftwareConsortium:mainfrom
blowekamp:gtest_alias_compatibility

Conversation

@blowekamp
Copy link
Member

  • Add depreciation warning for the removed GTest::GTest and GTest::Main targets.
  • Correct the namespace to GTest in ITKTargets.

@blowekamp blowekamp requested a review from N-Dekker February 10, 2026 17:16
@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:ThirdParty Issues affecting the ThirdParty module labels Feb 10, 2026
@blowekamp blowekamp force-pushed the gtest_alias_compatibility branch from f54d8de to 9e28fc7 Compare February 10, 2026 17:16
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good.

mark_as_advanced(GTEST_HAS_ABSL)
if (NOT ITK_LEGACY_REMOVE)
add_library(GTest::GTest INTERFACE IMPORTED)
add_library(GTest::Main INTERFACE IMPORTED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not work for the elastix ITK6 build, at least for now, because elastix always builds with ITK_LEGACY_REMOVE 🤔

Do you propose all those changes, just to make elastix happy? I hope not 😇 If it's just for elastix, we might as well simply adjust elastix with some dedicated CMake code, if ITK6 ...

Copy link
Member Author

@blowekamp blowekamp Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the first commit: ec08359 was needed for your request.
The condition could be changed to ITK_FUTURE_LEGACY_REMOVE if that is prefered.

The rest is needed to fix "ITK::gtest" to be "GTest::gtest" ( and similar to gtest_main) in the ITKTargets.cmake file for exporting in the build directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the PR #5791, this alias was marked deprecated in CMake 3.20, and remove in 4.1.0. Given that I think the "ITK_LEGACY_REMOVE" is appropriate. Please let me know your preference for this code block

The ITK specific alias were removed, this change restores them with a
deprecated warning.
Change to a function to avoid side effects during call. Use
cmake_parse_arguments to parse additional NAMESPACE argument. Add
detection of existing alias before setting.
Use added NAMESPACE option to itk_module_target to keep GTest
namespace, fixing it being overridden to ITK.
@blowekamp blowekamp force-pushed the gtest_alias_compatibility branch from 9e28fc7 to 815e9bd Compare February 12, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ThirdParty Issues affecting the ThirdParty module type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants