summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Maynard <robert.maynard@kitware.com>2020-06-01 17:45:13 (GMT)
committerRobert Maynard <robert.maynard@kitware.com>2020-06-09 23:41:20 (GMT)
commit74b1c9fc8e8b33c8faa9aadf6ce09c15d94ea011 (patch)
tree4574908690751173637e9ef498c495f6a1501e63
parent457170a476ca3ff3b5db80360a7fd8202ac31e91 (diff)
downloadCMake-74b1c9fc8e8b33c8faa9aadf6ce09c15d94ea011.zip
CMake-74b1c9fc8e8b33c8faa9aadf6ce09c15d94ea011.tar.gz
CMake-74b1c9fc8e8b33c8faa9aadf6ce09c15d94ea011.tar.bz2
Explicitly specify language flag when source LANGUAGE property is set
Fixes: #14516, #20716
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx7
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx8
-rw-r--r--Source/cmMakefileTargetGenerator.cxx7
-rw-r--r--Source/cmNinjaTargetGenerator.cxx11
-rw-r--r--Tests/SetLang/CMakeLists.txt7
-rw-r--r--Tests/SetLang/bar.c14
-rw-r--r--Tests/SetLang/zoom.zzz7
7 files changed, 59 insertions, 2 deletions
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 613a943..3e265a0 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -349,6 +349,13 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
if (language.empty()) {
language = "C";
}
+
+ // explicitly add the explicit language flag before any other flag
+ // this way backwards compatibility with user flags is maintained
+ if (source->GetProperty("LANGUAGE")) {
+ lg->AppendFeatureOptions(flags, language, "EXPLICIT_LANGUAGE");
+ }
+
std::string const& config =
lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index a5ce5d1..4d589ed 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -819,6 +819,14 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
default:
break;
}
+
+ // explicitly add the explicit language flag before any other flag
+ // this way backwards compatibility with user flags is maintained
+ if (sf->GetProperty("LANGUAGE")) {
+ this->CurrentLocalGenerator->AppendFeatureOptions(flags, lang,
+ "EXPLICIT_LANGUAGE");
+ }
+
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
if (cmProp cflags = sf->GetProperty(COMPILE_FLAGS)) {
lg->AppendFlags(flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 8396fa3..6887569 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -532,6 +532,13 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
// Build the set of compiler flags.
std::string flags;
+ // explicitly add the explicit language flag before any other flag
+ // this way backwards compatibility with user flags is maintained
+ if (source.GetProperty("LANGUAGE")) {
+ this->LocalGenerator->AppendFeatureOptions(flags, lang,
+ "EXPLICIT_LANGUAGE");
+ }
+
// Add language-specific flags.
std::string langFlags = cmStrCat("$(", lang, "_FLAGS", filterArch, ")");
this->LocalGenerator->AppendFlags(flags, langFlags);
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index d406c99..0c7591a 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -188,7 +188,16 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
}
}
- std::string flags = this->GetFlags(language, config, filterArch);
+ std::string flags;
+ // explicitly add the explicit language flag before any other flag
+ // this way backwards compatibility with user flags is maintained
+ if (source->GetProperty("LANGUAGE")) {
+ this->LocalGenerator->AppendFeatureOptions(flags, language,
+ "EXPLICIT_LANGUAGE");
+ flags += " ";
+ }
+
+ flags += this->GetFlags(language, config, filterArch);
// Add Fortran format flags.
if (language == "Fortran") {
diff --git a/Tests/SetLang/CMakeLists.txt b/Tests/SetLang/CMakeLists.txt
index f24e5cb..af90f11 100644
--- a/Tests/SetLang/CMakeLists.txt
+++ b/Tests/SetLang/CMakeLists.txt
@@ -8,3 +8,10 @@ add_executable(SetLang bar.c)
set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX)
target_link_libraries(SetLang foo)
set_target_properties(SetLang PROPERTIES LINKER_LANGUAGE CXX)
+
+if((CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang|MSVC|Borland|Embarcadero|Intel|TI|XL)"))
+ add_library(zoom zoom.zzz)
+ set_source_files_properties(zoom.zzz PROPERTIES LANGUAGE CXX)
+ target_link_libraries(SetLang zoom)
+ target_compile_definitions(SetLang PRIVATE WITH_ZOOM)
+endif()
diff --git a/Tests/SetLang/bar.c b/Tests/SetLang/bar.c
index b934356..515e8c2 100644
--- a/Tests/SetLang/bar.c
+++ b/Tests/SetLang/bar.c
@@ -1,10 +1,22 @@
#include <stdio.h>
int foo();
+
+#ifdef WITH_ZOOM
+int zoom();
+#endif
+
class A
{
public:
- A() { this->i = foo(); }
+ A()
+ {
+ this->i = foo();
+#ifdef WITH_ZOOM
+ i += zoom();
+ i -= zoom();
+#endif
+ }
int i;
};
diff --git a/Tests/SetLang/zoom.zzz b/Tests/SetLang/zoom.zzz
new file mode 100644
index 0000000..a0c8899
--- /dev/null
+++ b/Tests/SetLang/zoom.zzz
@@ -0,0 +1,7 @@
+int zoom()
+{
+ int r = 10;
+ r++;
+ int ret = r + 10;
+ return ret;
+}