Skip to content

Commit a02a960

Browse files
authored
SOURCE_DIR option disable call to find_package() (#456)
1 parent af3f1ca commit a02a960

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,14 @@ This can be controlled on a per package basis with the `CPM_DOWNLOAD_<dependency
199199
### CPM_USE_LOCAL_PACKAGES
200200

201201
CPM can be configured to use `find_package` to search for locally installed dependencies first by setting the CMake option `CPM_USE_LOCAL_PACKAGES`.
202+
202203
If the option `CPM_LOCAL_PACKAGES_ONLY` is set, CPM will emit an error if the dependency is not found locally.
203204
These options can also be set as environmental variables.
204205

205206
In the case that `find_package` requires additional arguments, the parameter `FIND_PACKAGE_ARGUMENTS` may be specified in the `CPMAddPackage` call. The value of this parameter will be forwarded to `find_package`.
206207

208+
Note that this does not apply to dependencies that have been defined with a truthy `FORCE` parameter. These will be added as defined.
209+
207210
### CPM_USE_NAMED_CACHE_DIRECTORIES
208211

209212
If set, CPM use additional directory level in cache to improve readability of packages names in IDEs like CLion. It changes cache structure, so all dependencies are downloaded again. There is no problem to mix both structures in one cache directory but then there may be 2 copies of some dependencies.

cmake/CPM.cmake

+13-11
Original file line numberDiff line numberDiff line change
@@ -648,19 +648,21 @@ function(CPMAddPackage)
648648
return()
649649
endif()
650650

651-
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
652-
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
651+
if(NOT CPM_ARGS_FORCE)
652+
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
653+
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
653654

654-
if(CPM_PACKAGE_FOUND)
655-
cpm_export_variables(${CPM_ARGS_NAME})
656-
return()
657-
endif()
655+
if(CPM_PACKAGE_FOUND)
656+
cpm_export_variables(${CPM_ARGS_NAME})
657+
return()
658+
endif()
658659

659-
if(CPM_LOCAL_PACKAGES_ONLY)
660-
message(
661-
SEND_ERROR
662-
"${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})"
663-
)
660+
if(CPM_LOCAL_PACKAGES_ONLY)
661+
message(
662+
SEND_ERROR
663+
"${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})"
664+
)
665+
endif()
664666
endif()
665667
endif()
666668

0 commit comments

Comments
 (0)