summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx121
1 files changed, 117 insertions, 4 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index fe8d502..eaf38d4 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -82,7 +82,6 @@ static auto ruleReplaceVars = { "CMAKE_${LANG}_COMPILER",
"CMAKE_CURRENT_SOURCE_DIR",
"CMAKE_CURRENT_BINARY_DIR",
"CMAKE_RANLIB",
- "CMAKE_LINKER",
"CMAKE_MT",
"CMAKE_TAPI",
"CMAKE_CUDA_HOST_COMPILER",
@@ -1604,6 +1603,7 @@ void cmLocalGenerator::GetTargetFlags(
}
std::string extraLinkFlags;
+ this->AppendLinkerTypeFlags(extraLinkFlags, target, config, linkLanguage);
this->AppendPositionIndependentLinkerFlags(extraLinkFlags, target, config,
linkLanguage);
this->AppendIPOLinkerFlags(extraLinkFlags, target, config, linkLanguage);
@@ -1651,6 +1651,39 @@ std::vector<BT<std::string>> cmLocalGenerator::GetTargetCompileFlags(
if (lang == "Fortran") {
this->AppendFlags(compileFlags,
this->GetTargetFortranFlags(target, config));
+ } else if (lang == "Swift") {
+ // Only set the compile mode if CMP0157 is set
+ if (cm::optional<cmSwiftCompileMode> swiftCompileMode =
+ this->GetSwiftCompileMode(target, config)) {
+ std::string swiftCompileModeFlag;
+ switch (*swiftCompileMode) {
+ case cmSwiftCompileMode::Incremental: {
+ swiftCompileModeFlag = "-incremental";
+ if (cmValue flag =
+ mf->GetDefinition("CMAKE_Swift_COMPILE_OPTIONS_INCREMENTAL")) {
+ swiftCompileModeFlag = *flag;
+ }
+ break;
+ }
+ case cmSwiftCompileMode::Wholemodule: {
+ swiftCompileModeFlag = "-wmo";
+ if (cmValue flag =
+ mf->GetDefinition("CMAKE_Swift_COMPILE_OPTIONS_WMO")) {
+ swiftCompileModeFlag = *flag;
+ }
+ break;
+ }
+ case cmSwiftCompileMode::Singlefile:
+ break;
+ case cmSwiftCompileMode::Unknown: {
+ this->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat("Unknown Swift_COMPILATION_MODE on target '",
+ target->GetName(), "'"));
+ }
+ }
+ this->AppendFlags(compileFlags, swiftCompileModeFlag);
+ }
}
this->AddCMP0018Flags(compileFlags, target, lang, config);
@@ -2955,6 +2988,34 @@ cm::optional<std::string> cmLocalGenerator::GetMSVCDebugFormatName(
return msvcDebugInformationFormat;
}
+cm::optional<cmSwiftCompileMode> cmLocalGenerator::GetSwiftCompileMode(
+ cmGeneratorTarget const* target, std::string const& config)
+{
+ cmMakefile const* mf = this->GetMakefile();
+ cmValue const swiftCompileModeDefault =
+ mf->GetDefinition("CMAKE_Swift_COMPILATION_MODE_DEFAULT");
+ if (!cmNonempty(swiftCompileModeDefault)) {
+ return {};
+ }
+ cmValue swiftCompileMode = target->GetProperty("Swift_COMPILATION_MODE");
+ if (!swiftCompileMode) {
+ swiftCompileMode = swiftCompileModeDefault;
+ }
+
+ std::string const expandedCompileMode =
+ cmGeneratorExpression::Evaluate(*swiftCompileMode, this, config, target);
+ if (expandedCompileMode == "wholemodule") {
+ return cmSwiftCompileMode::Wholemodule;
+ }
+ if (expandedCompileMode == "singlefile") {
+ return cmSwiftCompileMode::Singlefile;
+ }
+ if (expandedCompileMode == "incremental") {
+ return cmSwiftCompileMode::Incremental;
+ }
+ return cmSwiftCompileMode::Unknown;
+}
+
namespace {
inline void RegisterUnitySources(cmGeneratorTarget* target, cmSourceFile* sf,
@@ -3063,8 +3124,17 @@ cmLocalGenerator::AddUnityFilesModeAuto(
chunk = std::min(itemsLeft, batchSize);
- std::string filename = cmStrCat(filename_base, "unity_", batch,
- (lang == "C") ? "_c.c" : "_cxx.cxx");
+ std::string extension;
+ if (lang == "C") {
+ extension = "_c.c";
+ } else if (lang == "CXX") {
+ extension = "_cxx.cxx";
+ } else if (lang == "OBJC") {
+ extension = "_m.m";
+ } else if (lang == "OBJCXX") {
+ extension = "_mm.mm";
+ }
+ std::string filename = cmStrCat(filename_base, "unity_", batch, extension);
auto const begin = filtered_sources.begin() + batch * batchSize;
auto const end = begin + chunk;
unity_files.emplace_back(this->WriteUnitySource(
@@ -3155,7 +3225,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmValue afterInclude = target->GetProperty("UNITY_BUILD_CODE_AFTER_INCLUDE");
cmValue unityMode = target->GetProperty("UNITY_BUILD_MODE");
- for (std::string lang : { "C", "CXX" }) {
+ for (std::string lang : { "C", "CXX", "OBJC", "OBJCXX" }) {
std::vector<UnityBatchedSource> filtered_sources;
std::copy_if(unitySources.begin(), unitySources.end(),
std::back_inserter(filtered_sources),
@@ -3200,6 +3270,49 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
}
}
+void cmLocalGenerator::AppendLinkerTypeFlags(std::string& flags,
+ cmGeneratorTarget* target,
+ const std::string& config,
+ const std::string& linkLanguage)
+{
+ switch (target->GetType()) {
+ case cmStateEnums::EXECUTABLE:
+ case cmStateEnums::SHARED_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
+ break;
+ default:
+ return;
+ }
+
+ auto usingLinker =
+ cmStrCat("CMAKE_", linkLanguage, "_USING_",
+ target->IsDeviceLink() ? "DEVICE_" : "", "LINKER_");
+
+ auto format = this->Makefile->GetDefinition(cmStrCat(usingLinker, "MODE"));
+ if (format && format != "FLAG"_s) {
+ return;
+ }
+
+ auto linkerType = target->GetLinkerTypeProperty(linkLanguage, config);
+ if (linkerType.empty()) {
+ linkerType = "DEFAULT";
+ }
+ usingLinker = cmStrCat(usingLinker, linkerType);
+ auto linkerTypeFlags = this->Makefile->GetDefinition(usingLinker);
+ if (linkerTypeFlags) {
+ if (!linkerTypeFlags.IsEmpty()) {
+ auto linkerFlags = cmExpandListWithBacktrace(linkerTypeFlags);
+ target->ResolveLinkerWrapper(linkerFlags, linkLanguage);
+ this->AppendFlags(flags, linkerFlags);
+ }
+ } else if (linkerType != "DEFAULT"_s) {
+ this->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("LINKER_TYPE '", linkerType,
+ "' is unknown. Did you forgot to define '",
+ usingLinker, "' variable?"));
+ }
+}
+
void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags,
cmGeneratorTarget* target,
const std::string& config,