Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add find_package overrides that also work in CONFIG mode (#498) #604

Merged

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?

cmake/CPM.cmake Show resolved Hide resolved
@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 🎉

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
2 participants