Commit 7e81149
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
1 file changed
+0
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | 303 | | |
310 | 304 | | |
311 | 305 | | |
| |||
0 commit comments