2016-10-30 18:24:19 +01:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-10-12 18:41:06 +02:00
|
|
|
#include "cmLocalXCodeGenerator.h"
|
2016-07-09 11:21:54 +02:00
|
|
|
|
2022-03-29 21:10:50 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <ostream>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-08-04 22:12:04 +02:00
|
|
|
#include "cmGeneratorExpression.h"
|
2016-10-30 18:24:19 +01:00
|
|
|
#include "cmGeneratorTarget.h"
|
2008-10-12 18:41:06 +02:00
|
|
|
#include "cmGlobalXCodeGenerator.h"
|
2021-09-14 00:13:48 +02:00
|
|
|
#include "cmMakefile.h"
|
2016-07-09 11:21:54 +02:00
|
|
|
#include "cmSourceFile.h"
|
2022-03-29 21:10:50 +02:00
|
|
|
#include "cmStringAlgorithms.h"
|
|
|
|
#include "cmSystemTools.h"
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2017-04-14 19:02:05 +02:00
|
|
|
class cmGlobalGenerator;
|
|
|
|
|
2015-08-17 11:37:30 +02:00
|
|
|
cmLocalXCodeGenerator::cmLocalXCodeGenerator(cmGlobalGenerator* gg,
|
2015-11-17 17:22:37 +01:00
|
|
|
cmMakefile* mf)
|
|
|
|
: cmLocalGenerator(gg, mf)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
|
|
|
// the global generator does this, so do not
|
|
|
|
// put these flags into the language flags
|
|
|
|
this->EmitUniversalBinaryFlags = false;
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:01:05 +01:00
|
|
|
cmLocalXCodeGenerator::~cmLocalXCodeGenerator() = default;
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2016-07-09 11:21:54 +02:00
|
|
|
std::string cmLocalXCodeGenerator::GetTargetDirectory(
|
|
|
|
cmGeneratorTarget const*) const
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
|
|
|
// No per-target directory for this generator (yet).
|
2023-12-07 09:12:54 +01:00
|
|
|
return std::string{};
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
2013-11-03 12:27:13 +02:00
|
|
|
|
|
|
|
void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
|
2018-04-23 21:13:27 +02:00
|
|
|
const std::string& rawFlag) const
|
2013-11-03 12:27:13 +02:00
|
|
|
{
|
2018-04-23 21:13:27 +02:00
|
|
|
const cmGlobalXCodeGenerator* gg =
|
|
|
|
static_cast<const cmGlobalXCodeGenerator*>(this->GlobalGenerator);
|
2013-11-03 12:27:13 +02:00
|
|
|
gg->AppendFlag(flags, rawFlag);
|
|
|
|
}
|
2014-08-03 19:52:23 +02:00
|
|
|
|
|
|
|
void cmLocalXCodeGenerator::Generate()
|
|
|
|
{
|
|
|
|
cmLocalGenerator::Generate();
|
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
for (const auto& target : this->GetGeneratorTargets()) {
|
2018-01-26 17:06:56 +01:00
|
|
|
target->HasMacOSXRpathInstallNameDir("");
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2014-08-03 19:52:23 +02:00
|
|
|
}
|
|
|
|
|
2021-09-14 00:13:48 +02:00
|
|
|
void cmLocalXCodeGenerator::AddGeneratorSpecificInstallSetup(std::ostream& os)
|
2014-08-03 19:52:23 +02:00
|
|
|
{
|
2021-09-14 00:13:48 +02:00
|
|
|
// First check if we need to warn about incompatible settings
|
2020-08-30 11:54:41 +02:00
|
|
|
for (const auto& target : this->GetGeneratorTargets()) {
|
2018-01-26 17:06:56 +01:00
|
|
|
target->HasMacOSXRpathInstallNameDir("");
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2021-09-14 00:13:48 +02:00
|
|
|
|
|
|
|
// CMakeIOSInstallCombined.cmake needs to know the location of the top of
|
|
|
|
// the build directory
|
|
|
|
os << "set(CMAKE_BINARY_DIR \"" << this->GetBinaryDirectory() << "\")\n\n";
|
|
|
|
|
|
|
|
if (this->Makefile->PlatformIsAppleEmbedded()) {
|
|
|
|
std::string platformName;
|
|
|
|
switch (this->Makefile->GetAppleSDKType()) {
|
|
|
|
case cmMakefile::AppleSDK::IPhoneOS:
|
|
|
|
platformName = "iphoneos";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::IPhoneSimulator:
|
|
|
|
platformName = "iphonesimulator";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::AppleTVOS:
|
|
|
|
platformName = "appletvos";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::AppleTVSimulator:
|
|
|
|
platformName = "appletvsimulator";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::WatchOS:
|
|
|
|
platformName = "watchos";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::WatchSimulator:
|
|
|
|
platformName = "watchsimulator";
|
|
|
|
break;
|
2023-12-07 09:12:54 +01:00
|
|
|
case cmMakefile::AppleSDK::XROS:
|
|
|
|
platformName = "xros";
|
|
|
|
break;
|
|
|
|
case cmMakefile::AppleSDK::XRSimulator:
|
|
|
|
platformName = "xrsimulator";
|
|
|
|
break;
|
2021-09-14 00:13:48 +02:00
|
|
|
case cmMakefile::AppleSDK::MacOS:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!platformName.empty()) {
|
|
|
|
// The effective platform name is just the platform name with a hyphen
|
|
|
|
// prepended. We can get the SUPPORTED_PLATFORMS from the project file
|
|
|
|
// at runtime, so we don't need to compute that here.
|
|
|
|
/* clang-format off */
|
|
|
|
os <<
|
|
|
|
"if(NOT PLATFORM_NAME)\n"
|
|
|
|
" if(NOT \"$ENV{PLATFORM_NAME}\" STREQUAL \"\")\n"
|
|
|
|
" set(PLATFORM_NAME \"$ENV{PLATFORM_NAME}\")\n"
|
|
|
|
" endif()\n"
|
|
|
|
" if(NOT PLATFORM_NAME)\n"
|
|
|
|
" set(PLATFORM_NAME " << platformName << ")\n"
|
|
|
|
" endif()\n"
|
|
|
|
"endif()\n\n"
|
|
|
|
"if(NOT EFFECTIVE_PLATFORM_NAME)\n"
|
|
|
|
" if(NOT \"$ENV{EFFECTIVE_PLATFORM_NAME}\" STREQUAL \"\")\n"
|
|
|
|
" set(EFFECTIVE_PLATFORM_NAME \"$ENV{EFFECTIVE_PLATFORM_NAME}\")\n"
|
|
|
|
" endif()\n"
|
|
|
|
" if(NOT EFFECTIVE_PLATFORM_NAME)\n"
|
|
|
|
" set(EFFECTIVE_PLATFORM_NAME -" << platformName << ")\n"
|
|
|
|
" endif()\n"
|
|
|
|
"endif()\n\n";
|
|
|
|
/* clang-format off */
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 22:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalXCodeGenerator::ComputeObjectFilenames(
|
2016-07-09 11:21:54 +02:00
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const*)
|
2015-04-27 22:25:09 +02:00
|
|
|
{
|
|
|
|
// Count the number of object files with each name. Warn about duplicate
|
|
|
|
// names since Xcode names them uniquely automatically with a numeric suffix
|
|
|
|
// to avoid exact duplicate file names. Note that Mac file names are not
|
|
|
|
// typically case sensitive, hence the LowerCase.
|
|
|
|
std::map<std::string, int> counts;
|
2018-01-26 17:06:56 +01:00
|
|
|
for (auto& si : mapping) {
|
|
|
|
cmSourceFile const* sf = si.first;
|
2020-02-01 23:06:01 +01:00
|
|
|
std::string objectName = cmStrCat(
|
|
|
|
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()), ".o");
|
2015-04-27 22:25:09 +02:00
|
|
|
|
|
|
|
std::string objectNameLower = cmSystemTools::LowerCase(objectName);
|
|
|
|
counts[objectNameLower] += 1;
|
2016-07-09 11:21:54 +02:00
|
|
|
if (2 == counts[objectNameLower]) {
|
2015-04-27 22:25:09 +02:00
|
|
|
// TODO: emit warning about duplicate name?
|
2014-08-03 19:52:23 +02:00
|
|
|
}
|
2018-01-26 17:06:56 +01:00
|
|
|
si.second = objectName;
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2014-08-03 19:52:23 +02:00
|
|
|
}
|
2022-08-04 22:12:04 +02:00
|
|
|
|
|
|
|
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(
|
2023-05-23 16:38:00 +02:00
|
|
|
*xcconfig,
|
2022-08-04 22:12:04 +02:00
|
|
|
this, config);
|
|
|
|
if (!file.empty()) {
|
|
|
|
target->AddSource(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|