summaryrefslogtreecommitdiffstats
path: root/Source/cmOptionCommand.cxx
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2018-06-21 18:53:11 (GMT)
committerBrad King <brad.king@kitware.com>2018-07-09 11:48:28 (GMT)
commit2a5f5c0e316d415e1b8207348b34761d34f191ae (patch)
treea17a979c357a3148424b71fc0bcac898b1ec7e4a /Source/cmOptionCommand.cxx
parent12e6f83319d089b3295b4211d0d4810575e8f7d5 (diff)
downloadCMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.zip
CMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.tar.gz
CMake-2a5f5c0e316d415e1b8207348b34761d34f191ae.tar.bz2
option: respect existing normal variable
Add policy CMP0077 to change this behavior in a compatible way.
Diffstat (limited to 'Source/cmOptionCommand.cxx')
-rw-r--r--Source/cmOptionCommand.cxx52
1 files changed, 43 insertions, 9 deletions
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
index 13bcd03..4ab0e96 100644
--- a/Source/cmOptionCommand.cxx
+++ b/Source/cmOptionCommand.cxx
@@ -2,11 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmOptionCommand.h"
+#include <sstream>
+
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmPolicies.h"
#include "cmState.h"
+#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
+#include "cmake.h"
class cmExecutionStatus;
@@ -22,18 +27,47 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- std::string initialValue = "Off";
- // Now check and see if the value has been stored in the cache
- // already, if so use that value and don't look for the program
+ // 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;
+ }
+
+ // See if a cache variable with this name already exists
+ // If so just make sure the doc state is correct
cmState* state = this->Makefile->GetState();
const char* existingValue = state->GetCacheEntryValue(args[0]);
- if (existingValue) {
- if (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED) {
- state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
- return true;
- }
- initialValue = existingValue;
+ if (existingValue &&
+ (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED)) {
+ state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
+ return true;
}
+
+ // Nothing in the cache so add it
+ std::string initialValue = existingValue ? existingValue : "Off";
if (args.size() == 3) {
initialValue = args[2];
}