Skip to content

Commit 7e81149

Browse files
authored
Use cpm_find_package to check if a package added (#552)
If I have a project, which has: 1. /CMakeLists.txt: ```cmake cmake_minimum_required(VERSION 3.29) project(test) include(./cmake/CPM.cmake) add_subdirectory(subdir) cpmfindpackage( NAME nlohmann_json VERSION 3.11.2 URL "https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz" EXCLUDE_FROM_ALL ON) if(NOT TARGET nlohmann_json::nlohmann_json) message(FATAL_ERROR "BUG") endif() ``` 2. /subdir/CMakeLists.txt ```cmake cpmfindpackage( NAME nlohmann_json VERSION 3.11.2 URL "https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz" EXCLUDE_FROM_ALL ON) ``` When nlohmann_json is first founded by find_package, CPM.cmake register this package and later call to CPMFindPackage will not actually perform a find_package again, which leads to this buggy behavior. As CPM write a FindXXX.cmake file for packages added by CPM to pervert find_package to get local package, I think directly use cpm_find_package to check if a package is already added is good enough.
1 parent 0e450ef commit 7e81149

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

cmake/CPM.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,6 @@ function(CPMFindPackage)
300300
return()
301301
endif()
302302

303-
cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}")
304-
if(CPM_PACKAGE_ALREADY_ADDED)
305-
cpm_export_variables(${CPM_ARGS_NAME})
306-
return()
307-
endif()
308-
309303
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
310304

311305
if(NOT CPM_PACKAGE_FOUND)

0 commit comments

Comments
 (0)