diff options
author | Eugene Shalygin <eugene.shalygin@gmail.com> | 2021-07-07 12:41:34 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-07-08 12:03:38 (GMT) |
commit | a2e9fe38e43bd73513cde410f83e53e0c31ec6d6 (patch) | |
tree | 5967cc1531f5a4f5c561c6d1159c9a98db434036 /Tests/RunCMake/find_package | |
parent | d49b507bb6fb798bdab3edc738af80495efa979f (diff) | |
download | CMake-a2e9fe38e43bd73513cde410f83e53e0c31ec6d6.zip CMake-a2e9fe38e43bd73513cde410f83e53e0c31ec6d6.tar.gz CMake-a2e9fe38e43bd73513cde410f83e53e0c31ec6d6.tar.bz2 |
find_package: Add variable to make package REQUIRED
Add a `CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable is complement
to `CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` with just the opposite
behaviour: it turns non-required find_package call into the required one.
While optional package dependencies usually result in simple and clean
build logic, sometimes people want to be sure those optional
dependencies will be found and used. Examples are reproducible builds
and build instructions for 3rd parties. People choose to make
find_package calls REQUIRED and put them behind an option(). Such
workarounds blend build logic with build environment management and do
not look elegant.
Diffstat (limited to 'Tests/RunCMake/find_package')
7 files changed, 43 insertions, 0 deletions
diff --git a/Tests/RunCMake/find_package/MissingNormalForceRequired-result.txt b/Tests/RunCMake/find_package/MissingNormalForceRequired-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalForceRequired-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/MissingNormalForceRequired-stderr.txt b/Tests/RunCMake/find_package/MissingNormalForceRequired-stderr.txt new file mode 100644 index 0000000..f6c0b44 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalForceRequired-stderr.txt @@ -0,0 +1,20 @@ +CMake Error at MissingNormalForceRequired.cmake:2 \(find_package\): + No "FindNotHere.cmake" found in CMAKE_MODULE_PATH\. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Warning \(dev\) at MissingNormalForceRequired.cmake:2 \(find_package\): + FindNotHere.cmake must either be part of this project itself, in this case + adjust CMAKE_MODULE_PATH so that it points to the correct location inside + its source tree\. + + Or it must be installed by a package which has already been found via + find_package\(\)\. In this case make sure that package has indeed been found + and adjust CMAKE_MODULE_PATH to contain the location where that package has + installed FindNotHere\.cmake\. This must be a location provided by that + package. This error in general means that the buildsystem of this project + is relying on a Find-module without ensuring that it is actually available\. + +Call Stack \(most recent call first\): + CMakeLists\.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/find_package/MissingNormalForceRequired.cmake b/Tests/RunCMake/find_package/MissingNormalForceRequired.cmake new file mode 100644 index 0000000..5935316 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalForceRequired.cmake @@ -0,0 +1,3 @@ +set(CMAKE_REQUIRE_FIND_PACKAGE_NotHere ON) +find_package(NotHere MODULE) +message(FATAL_ERROR "This error must not be reachable.") diff --git a/Tests/RunCMake/find_package/RequiredOptionValuesClash-result.txt b/Tests/RunCMake/find_package/RequiredOptionValuesClash-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/find_package/RequiredOptionValuesClash-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/RequiredOptionValuesClash-stderr.txt b/Tests/RunCMake/find_package/RequiredOptionValuesClash-stderr.txt new file mode 100644 index 0000000..b4fdd98 --- /dev/null +++ b/Tests/RunCMake/find_package/RequiredOptionValuesClash-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at RequiredOptionValuesClash.cmake:4 \(find_package\): + find_package for module Foo was made REQUIRED with + CMAKE_REQUIRE_FIND_PACKAGE_Foo but CMAKE_DISABLE_FIND_PACKAGE_Foo is + enabled. A REQUIRED package cannot be disabled. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at RequiredOptionValuesClash.cmake:5 \(message\): + This error must not be reachable\. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/RequiredOptionValuesClash.cmake b/Tests/RunCMake/find_package/RequiredOptionValuesClash.cmake new file mode 100644 index 0000000..04fece7 --- /dev/null +++ b/Tests/RunCMake/find_package/RequiredOptionValuesClash.cmake @@ -0,0 +1,5 @@ +set(CMAKE_DISABLE_FIND_PACKAGE_Foo ON) +set(CMAKE_REQUIRE_FIND_PACKAGE_Foo ON) + +find_package(Foo) +message(FATAL_ERROR "This error must not be reachable.") diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index 3ba04c8..b20a889 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(ComponentRequiredAndOptional) run_cmake(FromPATHEnv) run_cmake(FromPrefixPath) run_cmake(MissingNormal) +run_cmake(MissingNormalForceRequired) run_cmake(MissingNormalRequired) run_cmake(MissingNormalVersion) run_cmake(MissingNormalWarnNoModuleOld) @@ -23,6 +24,7 @@ run_cmake(PackageRootNestedConfig) run_cmake(PackageRootNestedModule) run_cmake(PolicyPush) run_cmake(PolicyPop) +run_cmake(RequiredOptionValuesClash) run_cmake(SetFoundFALSE) run_cmake(WrongVersion) run_cmake(WrongVersionConfig) |