Commit 74b1c9fc authored by Robert Maynard's avatar Robert Maynard
Browse files

Explicitly specify language flag when source LANGUAGE property is set

Fixes: #14516, #20716
parent 457170a4
......@@ -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");
......
......@@ -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));
......
......@@ -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);
......
......@@ -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") {
......
......@@ -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()
#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;
};
......
int zoom()
{
int r = 10;
r++;
int ret = r + 10;
return ret;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment