1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmLocalXCodeGenerator.h"
9 #include "cmGeneratorExpression.h"
10 #include "cmGeneratorTarget.h"
11 #include "cmGlobalXCodeGenerator.h"
12 #include "cmMakefile.h"
13 #include "cmSourceFile.h"
14 #include "cmStringAlgorithms.h"
15 #include "cmSystemTools.h"
17 class cmGlobalGenerator;
19 cmLocalXCodeGenerator::cmLocalXCodeGenerator(cmGlobalGenerator* gg,
21 : cmLocalGenerator(gg, mf)
23 // the global generator does this, so do not
24 // put these flags into the language flags
25 this->EmitUniversalBinaryFlags = false;
28 cmLocalXCodeGenerator::~cmLocalXCodeGenerator() = default;
30 std::string cmLocalXCodeGenerator::GetTargetDirectory(
31 cmGeneratorTarget const*) const
33 // No per-target directory for this generator (yet).
37 void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
38 const std::string& rawFlag) const
40 const cmGlobalXCodeGenerator* gg =
41 static_cast<const cmGlobalXCodeGenerator*>(this->GlobalGenerator);
42 gg->AppendFlag(flags, rawFlag);
45 void cmLocalXCodeGenerator::Generate()
47 cmLocalGenerator::Generate();
49 for (const auto& target : this->GetGeneratorTargets()) {
50 target->HasMacOSXRpathInstallNameDir("");
54 void cmLocalXCodeGenerator::AddGeneratorSpecificInstallSetup(std::ostream& os)
56 // First check if we need to warn about incompatible settings
57 for (const auto& target : this->GetGeneratorTargets()) {
58 target->HasMacOSXRpathInstallNameDir("");
61 // CMakeIOSInstallCombined.cmake needs to know the location of the top of
62 // the build directory
63 os << "set(CMAKE_BINARY_DIR \"" << this->GetBinaryDirectory() << "\")\n\n";
65 if (this->Makefile->PlatformIsAppleEmbedded()) {
66 std::string platformName;
67 switch (this->Makefile->GetAppleSDKType()) {
68 case cmMakefile::AppleSDK::IPhoneOS:
69 platformName = "iphoneos";
71 case cmMakefile::AppleSDK::IPhoneSimulator:
72 platformName = "iphonesimulator";
74 case cmMakefile::AppleSDK::AppleTVOS:
75 platformName = "appletvos";
77 case cmMakefile::AppleSDK::AppleTVSimulator:
78 platformName = "appletvsimulator";
80 case cmMakefile::AppleSDK::WatchOS:
81 platformName = "watchos";
83 case cmMakefile::AppleSDK::WatchSimulator:
84 platformName = "watchsimulator";
86 case cmMakefile::AppleSDK::MacOS:
89 if (!platformName.empty()) {
90 // The effective platform name is just the platform name with a hyphen
91 // prepended. We can get the SUPPORTED_PLATFORMS from the project file
92 // at runtime, so we don't need to compute that here.
93 /* clang-format off */
95 "if(NOT PLATFORM_NAME)\n"
96 " if(NOT \"$ENV{PLATFORM_NAME}\" STREQUAL \"\")\n"
97 " set(PLATFORM_NAME \"$ENV{PLATFORM_NAME}\")\n"
99 " if(NOT PLATFORM_NAME)\n"
100 " set(PLATFORM_NAME " << platformName << ")\n"
103 "if(NOT EFFECTIVE_PLATFORM_NAME)\n"
104 " if(NOT \"$ENV{EFFECTIVE_PLATFORM_NAME}\" STREQUAL \"\")\n"
105 " set(EFFECTIVE_PLATFORM_NAME \"$ENV{EFFECTIVE_PLATFORM_NAME}\")\n"
107 " if(NOT EFFECTIVE_PLATFORM_NAME)\n"
108 " set(EFFECTIVE_PLATFORM_NAME -" << platformName << ")\n"
111 /* clang-format off */
116 void cmLocalXCodeGenerator::ComputeObjectFilenames(
117 std::map<cmSourceFile const*, std::string>& mapping,
118 cmGeneratorTarget const*)
120 // Count the number of object files with each name. Warn about duplicate
121 // names since Xcode names them uniquely automatically with a numeric suffix
122 // to avoid exact duplicate file names. Note that Mac file names are not
123 // typically case sensitive, hence the LowerCase.
124 std::map<std::string, int> counts;
125 for (auto& si : mapping) {
126 cmSourceFile const* sf = si.first;
127 std::string objectName = cmStrCat(
128 cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()), ".o");
130 std::string objectNameLower = cmSystemTools::LowerCase(objectName);
131 counts[objectNameLower] += 1;
132 if (2 == counts[objectNameLower]) {
133 // TODO: emit warning about duplicate name?
135 si.second = objectName;
139 void cmLocalXCodeGenerator::AddXCConfigSources(cmGeneratorTarget* target)
141 auto xcconfig = target->GetProperty("XCODE_XCCONFIG");
145 auto configs = target->Makefile->GetGeneratorConfigs(
146 cmMakefile::IncludeEmptyConfig);
148 for (auto& config : configs) {
149 auto file = cmGeneratorExpression::Evaluate(
153 target->AddSource(file);