Swift: Factor out Swift-specific target flags

Swift started the trend of piling language-specific target flags in
`cmLocalGenerator::AddLanguageFlags`. Other languages have added their
own under language-specific `Add<Lang>TargetFlags`.
I'm refactoring where Swift piles on its language-specific target flags
to match the pattern other languages are using.
This commit is contained in:
Evan Wilde
2026-04-27 10:45:14 -07:00
parent de52c08ba2
commit 635f71737c
3 changed files with 15 additions and 8 deletions
+12
View File
@@ -2810,6 +2810,18 @@ void cmGeneratorTarget::AddRustTargetFlags(std::string& flags) const
}
}
void cmGeneratorTarget::AddSwiftTargetFlags(std::string& flags) const
{
if (cmValue version = GetProperty("Swift_LANGUAGE_VERSION")) {
if (cmSystemTools::VersionCompare(
cmSystemTools::OP_GREATER_EQUAL,
this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"),
"4.2")) {
flags += " -swift-version " + *version;
}
}
}
void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const
{
std::string const& compiler =
+2
View File
@@ -628,6 +628,8 @@ public:
void AddRustTargetFlags(std::string& flags) const;
void AddSwiftTargetFlags(std::string& flags) const;
std::string GetFeatureSpecificLinkRuleVariable(
std::string const& var, std::string const& lang,
std::string const& config) const;
+1 -8
View File
@@ -2115,14 +2115,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
(compilerId == "OpenWatcom" || compilerSimulateId == "OpenWatcom");
if (lang == "Swift") {
if (cmValue v = target->GetProperty("Swift_LANGUAGE_VERSION")) {
if (cmSystemTools::VersionCompare(
cmSystemTools::OP_GREATER_EQUAL,
this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"),
"4.2")) {
this->AppendFlags(flags, "-swift-version " + *v);
}
}
target->AddSwiftTargetFlags(flags);
} else if (lang == "CUDA") {
target->AddCUDAArchitectureFlags(compileOrLink, config, flags);
target->AddCUDAToolkitFlags(flags);