Skip to content

[cmake] Make CCCL::CUB an IMPORTED target to allow downstream export#8330

Merged
alliepiper merged 1 commit intoNVIDIA:mainfrom
edenfunf:fix/cccl-cub-cmake-export
Apr 9, 2026
Merged

[cmake] Make CCCL::CUB an IMPORTED target to allow downstream export#8330
alliepiper merged 1 commit intoNVIDIA:mainfrom
edenfunf:fix/cccl-cub-cmake-export

Conversation

@edenfunf
Copy link
Copy Markdown
Contributor

@edenfunf edenfunf commented Apr 8, 2026

Description

closes #8069

When a downstream project links an interface library to CCCL::CUB and then tries to install(EXPORT ...) it, CMake fails with:

CMake Error in CMakeLists.txt:
  install(EXPORT "fooTargets" ...) includes target "foo" which requires
  target "_CUB_CUB" that is not in any export set.

Root cause: CCCL::CUB was created as an ALIAS for the non-IMPORTED internal target _CUB_CUB. When a target that links to CCCL::CUB is exported, CMake resolves the alias to _CUB_CUB and requires it to be in the export set—which it never is.

Fix: Create CCCL::CUB as an INTERFACE IMPORTED GLOBAL target that links to CUB::CUB, mirroring the approach already used by CCCL::Thrust (which thrust_create_target creates as IMPORTED GLOBAL). Since CCCL::CUB is IMPORTED, CMake treats it as an external dependency and does not require it in downstream export sets.

The include directories from _CUB_CUB remain non-SYSTEM (nvcc treats include dirs as SYSTEM only for IMPORTED targets that have them set directly; here they remain on the non-IMPORTED _CUB_CUB target and are propagated transitively).

Before / After:

# Before (broken for export):
add_library(CCCL::CUB ALIAS _CUB_CUB)

# After (consistent with CCCL::Thrust pattern):
add_library(CCCL::CUB INTERFACE IMPORTED GLOBAL)
target_link_libraries(CCCL::CUB INTERFACE CUB::CUB)

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Previously, CCCL::CUB was created as an ALIAS for the non-IMPORTED
_CUB_CUB target. When downstream projects tried to install(EXPORT ...)
a target that links to CCCL::CUB, CMake would resolve the alias and
complain that _CUB_CUB was not in any export set:

  CMake Error: install(EXPORT "fooTargets" ...) includes target "foo"
  which requires target "_CUB_CUB" that is not in any export set.

Fix this by creating CCCL::CUB as an INTERFACE IMPORTED GLOBAL target
that links to CUB::CUB, mirroring the pattern already used by
CCCL::Thrust (created via thrust_create_target as IMPORTED GLOBAL).
Since CCCL::CUB is IMPORTED, CMake treats it as an external dependency
and does not require it to be included in downstream export sets.

Fixes NVIDIA#8069
@edenfunf edenfunf requested a review from a team as a code owner April 8, 2026 13:24
@edenfunf edenfunf requested a review from bernhardmgruber April 8, 2026 13:24
@github-project-automation github-project-automation bot moved this to Todo in CCCL Apr 8, 2026
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot bot commented Apr 8, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Apr 8, 2026
@edenfunf
Copy link
Copy Markdown
Contributor Author

edenfunf commented Apr 9, 2026

@bernhardmgruber could you help review this PR? thanks!

@bernhardmgruber
Copy link
Copy Markdown
Contributor

@bernhardmgruber could you help review this PR? thanks!

I think we need our cmake guru here. @alliepiper can you talk a look please? Thx!

Copy link
Copy Markdown
Contributor

@alliepiper alliepiper left a comment

Choose a reason for hiding this comment

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

LGTM -- Thanks for the PR!

@alliepiper
Copy link
Copy Markdown
Contributor

/ok to test e2cba75

@alliepiper alliepiper enabled auto-merge (squash) April 9, 2026 16:48
@alliepiper
Copy link
Copy Markdown
Contributor

Those failures look unrelated, I'll look into them.

@edenfunf
Copy link
Copy Markdown
Contributor Author

edenfunf commented Apr 9, 2026

這些故障看起來互不相關,我會調查一下。

OK, thank you!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

🥳 CI Workflow Results

🟩 Finished in 1h 33m: Pass: 100%/478 | Total: 7d 21h | Max: 1h 28m | Hits: 96%/555534

See results here.

@alliepiper alliepiper merged commit 6c0a33e into NVIDIA:main Apr 9, 2026
495 of 499 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG]: Cannot export CMake interface target which links to CCCL::CUB

3 participants