diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2018-07-10 17:56:15 (GMT) |
---|---|---|
committer | Robert Maynard <robert.maynard@kitware.com> | 2018-07-10 17:56:15 (GMT) |
commit | f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa (patch) | |
tree | 10f8144038e8f64907c5b9f2189a79d97e742f0c /Source | |
parent | 2a5f5c0e316d415e1b8207348b34761d34f191ae (diff) | |
download | CMake-f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa.zip CMake-f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa.tar.gz CMake-f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa.tar.bz2 |
option: No CMP077 warnings when both cache and local variable exists
Previously we would warn when the local and cache version of a variable
exists, but this use case doesn't need a warning as it maintains backwards
compatibility.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmOptionCommand.cxx | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx index 4ab0e96..239cd00 100644 --- a/Source/cmOptionCommand.cxx +++ b/Source/cmOptionCommand.cxx @@ -28,32 +28,28 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args, } // Determine the state of the option policy - auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077); - const char* exists = - this->Makefile->GetStateSnapshot().GetDefinition(args[0]); - switch (status) { - case cmPolicies::WARN: - if (exists) { - std::ostringstream w; - w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0077) - << "\n" - "For compatibility with older versions of CMake, option " - "is clearing the normal variable '" - << args[0] << "'."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); - } - case cmPolicies::OLD: - // OLD behavior does not warn. - break; - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::NEW: { - // See if a local variable with this name already exists. - // If so we ignore the option command. - if (exists) { - return true; - } - } break; + bool checkAndWarn = false; + { + auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077); + const char* existsBeforeSet = + this->Makefile->GetStateSnapshot().GetDefinition(args[0]); + switch (status) { + case cmPolicies::WARN: + checkAndWarn = (existsBeforeSet != nullptr); + break; + case cmPolicies::OLD: + // OLD behavior does not warn. + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: { + // See if a local variable with this name already exists. + // If so we ignore the option command. + if (existsBeforeSet) { + return true; + } + } break; + } } // See if a cache variable with this name already exists @@ -74,5 +70,19 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args, bool init = cmSystemTools::IsOn(initialValue.c_str()); this->Makefile->AddCacheDefinition(args[0], init ? "ON" : "OFF", args[1].c_str(), cmStateEnums::BOOL); + + if (checkAndWarn) { + const char* existsAfterSet = + this->Makefile->GetStateSnapshot().GetDefinition(args[0]); + if (!existsAfterSet) { + std::ostringstream w; + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0077) + << "\n" + "For compatibility with older versions of CMake, option " + "is clearing the normal variable '" + << args[0] << "'."; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + } + } return true; } |