mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
find_package: Improve CMP0074 warning messages
Policy `CMP0074` was added by commit eb35d8884b (find_package: Use
PackageName_ROOT variables as search prefixes, 2018-03-15). Revise the
logic to avoid warning when a `PackageName_ROOT` variable is set to
empty since that won't change the search behavior. Also, when we do
warn include the variable value(s) for reference.
This commit is contained in:
@@ -162,16 +162,22 @@ void cmMakefile::MaybeWarnCMP0074(std::string const& pkg)
|
||||
{
|
||||
// Warn if a <pkg>_ROOT variable we may use is set.
|
||||
std::string const varName = pkg + "_ROOT";
|
||||
bool const haveVar = this->GetDefinition(varName) != nullptr;
|
||||
bool const haveEnv = cmSystemTools::HasEnv(varName);
|
||||
const char* var = this->GetDefinition(varName);
|
||||
std::string env;
|
||||
cmSystemTools::GetEnv(varName, env);
|
||||
|
||||
bool const haveVar = var && *var;
|
||||
bool const haveEnv = !env.empty();
|
||||
if ((haveVar || haveEnv) && this->WarnedCMP0074.insert(varName).second) {
|
||||
std::ostringstream w;
|
||||
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0074) << "\n";
|
||||
if (haveVar) {
|
||||
w << "CMake variable " << varName << " is set.\n";
|
||||
w << "CMake variable " << varName << " is set to:\n"
|
||||
<< " " << var << "\n";
|
||||
}
|
||||
if (haveEnv) {
|
||||
w << "Environment variable " << varName << " is set.\n";
|
||||
w << "Environment variable " << varName << " is set to:\n"
|
||||
<< " " << env << "\n";
|
||||
}
|
||||
w << "For compatibility, CMake is ignoring the variable.";
|
||||
this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
|
||||
|
||||
@@ -7,9 +7,13 @@ CMake Warning \(dev\) at CMP0074-common.cmake:[0-9]+ \(find_package\):
|
||||
Run "cmake --help-policy CMP0074" for policy details. Use the cmake_policy
|
||||
command to set the policy and suppress this warning.
|
||||
|
||||
CMake variable Foo_ROOT is set.
|
||||
CMake variable Foo_ROOT is set to:
|
||||
|
||||
Environment variable Foo_ROOT is set.
|
||||
.*/Tests/RunCMake/find_package/PackageRoot/foo/cmake_root
|
||||
|
||||
Environment variable Foo_ROOT is set to:
|
||||
|
||||
.*/Tests/RunCMake/find_package/PackageRoot/foo/env_root
|
||||
|
||||
For compatibility, CMake is ignoring the variable.
|
||||
Call Stack \(most recent call first\):
|
||||
|
||||
Reference in New Issue
Block a user