Commit ca0310b9 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'set-validate-cache-type'

198650ae

 set: warn if CACHE type is not recognized
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !2874
parents a2dc420c 198650ae
......@@ -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();
}
......
......@@ -74,15 +74,24 @@ 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)
......
......@@ -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);
......
......@@ -3,3 +3,4 @@ include(RunCMake)
run_cmake(ParentScope)
run_cmake(ParentPulling)
run_cmake(ParentPullingRecursive)
run_cmake(UnknownCacheType)
CMake Warning \(dev\) at UnknownCacheType.cmake:1 \(set\):
implicitly converting 'unknown_type_sample' to 'STRING' type.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
set (sample_key sample_value CACHE unknown_type_sample "sample doc")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment