cmLocalXCodeGenerator.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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"
  4. #include "cmGeneratorTarget.h"
  5. #include "cmGlobalXCodeGenerator.h"
  6. #include "cmMakefile.h"
  7. #include "cmSourceFile.h"
  8. class cmGeneratorTarget;
  9. class cmGlobalGenerator;
  10. class cmMakefile;
  11. cmLocalXCodeGenerator::cmLocalXCodeGenerator(cmGlobalGenerator* gg,
  12. cmMakefile* mf)
  13. : cmLocalGenerator(gg, mf)
  14. {
  15. // the global generator does this, so do not
  16. // put these flags into the language flags
  17. this->EmitUniversalBinaryFlags = false;
  18. }
  19. cmLocalXCodeGenerator::~cmLocalXCodeGenerator() = default;
  20. std::string cmLocalXCodeGenerator::GetTargetDirectory(
  21. cmGeneratorTarget const*) const
  22. {
  23. // No per-target directory for this generator (yet).
  24. return "";
  25. }
  26. void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
  27. const std::string& rawFlag) const
  28. {
  29. const cmGlobalXCodeGenerator* gg =
  30. static_cast<const cmGlobalXCodeGenerator*>(this->GlobalGenerator);
  31. gg->AppendFlag(flags, rawFlag);
  32. }
  33. void cmLocalXCodeGenerator::Generate()
  34. {
  35. cmLocalGenerator::Generate();
  36. for (const auto& target : this->GetGeneratorTargets()) {
  37. target->HasMacOSXRpathInstallNameDir("");
  38. }
  39. }
  40. void cmLocalXCodeGenerator::AddGeneratorSpecificInstallSetup(std::ostream& os)
  41. {
  42. // First check if we need to warn about incompatible settings
  43. for (const auto& target : this->GetGeneratorTargets()) {
  44. target->HasMacOSXRpathInstallNameDir("");
  45. }
  46. // CMakeIOSInstallCombined.cmake needs to know the location of the top of
  47. // the build directory
  48. os << "set(CMAKE_BINARY_DIR \"" << this->GetBinaryDirectory() << "\")\n\n";
  49. if (this->Makefile->PlatformIsAppleEmbedded()) {
  50. std::string platformName;
  51. switch (this->Makefile->GetAppleSDKType()) {
  52. case cmMakefile::AppleSDK::IPhoneOS:
  53. platformName = "iphoneos";
  54. break;
  55. case cmMakefile::AppleSDK::IPhoneSimulator:
  56. platformName = "iphonesimulator";
  57. break;
  58. case cmMakefile::AppleSDK::AppleTVOS:
  59. platformName = "appletvos";
  60. break;
  61. case cmMakefile::AppleSDK::AppleTVSimulator:
  62. platformName = "appletvsimulator";
  63. break;
  64. case cmMakefile::AppleSDK::WatchOS:
  65. platformName = "watchos";
  66. break;
  67. case cmMakefile::AppleSDK::WatchSimulator:
  68. platformName = "watchsimulator";
  69. break;
  70. case cmMakefile::AppleSDK::MacOS:
  71. break;
  72. }
  73. if (!platformName.empty()) {
  74. // The effective platform name is just the platform name with a hyphen
  75. // prepended. We can get the SUPPORTED_PLATFORMS from the project file
  76. // at runtime, so we don't need to compute that here.
  77. /* clang-format off */
  78. os <<
  79. "if(NOT PLATFORM_NAME)\n"
  80. " if(NOT \"$ENV{PLATFORM_NAME}\" STREQUAL \"\")\n"
  81. " set(PLATFORM_NAME \"$ENV{PLATFORM_NAME}\")\n"
  82. " endif()\n"
  83. " if(NOT PLATFORM_NAME)\n"
  84. " set(PLATFORM_NAME " << platformName << ")\n"
  85. " endif()\n"
  86. "endif()\n\n"
  87. "if(NOT EFFECTIVE_PLATFORM_NAME)\n"
  88. " if(NOT \"$ENV{EFFECTIVE_PLATFORM_NAME}\" STREQUAL \"\")\n"
  89. " set(EFFECTIVE_PLATFORM_NAME \"$ENV{EFFECTIVE_PLATFORM_NAME}\")\n"
  90. " endif()\n"
  91. " if(NOT EFFECTIVE_PLATFORM_NAME)\n"
  92. " set(EFFECTIVE_PLATFORM_NAME -" << platformName << ")\n"
  93. " endif()\n"
  94. "endif()\n\n";
  95. /* clang-format off */
  96. }
  97. }
  98. }
  99. void cmLocalXCodeGenerator::ComputeObjectFilenames(
  100. std::map<cmSourceFile const*, std::string>& mapping,
  101. cmGeneratorTarget const*)
  102. {
  103. // Count the number of object files with each name. Warn about duplicate
  104. // names since Xcode names them uniquely automatically with a numeric suffix
  105. // to avoid exact duplicate file names. Note that Mac file names are not
  106. // typically case sensitive, hence the LowerCase.
  107. std::map<std::string, int> counts;
  108. for (auto& si : mapping) {
  109. cmSourceFile const* sf = si.first;
  110. std::string objectName = cmStrCat(
  111. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()), ".o");
  112. std::string objectNameLower = cmSystemTools::LowerCase(objectName);
  113. counts[objectNameLower] += 1;
  114. if (2 == counts[objectNameLower]) {
  115. // TODO: emit warning about duplicate name?
  116. }
  117. si.second = objectName;
  118. }
  119. }