summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-27 16:48:39 -0500
committerBrad King <brad.king@kitware.com>2015-02-28 12:14:42 -0500
commit00d66557d49989f9813ba9f04beaa0a984699cf0 (patch)
tree921297d0937dbdfb57b9103ec23994cd1dc44d78
parent99575c9ac114e6f5d388e1ee7b9a3f788d773c9e (diff)
downloadcmake-00d66557d49989f9813ba9f04beaa0a984699cf0.tar.gz
Diagnose invalid <LANG>_STANDARD value instead of crashing (#15426)
-rw-r--r--Source/cmLocalGenerator.cxx9
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAStandard-result.txt1
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAStandard-stderr.txt4
-rw-r--r--Tests/RunCMake/CompileFeatures/NotAStandard.cmake2
-rw-r--r--Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake2
5 files changed, 17 insertions, 1 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 7ca7684c49..b64383fb1c 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -2270,7 +2270,14 @@ AddCompilerRequirementFlag(std::string &flags, cmTarget* target,
std::vector<std::string>::const_iterator stdIt =
std::find(stds.begin(), stds.end(), standard);
- assert(stdIt != stds.end());
+ if (stdIt == stds.end())
+ {
+ std::string e =
+ lang + "_STANDARD is set to invalid value '" + standard + "'";
+ this->GetGlobalGenerator()->GetCMakeInstance()
+ ->IssueMessage(cmake::FATAL_ERROR, e, target->GetBacktrace());
+ return;
+ }
std::vector<std::string>::const_iterator defaultStdIt =
std::find(stds.begin(), stds.end(), defaultStd);
diff --git a/Tests/RunCMake/CompileFeatures/NotAStandard-result.txt b/Tests/RunCMake/CompileFeatures/NotAStandard-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAStandard-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CompileFeatures/NotAStandard-stderr.txt b/Tests/RunCMake/CompileFeatures/NotAStandard-stderr.txt
new file mode 100644
index 0000000000..deab12f820
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAStandard-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at NotAStandard.cmake:[0-9]+ \(add_library\):
+ CXX_STANDARD is set to invalid value 'bad'
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CompileFeatures/NotAStandard.cmake b/Tests/RunCMake/CompileFeatures/NotAStandard.cmake
new file mode 100644
index 0000000000..11529d85a5
--- /dev/null
+++ b/Tests/RunCMake/CompileFeatures/NotAStandard.cmake
@@ -0,0 +1,2 @@
+set(CMAKE_CXX_STANDARD bad)
+add_library(somelib STATIC empty.cpp)
diff --git a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
index 833a3150e1..c1b2227dac 100644
--- a/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CompileFeatures/RunCMakeTest.cmake
@@ -43,6 +43,8 @@ else()
endif()
if(CXX_STANDARD_DEFAULT)
+ run_cmake(NotAStandard)
+
foreach(standard 98 11)
file(READ
"${RunCMake_BINARY_DIR}/generate_feature_list-build/cxx${standard}_flag.txt"