summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorGregor Jasny <gjasny@googlemail.com>2022-03-24 21:01:09 (GMT)
committerGregor Jasny <gjasny@googlemail.com>2022-04-03 20:39:34 (GMT)
commit53ca6edd8aefcb6456755f2de48d2d1375d6df7f (patch)
tree9657713940092155470eac78ce7cfb84b16c3fa8 /Source
parent183b6bbf51d40be9a0d54e351538c6413ad41407 (diff)
downloadCMake-53ca6edd8aefcb6456755f2de48d2d1375d6df7f.zip
CMake-53ca6edd8aefcb6456755f2de48d2d1375d6df7f.tar.gz
CMake-53ca6edd8aefcb6456755f2de48d2d1375d6df7f.tar.bz2
xcode: add support for xcconfig files
Fixes: #18420
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalGenerator.cxx1
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx78
-rw-r--r--Source/cmGlobalXCodeGenerator.h6
-rw-r--r--Source/cmLocalGenerator.h1
-rw-r--r--Source/cmLocalXCodeGenerator.cxx20
-rw-r--r--Source/cmLocalXCodeGenerator.h2
6 files changed, 108 insertions, 0 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 3c31db1..09e2abe 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1764,6 +1764,7 @@ bool cmGlobalGenerator::AddAutomaticSources()
if (!gt->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
lg->AddPchDependencies(gt.get());
}
+ lg->AddXCConfigSources(gt.get());
}
}
for (const auto& lg : this->LocalGenerators) {
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index f01b36c..3ce3d59 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -616,6 +616,16 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
cmTarget* allbuild =
root->AddUtilityCommand("ALL_BUILD", true, std::move(cc));
+ // Add xcconfig files to ALL_BUILD sources
+ for (auto& config : this->CurrentConfigurationTypes) {
+ auto xcconfig = cmGeneratorExpression::Evaluate(
+ this->CurrentMakefile->GetSafeDefinition("CMAKE_XCODE_XCCONFIG"),
+ this->CurrentLocalGenerator, config);
+ if (!xcconfig.empty()) {
+ allbuild->AddSource(xcconfig);
+ }
+ }
+
root->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(allbuild, root));
// Add XCODE depend helper
@@ -1142,6 +1152,9 @@ std::string GetSourcecodeValueFromFileExtension(
} else if (ext == "xcassets") {
keepLastKnownFileType = true;
sourcecode = "folder.assetcatalog";
+ } else if (ext == "xcconfig") {
+ keepLastKnownFileType = true;
+ sourcecode = "text.xcconfig";
}
// else
// {
@@ -3045,6 +3058,8 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
config->AddAttribute("name", this->CreateString(i));
config->SetComment(i);
config->AddAttribute("buildSettings", buildSettings);
+
+ this->CreateTargetXCConfigSettings(gtgt, config, i);
}
if (!configVector.empty()) {
configlist->AddAttribute("defaultConfigurationName",
@@ -3056,6 +3071,67 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
return "";
}
+void cmGlobalXCodeGenerator::CreateGlobalXCConfigSettings(
+ cmLocalGenerator* root, cmXCodeObject* config, const std::string& configName)
+{
+ auto xcconfig = cmGeneratorExpression::Evaluate(
+ this->CurrentMakefile->GetSafeDefinition("CMAKE_XCODE_XCCONFIG"),
+ this->CurrentLocalGenerator, configName);
+ if (xcconfig.empty()) {
+ return;
+ }
+
+ auto sf = this->CurrentMakefile->GetSource(xcconfig);
+ if (!sf) {
+ cmSystemTools::Error(
+ cmStrCat("sources for ALL_BUILD do not contain xcconfig file: '",
+ xcconfig, "' (configuration: ", configName, ")"));
+ return;
+ }
+
+ cmXCodeObject* fileRef = this->CreateXCodeFileReferenceFromPath(
+ sf->ResolveFullPath(), root->FindGeneratorTargetToUse("ALL_BUILD"), "",
+ sf);
+
+ if (!fileRef) {
+ // error is already reported by CreateXCodeFileReferenceFromPath
+ return;
+ }
+
+ config->AddAttribute("baseConfigurationReference",
+ this->CreateObjectReference(fileRef));
+}
+
+void cmGlobalXCodeGenerator::CreateTargetXCConfigSettings(
+ cmGeneratorTarget* target, cmXCodeObject* config,
+ const std::string& configName)
+{
+ auto xcconfig =
+ cmGeneratorExpression::Evaluate(target->GetSafeProperty("XCODE_XCCONFIG"),
+ this->CurrentLocalGenerator, configName);
+ if (xcconfig.empty()) {
+ return;
+ }
+
+ auto sf = target->Makefile->GetSource(xcconfig);
+ if (!sf) {
+ cmSystemTools::Error(cmStrCat("target sources for target ",
+ target->Target->GetName(),
+ " do not contain xcconfig file: '", xcconfig,
+ "' (configuration: ", configName, ")"));
+ return;
+ }
+
+ cmXCodeObject* fileRef = this->CreateXCodeFileReferenceFromPath(
+ sf->ResolveFullPath(), target, "", sf);
+ if (!fileRef) {
+ // error is already reported by CreateXCodeFileReferenceFromPath
+ return;
+ }
+ config->AddAttribute("baseConfigurationReference",
+ this->CreateObjectReference(fileRef));
+}
+
const char* cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(
cmGeneratorTarget const* target) const
{
@@ -4245,6 +4321,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
}
for (auto& config : configs) {
+ CreateGlobalXCConfigSettings(root, config.second, config.first);
+
cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings);
// Put this last so it can override existing settings
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 98cebef..1159d1f 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -224,6 +224,12 @@ private:
void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
cmXCodeObject* buildSettings,
const std::string& configName);
+ void CreateGlobalXCConfigSettings(cmLocalGenerator* root,
+ cmXCodeObject* config,
+ const std::string& configName);
+ void CreateTargetXCConfigSettings(cmGeneratorTarget* target,
+ cmXCodeObject* config,
+ const std::string& configName);
void CreateBuildSettings(cmGeneratorTarget* gtgt,
cmXCodeObject* buildSettings,
const std::string& buildType);
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 436a29e..da3c9fd 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -170,6 +170,7 @@ public:
void AddISPCDependencies(cmGeneratorTarget* target);
void AddPchDependencies(cmGeneratorTarget* target);
void AddUnityBuild(cmGeneratorTarget* target);
+ virtual void AddXCConfigSources(cmGeneratorTarget* /* target */) {}
void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
const std::string& config,
const std::string& lang);
diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx
index dd064a1..e7a1f93 100644
--- a/Source/cmLocalXCodeGenerator.cxx
+++ b/Source/cmLocalXCodeGenerator.cxx
@@ -6,6 +6,7 @@
#include <ostream>
#include <utility>
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalXCodeGenerator.h"
#include "cmMakefile.h"
@@ -134,3 +135,22 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames(
si.second = objectName;
}
}
+
+void cmLocalXCodeGenerator::AddXCConfigSources(cmGeneratorTarget* target)
+{
+ auto xcconfig = target->GetProperty("XCODE_XCCONFIG");
+ if (!xcconfig) {
+ return;
+ }
+ auto configs = target->Makefile->GetGeneratorConfigs(
+ cmMakefile::IncludeEmptyConfig);
+
+ for (auto& config : configs) {
+ auto file = cmGeneratorExpression::Evaluate(
+ xcconfig,
+ this, config);
+ if (!file.empty()) {
+ target->AddSource(file);
+ }
+ }
+}
diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h
index ff6b356..b825161 100644
--- a/Source/cmLocalXCodeGenerator.h
+++ b/Source/cmLocalXCodeGenerator.h
@@ -38,5 +38,7 @@ public:
std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt = nullptr) override;
+ void AddXCConfigSources(cmGeneratorTarget* target) override;
+
private:
};