Merge topic 'explicit-LANGUAGE-flag'

48aac247e9 Compile with explicit language flag when source LANGUAGE property is set
2e67a75acd Embarcadero: Simplify addition of -P flag for C++

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5522
This commit is contained in:
Brad King
2020-12-04 13:27:36 +00:00
committed by Kitware Robot
40 changed files with 203 additions and 9 deletions

View File

@@ -349,6 +349,11 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
if (language.empty()) {
language = "C";
}
// Explicitly add the explicit language flag before any other flag
// so user flags can override it.
gtgt->AddExplicitLanguageFlags(flags, *source);
std::string const& config =
lg->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");

View File

@@ -3155,6 +3155,30 @@ void cmGeneratorTarget::GetAppleArchs(const std::string& config,
}
}
void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags,
cmSourceFile const& sf) const
{
cmProp lang = sf.GetProperty("LANGUAGE");
if (!lang) {
return;
}
switch (this->GetPolicyStatusCMP0119()) {
case cmPolicies::WARN:
case cmPolicies::OLD:
// The OLD behavior is to not add explicit language flags.
return;
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
// The NEW behavior is to add explicit language flags.
break;
}
this->LocalGenerator->AppendFeatureOptions(flags, *lang,
"EXPLICIT_LANGUAGE");
}
void cmGeneratorTarget::AddCUDAArchitectureFlags(std::string& flags) const
{
const std::string& property = this->GetSafeProperty("CUDA_ARCHITECTURES");

View File

@@ -447,6 +447,9 @@ public:
void GetAppleArchs(const std::string& config,
std::vector<std::string>& archVec) const;
void AddExplicitLanguageFlags(std::string& flags,
cmSourceFile const& sf) const;
void AddCUDAArchitectureFlags(std::string& flags) const;
void AddCUDAToolkitFlags(std::string& flags) const;

View File

@@ -938,6 +938,11 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
default:
break;
}
// Explicitly add the explicit language flag before any other flag
// so user flags can override it.
gtgt->AddExplicitLanguageFlags(flags, *sf);
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
if (cmProp cflags = sf->GetProperty(COMPILE_FLAGS)) {
lg->AppendFlags(flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));

View File

@@ -622,6 +622,10 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
// Build the set of compiler flags.
std::string flags;
// Explicitly add the explicit language flag before any other flag
// so user flags can override it.
this->GeneratorTarget->AddExplicitLanguageFlags(flags, source);
// Add language-specific flags.
std::string langFlags = cmStrCat("$(", lang, "_FLAGS", filterArch, ")");
this->LocalGenerator->AppendFlags(flags, langFlags);

View File

@@ -185,7 +185,15 @@ 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
// so user flags can override it.
this->GeneratorTarget->AddExplicitLanguageFlags(flags, *source);
if (!flags.empty()) {
flags += " ";
}
flags += this->GetFlags(language, config, filterArch);
// Add Fortran format flags.
if (language == "Fortran") {

View File

@@ -352,7 +352,11 @@ class cmMakefile;
SELECT( \
POLICY, CMP0118, \
"The GENERATED source file property is now visible in all directories.", \
3, 20, 0, cmPolicies::WARN)
3, 20, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0119, \
"LANGUAGE source file property explicitly compiles as specified " \
"language.", \
3, 20, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -387,7 +391,8 @@ class cmMakefile;
F(CMP0105) \
F(CMP0108) \
F(CMP0112) \
F(CMP0113)
F(CMP0113) \
F(CMP0119)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies