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 option to allow CPMFindPackage to behave as find_package #432

Open
kkraus14 opened this issue Dec 21, 2022 · 4 comments
Open

Add option to allow CPMFindPackage to behave as find_package #432

kkraus14 opened this issue Dec 21, 2022 · 4 comments

Comments

@kkraus14
Copy link

We currently use CPMFindPackage as a way to try to find a package if it currently exists on the users system, but then fall back to fetching it and building it from source if it doesn't currently exist. This works great for users in practice because generally it makes the builds just work which is the goal.

Unfortunately, one of the downsides to this is that for us as library maintainers and packagers, we can run into issues where in a packaging flow we expect to have all of the packages installed on the system, but if we miss something then it falls back to CPMAddPackage and can lead to us erroneously bundling that dependency in our package.

It would be great if there were options that had the opposite behavior of CPM_DOWNLOAD_ALL and CPM_DOWNLOAD_<dependency name> that would prevent fetching the package from source if it was failed to be found.

@TheLartians
Copy link
Member

Not sure I understand but does CPM_USE_LOCAL_PACKAGES not work for this?

@kkraus14
Copy link
Author

kkraus14 commented Jan 30, 2023

Indeed, using CPM_LOCAL_PACKAGES_ONLY seems to have the behavior I'm looking for, albeit with an extra call to cpm_find_package underneath the CPMAddPackage call, but that shouldn't be an issue. Apologies for the noise.

EDIT: Apologies, I forgot a critical detail of my use case, where there's a combination of CPMAddPackage and CPMFindPackage calls and the CPMAddPackage calls wouldn't be expected to function any differently where they would still fetch and build as expected.

@kkraus14 kkraus14 reopened this Jan 30, 2023
@ClausKlein
Copy link
Contributor

@kkraus14 Is you problem solved with setting CPM_USE_LOCAL_PACKAGES to NO?

@kkraus14
Copy link
Author

kkraus14 commented Feb 22, 2023

Unfortunately not. We have a scenario that looks roughly like the following:

...
# Always want to fetch these as we apply some patches on top of them or something else that prevents using a pre-installed package
CPMAddPackage(package_a ...)
CPMAddPackage(package_b ...)

# We want to find these on the system if they exist, if they don't exist then we want to fetch them (idea being to enable an end user to build and use the software as easily as possible)
# In the case of packaging the software, we don't want to bundle these packages with our software, so we'd love to have an option in CPM to not fall back to fetching if the option is set
CPMFindPackage(package_c ...)
CPMFindPackage(package_d ...)
CPMFindPackage(package_e ...)

Currently, CPM_USE_LOCAL_PACKAGES and CPM_LOCAL_PACKAGES_ONLY would enable what we want to do with packages c, d, and e in the above example, but would break what we need to do with packages a and b. If there was CPM_LOCAL_PACKAGE_ONLY_<dependency name> that would solve the problem or something more general that errors if CPMFindPackage fails to find the package locally instead of falling back to CPMAddPackage.

The workaround here looks something like wrapping CPMFindPackage behind another function call where if an option is set forwards it to find_package instead of CPMFindPackage.

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

No branches or pull requests

3 participants