From 005f20265518b87ff6adab584267cd4fdcaffbdc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 11 Feb 2022 13:37:32 -0500 Subject: [PATCH] Add per package CPM_DOWNLOAD controls (#336) * Add per project CPM_DOWNLOAD controls Introduces support for `CPM__DOWNLOAD` variable ( and env ) which allows finer grained control. * Address PR feedback on API names --- README.md | 1 + cmake/CPM.cmake | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 20f635c..0e0819f 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ You can use `CPM_SOURCE_CACHE` on GitHub Actions workflows [cache](https://githu If set, CPM will forward all calls to `CPMFindPackage` as `CPMAddPackage`. This is useful to create reproducible builds or to determine if the source parameters have all been set correctly. This can also be set as an environmental variable. +This can be controlled on a per package basis with the `CPM_DOWNLOAD_` variable. ### CPM_USE_LOCAL_PACKAGES diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index e32b7d0..b7a6249 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -251,7 +251,13 @@ function(CPMFindPackage) endif() endif() - if(CPM_DOWNLOAD_ALL) + set(downloadPackage ${CPM_DOWNLOAD_ALL}) + if(DEFINED CPM_DOWNLOAD_${CPM_ARGS_NAME}) + set(downloadPackage ${CPM_DOWNLOAD_${CPM_ARGS_NAME}}) + elseif(DEFINED ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) + set(downloadPackage $ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}}) + endif() + if(downloadPackage) CPMAddPackage(${ARGN}) cpm_export_variables(${CPM_ARGS_NAME}) return()