summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorEugene Shalygin <eugene.shalygin@gmail.com>2021-07-07 12:41:34 (GMT)
committerBrad King <brad.king@kitware.com>2021-07-08 12:03:38 (GMT)
commita2e9fe38e43bd73513cde410f83e53e0c31ec6d6 (patch)
tree5967cc1531f5a4f5c561c6d1159c9a98db434036 /Source/cmFindPackageCommand.cxx
parentd49b507bb6fb798bdab3edc738af80495efa979f (diff)
downloadCMake-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 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx24
1 files changed, 21 insertions, 3 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index fba736e..a0de74c 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -478,17 +478,35 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
this->VersionMaxPatch, this->VersionMaxTweak);
}
+ const std::string makePackageRequiredVar =
+ cmStrCat("CMAKE_REQUIRE_FIND_PACKAGE_", this->Name);
+ const bool makePackageRequiredSet =
+ this->Makefile->IsOn(makePackageRequiredVar);
+ if (makePackageRequiredSet) {
+ if (this->Required) {
+ this->Makefile->IssueMessage(
+ MessageType::WARNING,
+ cmStrCat("for module ", this->Name,
+ " already called with REQUIRED, thus ",
+ makePackageRequiredVar, " has no effect."));
+ } else {
+ this->Required = true;
+ }
+ }
+
std::string disableFindPackageVar =
cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name);
if (this->Makefile->IsOn(disableFindPackageVar)) {
if (this->Required) {
this->SetError(
- cmStrCat("for module ", this->Name, " called with REQUIRED, but ",
- disableFindPackageVar,
+ cmStrCat("for module ", this->Name,
+ (makePackageRequiredSet
+ ? " was made REQUIRED with " + makePackageRequiredVar
+ : " called with REQUIRED, "),
+ " but ", disableFindPackageVar,
" is enabled. A REQUIRED package cannot be disabled."));
return false;
}
-
return true;
}