summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-06-26 13:52:26 -0400
committerBrad King <brad.king@kitware.com>2017-06-26 13:54:20 -0400
commite03a1b3b6185e36a5905db3d2551c9575fb074aa (patch)
tree692470eaf5980b30a2631c612fd8bf0227bdab7f
parent869904271ba0e8b855043894360b5dc7fe1e3b56 (diff)
downloadcmake-e03a1b3b6185e36a5905db3d2551c9575fb074aa.tar.gz
target_compile_features: Do not crash on non-enabled language
Fixes: #17011
-rw-r--r--Source/cmMakefile.cxx21
-rw-r--r--Tests/RunCMake/target_compile_features/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/target_compile_features/cxx_not_enabled-result.txt1
-rw-r--r--Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/cxx_not_enabled.cmake2
5 files changed, 27 insertions, 2 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 802a427a66..608b18a46a 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4190,6 +4190,23 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target,
const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang,
std::string* error) const
{
+ if (!this->GlobalGenerator->GetLanguageEnabled(lang)) {
+ std::ostringstream e;
+ if (error) {
+ e << "cannot";
+ } else {
+ e << "Cannot";
+ }
+ e << " use features from non-enabled language " << lang;
+ if (error) {
+ *error = e.str();
+ } else {
+ this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Backtrace);
+ }
+ return CM_NULLPTR;
+ }
+
const char* featuresKnown =
this->GetDefinition("CMAKE_" + lang + "_COMPILE_FEATURES");
@@ -4201,9 +4218,9 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang,
e << "No";
}
e << " known features for " << lang << " compiler\n\""
- << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID")
+ << this->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_ID")
<< "\"\nversion "
- << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
+ << this->GetSafeDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << ".";
if (error) {
*error = e.str();
} else {
diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
index 33faf2bbb8..1f67f11a09 100644
--- a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
@@ -11,3 +11,4 @@ run_cmake(not_a_cxx_feature)
run_cmake(no_matching_cxx_feature)
run_cmake(not_a_c_feature)
run_cmake(no_matching_c_feature)
+run_cmake(cxx_not_enabled)
diff --git a/Tests/RunCMake/target_compile_features/cxx_not_enabled-result.txt b/Tests/RunCMake/target_compile_features/cxx_not_enabled-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/cxx_not_enabled-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt b/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt
new file mode 100644
index 0000000000..4f707c7b9a
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at cxx_not_enabled.cmake:[0-9]+ \(target_compile_features\):
+ target_compile_features cannot use features from non-enabled language CXX
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/target_compile_features/cxx_not_enabled.cmake b/Tests/RunCMake/target_compile_features/cxx_not_enabled.cmake
new file mode 100644
index 0000000000..b7e91196e4
--- /dev/null
+++ b/Tests/RunCMake/target_compile_features/cxx_not_enabled.cmake
@@ -0,0 +1,2 @@
+add_executable(main empty.c)
+target_compile_features(main PRIVATE cxx_decltype)