This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, master has been updated via 7b04ad61cf925161c8b7f9abf6ef3db047118807 (commit) via f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa (commit) from 05cd8311ab52cf1e1ca40701c092602fe51cfbe4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=7b04ad61cf925161c8b7f9abf6ef3db047118807 commit 7b04ad61cf925161c8b7f9abf6ef3db047118807 Merge: 05cd831 f8a7cf8 Author: Brad King <brad.k...@kitware.com> AuthorDate: Thu Jul 12 13:12:15 2018 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Thu Jul 12 09:12:26 2018 -0400 Merge topic 'option_respects_existing_stack_variable' f8a7cf85ad option: No CMP077 warnings when both cache and local variable exists Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !2203 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa commit f8a7cf85ad7ff9ed01987d5845dad46c395ac4fa Author: Robert Maynard <robert.mayn...@kitware.com> AuthorDate: Tue Jul 10 13:56:15 2018 -0400 Commit: Robert Maynard <robert.mayn...@kitware.com> CommitDate: Tue Jul 10 13:56:15 2018 -0400 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. 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; } diff --git a/Tests/RunCMake/option/CMP0077-SECOND-PASS.cmake b/Tests/RunCMake/option/CMP0077-SECOND-PASS.cmake new file mode 100644 index 0000000..f62a853 --- /dev/null +++ b/Tests/RunCMake/option/CMP0077-SECOND-PASS.cmake @@ -0,0 +1,14 @@ + +#Verify that when both a cache and local version of a value exist that CMake +#doesn't produce a CMP0077 warning and that we get the expected values. +option(OPT_LOCAL_VAR "TEST_VAR" ON) +set(OPT_LOCAL_VAR FALSE) +option(OPT_LOCAL_VAR "TEST_VAR" ON) +if(OPT_LOCAL_VAR) + message(FATAL_ERROR "option improperly set a cache variable that already exists") +endif() + +get_property(_exists_in_cache CACHE OPT_LOCAL_VAR PROPERTY VALUE SET) +if(NOT _exists_in_cache) + message(FATAL_ERROR "value should exist in cache") +endif() diff --git a/Tests/RunCMake/option/RunCMakeTest.cmake b/Tests/RunCMake/option/RunCMakeTest.cmake index 0501624..979afa1 100644 --- a/Tests/RunCMake/option/RunCMakeTest.cmake +++ b/Tests/RunCMake/option/RunCMakeTest.cmake @@ -3,3 +3,4 @@ include(RunCMake) run_cmake(CMP0077-OLD) run_cmake(CMP0077-NEW) run_cmake(CMP0077-WARN) +run_cmake(CMP0077-SECOND-PASS) ----------------------------------------------------------------------- Summary of changes: Source/cmOptionCommand.cxx | 62 ++++++++++++++----------- Tests/RunCMake/option/CMP0077-SECOND-PASS.cmake | 14 ++++++ Tests/RunCMake/option/RunCMakeTest.cmake | 1 + 3 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 Tests/RunCMake/option/CMP0077-SECOND-PASS.cmake hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org https://cmake.org/mailman/listinfo/cmake-commits