1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 12:16:40 +08:00

Explicitly specify language flag when source LANGUAGE property is set

Fixes: #14516, #20716
This commit is contained in:
Robert Maynard
2020-06-01 13:45:13 -04:00
parent 457170a476
commit 74b1c9fc8e
7 changed files with 59 additions and 2 deletions

View File

@@ -349,6 +349,13 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
if (language.empty()) { if (language.empty()) {
language = "C"; 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 = std::string const& config =
lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"); lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");

View File

@@ -819,6 +819,14 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
default: default:
break; 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"); const std::string COMPILE_FLAGS("COMPILE_FLAGS");
if (cmProp cflags = sf->GetProperty(COMPILE_FLAGS)) { if (cmProp cflags = sf->GetProperty(COMPILE_FLAGS)) {
lg->AppendFlags(flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS)); lg->AppendFlags(flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));

View File

@@ -532,6 +532,13 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
// Build the set of compiler flags. // Build the set of compiler flags.
std::string 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. // Add language-specific flags.
std::string langFlags = cmStrCat("$(", lang, "_FLAGS", filterArch, ")"); std::string langFlags = cmStrCat("$(", lang, "_FLAGS", filterArch, ")");
this->LocalGenerator->AppendFlags(flags, langFlags); this->LocalGenerator->AppendFlags(flags, langFlags);

View File

@@ -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. // Add Fortran format flags.
if (language == "Fortran") { if (language == "Fortran") {

View File

@@ -8,3 +8,10 @@ add_executable(SetLang bar.c)
set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX) set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX)
target_link_libraries(SetLang foo) target_link_libraries(SetLang foo)
set_target_properties(SetLang PROPERTIES LINKER_LANGUAGE CXX) 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()

View File

@@ -1,10 +1,22 @@
#include <stdio.h> #include <stdio.h>
int foo(); int foo();
#ifdef WITH_ZOOM
int zoom();
#endif
class A class A
{ {
public: public:
A() { this->i = foo(); } A()
{
this->i = foo();
#ifdef WITH_ZOOM
i += zoom();
i -= zoom();
#endif
}
int i; int i;
}; };

7
Tests/SetLang/zoom.zzz Normal file
View File

@@ -0,0 +1,7 @@
int zoom()
{
int r = 10;
r++;
int ret = r + 10;
return ret;
}