Skip to content

Conversation

@patstew
Copy link
Contributor

@patstew patstew commented Sep 24, 2024

CPM currently adds a FindFoo.cmake to the module path to override subsequent find_package calls. This makes sure that works when the find_package call is in CONFIG mode as well. Some of my dependencies use this in their CMakeLists.txt. This is equivalent to the OVERRIDE_FIND_PACKAGE argument to FetchContent, we could add that option to CPMAddPackage, but it seems like this is the intended default behaviour of CPM?

The include(....-extra.cmake) bits are something FetchContent does that's also useful here. They should maybe be added to the Find*.cmake version too?

Fixes #498

Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR and sorry for taking long to review it! It looks great on first glance, I have one small suggestion for readability. Also I'm not sure why the CI pipelines are not running, do you need to enable GitHub actions for your fork?

@patstew patstew force-pushed the override_find_package_config_mode branch from 121410c to b9499c0 Compare December 18, 2024 15:19
@patstew
Copy link
Contributor Author

patstew commented Dec 18, 2024

No worries, thanks for CPM.
I have added some documentation.
I think you need to approve it to run the tests https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/approving-workflow-runs-from-public-forks
There should be an "Approve and Run" button somewhere for you?

@TheLartians
Copy link
Member

There should be an "Approve and Run" button somewhere for you?

Yep this time it showed the button, thanks for update!

Looks like we need to update the tests to support the different behavior based on the CMake version and also run
The code formatter (see here for more info).

@patstew patstew force-pushed the override_find_package_config_mode branch from b9499c0 to 8497a75 Compare December 20, 2024 08:44
@patstew patstew force-pushed the override_find_package_config_mode branch from 8497a75 to 8ff2d08 Compare December 20, 2024 09:08
@patstew
Copy link
Contributor Author

patstew commented Dec 20, 2024

I think I've fixed the issues (patstew#1). I've also added a few checks to the modules.cmake test so that it fails without the fixes in this commit, and ensures the fallback to the old method works. I've got rid of the simple check that FindA.cmake exists and reinstated the check that find_package works instead. Was there was a reason for the find_package to be disabled previously?

Copy link
Member

@TheLartians TheLartians left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for updating this feature and the according documentation and test changes!

Was there was a reason for the find_package to be disabled previously?

Probably an oversight, good catch!

@TheLartians TheLartians merged commit 9ddfe1b into cpm-cmake:master Dec 20, 2024
11 checks passed
@TheLartians
Copy link
Member

Changes released in v0.40.3 🎉

@jay3d
Copy link

jay3d commented Jan 4, 2025

This change breaks my configuration that worked in v0.40.2 before.
I have two packages that are added via CPM, and one is dependent on the other, now the "next" package won't find the first one anymore after this change, that was working fine before by default:

CPMAddPackage(
        NAME TBB
        GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git
        GIT_TAG v2021.13.0
        EXCLUDE_FROM_ALL YES
        SYSTEM YES
)

CPMAddPackage(
        NAME OpenSubdiv
        GIT_REPOSITORY https://github.com/PixarAnimationStudios/OpenSubdiv.git
        GIT_TAG v3_6_0
        EXCLUDE_FROM_ALL YES
        SYSTEM YES
)

Now it can't find TBB anymore in .3 and above.

rapids-bot bot pushed a commit to rapidsai/rapids-cmake that referenced this pull request Oct 1, 2025
We'd like to use the latest CPM. The test change is due to cpm-cmake/CPM.cmake#604, which was released as part of [CPM 0.40.3](https://github.com/cpm-cmake/CPM.cmake/releases/tag/v0.40.3). The main change is that CPM produces config files instead of find modules so that CPM-downloaded packages will also be found by `find_package` in CONFIG mode.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Robert Maynard (https://github.com/robertmaynard)

URL: #916
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.

OVERRIDE_FIND_PACKAGE doesn't work

3 participants