mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
Explicitly specify language flag when source LANGUAGE property is set
Fixes: #14516, #20716
This commit is contained in:
@@ -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()
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
|
7
Tests/SetLang/zoom.zzz
Normal file
7
Tests/SetLang/zoom.zzz
Normal file
@@ -0,0 +1,7 @@
|
||||
int zoom()
|
||||
{
|
||||
int r = 10;
|
||||
r++;
|
||||
int ret = r + 10;
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user