summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-31 16:15:34 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-01-31 16:16:53 (GMT)
commitca0310b919cb389618d480cbdc0124609051866a (patch)
treebbc39c790611ea7fe05060fa594c59bbc2a0c589 /Source
parenta2dc420cd4946eb3b17fcdcc6c32dafc7c679ad5 (diff)
parent198650ae7399cc086c49e58b0a9e03e9efb86235 (diff)
downloadCMake-ca0310b919cb389618d480cbdc0124609051866a.zip
CMake-ca0310b919cb389618d480cbdc0124609051866a.tar.gz
CMake-ca0310b919cb389618d480cbdc0124609051866a.tar.bz2
Merge topic 'set-validate-cache-type'
198650ae73 set: warn if CACHE type is not recognized Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !2874
Diffstat (limited to 'Source')
-rw-r--r--Source/cmSetCommand.cxx11
-rw-r--r--Source/cmState.cxx13
-rw-r--r--Source/cmState.h2
3 files changed, 23 insertions, 3 deletions
diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx
index 1a2d1c6..b09e3ca 100644
--- a/Source/cmSetCommand.cxx
+++ b/Source/cmSetCommand.cxx
@@ -4,6 +4,7 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -112,7 +113,15 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
if (cache) {
std::string::size_type cacheStart = args.size() - 3 - (force ? 1 : 0);
- type = cmState::StringToCacheEntryType(args[cacheStart + 1].c_str());
+ if (!cmState::StringToCacheEntryType(args[cacheStart + 1].c_str(), type)) {
+ std::string m = "implicitly converting '" + args[cacheStart + 1] +
+ "' to 'STRING' type.";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
+ // Setting this may not be required, since it's
+ // initialized as a string. Keeping this here to
+ // ensure that the type is actually converting to a string.
+ type = cmStateEnums::STRING;
+ }
docstring = args[cacheStart + 2].c_str();
}
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index fdd7b3d..a08e9b8 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -75,14 +75,23 @@ const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type)
cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(const char* s)
{
+ cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
+ StringToCacheEntryType(s, type);
+ return type;
+}
+
+bool cmState::StringToCacheEntryType(const char* s,
+ cmStateEnums::CacheEntryType& type)
+{
int i = 0;
while (cmCacheEntryTypes[i]) {
if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
- return static_cast<cmStateEnums::CacheEntryType>(i);
+ type = static_cast<cmStateEnums::CacheEntryType>(i);
+ return true;
}
++i;
}
- return cmStateEnums::STRING;
+ return false;
}
bool cmState::IsCacheEntryType(std::string const& key)
diff --git a/Source/cmState.h b/Source/cmState.h
index e447485..f755f83 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -65,6 +65,8 @@ public:
cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot);
static cmStateEnums::CacheEntryType StringToCacheEntryType(const char*);
+ static bool StringToCacheEntryType(const char*,
+ cmStateEnums::CacheEntryType& type);
static const char* CacheEntryTypeToString(cmStateEnums::CacheEntryType);
static bool IsCacheEntryType(std::string const& key);