cmake/Source/cmLocalXCodeGenerator.cxx

133 lines
4.4 KiB
C++
Raw Normal View History

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. */
#include "cmLocalXCodeGenerator.h"
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
#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"
2017-04-14 19:02:05 +02:00
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
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)
{
// 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;
2016-07-09 11:21:54 +02:00
std::string cmLocalXCodeGenerator::GetTargetDirectory(
cmGeneratorTarget const*) const
{
// No per-target directory for this generator (yet).
return "";
}
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;
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
}