mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-04 04:03:22 +03:00
target_compile_features: Do not crash on non-enabled language
Fixes: #17011
This commit is contained in:
1 parent
869904271b
commit
e03a1b3b61
5 files changed
+27
-2
No files matched your search
+19
-2
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -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\)$
|
||||
@@ -0,0 +1,2 @@
|
||||
add_executable(main empty.c)
|
||||
target_compile_features(main PRIVATE cxx_decltype)
|
||||
Reference in new issue
Block a user