cmLocalFastbuildGenerator.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmLocalFastbuildGenerator.h"
  4. #include <memory>
  5. #include <utility>
  6. #include <vector>
  7. #include "cmFastbuildTargetGenerator.h"
  8. #include "cmGeneratorExpression.h"
  9. #include "cmGeneratorTarget.h"
  10. #include "cmGlobalFastbuildGenerator.h"
  11. #include "cmList.h"
  12. #include "cmLocalCommonGenerator.h"
  13. #include "cmMakefile.h"
  14. #include "cmObjectLocation.h"
  15. #include "cmStringAlgorithms.h"
  16. #include "cmSystemTools.h"
  17. #include "cmValue.h"
  18. #include "cmake.h"
  19. class cmGlobalGenerator;
  20. cmLocalFastbuildGenerator::cmLocalFastbuildGenerator(cmGlobalGenerator* gg,
  21. cmMakefile* makefile)
  22. : cmLocalCommonGenerator(gg, makefile)
  23. {
  24. }
  25. void cmLocalFastbuildGenerator::Generate()
  26. {
  27. auto const& targets = this->GetGeneratorTargets();
  28. for (auto const& target : targets) {
  29. if (!target->IsInBuildSystem()) {
  30. continue;
  31. }
  32. for (std::string config : this->GetConfigNames()) {
  33. cmFastbuildTargetGenerator* tg =
  34. cmFastbuildTargetGenerator::New(target.get(), std::move(config));
  35. if (tg) {
  36. tg->Generate();
  37. delete tg;
  38. }
  39. // Directory level.
  40. this->AdditionalCleanFiles(config);
  41. }
  42. }
  43. }
  44. cmGlobalFastbuildGenerator const*
  45. cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator() const
  46. {
  47. return static_cast<cmGlobalFastbuildGenerator const*>(
  48. this->GetGlobalGenerator());
  49. }
  50. cmGlobalFastbuildGenerator*
  51. cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator()
  52. {
  53. return static_cast<cmGlobalFastbuildGenerator*>(this->GetGlobalGenerator());
  54. }
  55. void cmLocalFastbuildGenerator::ComputeObjectFilenames(
  56. std::map<cmSourceFile const*, cmObjectLocations>& mapping,
  57. std::string const& config, cmGeneratorTarget const* gt)
  58. {
  59. char const* customExt = gt->GetCustomObjectExtension();
  60. for (auto& si : mapping) {
  61. cmSourceFile const* sf = si.first;
  62. si.second.LongLoc = this->GetObjectFileNameWithoutTarget(
  63. *sf, gt->ObjectDirectory, nullptr, nullptr);
  64. this->FillCustomInstallObjectLocations(*sf, config, nullptr,
  65. si.second.InstallLongLoc);
  66. // FASTBuild always appends output extension to the source file name.
  67. // So if custom ext is ".ptx", then
  68. // "kernelA.cu" will be outputted as "kernelA.cu.ptx",
  69. // that's why we can't just replace ".cu" with ".ptx".
  70. // This is needed to resolve $<TARGET_OBJECTS> genex correctly.
  71. // Tested in "CudaOnly.ExportPTX" test.
  72. if (customExt) {
  73. si.second.LongLoc.Update(
  74. cmStrCat(si.second.LongLoc.GetPath(), customExt));
  75. }
  76. }
  77. }
  78. void cmLocalFastbuildGenerator::AppendFlagEscape(
  79. std::string& flags, std::string const& rawFlag) const
  80. {
  81. std::string escapedFlag = this->EscapeForShell(rawFlag);
  82. // Other make systems will remove the double $ but
  83. // fastbuild uses ^$ to escape it. So switch to that.
  84. // cmSystemTools::ReplaceString(escapedFlag, "$$", "^$");
  85. this->AppendFlags(flags, escapedFlag);
  86. }
  87. void cmLocalFastbuildGenerator::AdditionalCleanFiles(std::string const& config)
  88. {
  89. if (cmValue prop_value =
  90. this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
  91. cmList cleanFiles{ cmGeneratorExpression::Evaluate(*prop_value, this,
  92. config) };
  93. std::string const& binaryDir = this->GetCurrentBinaryDirectory();
  94. auto* gg = this->GetGlobalFastbuildGenerator();
  95. for (auto const& cleanFile : cleanFiles) {
  96. // Support relative paths
  97. gg->AddFileToClean(gg->ConvertToFastbuildPath(
  98. cmSystemTools::CollapseFullPath(cleanFile, binaryDir)));
  99. }
  100. }
  101. }
  102. std::string cmLocalFastbuildGenerator::ConvertToIncludeReference(
  103. std::string const& path, cmOutputConverter::OutputFormat format)
  104. {
  105. std::string converted = this->ConvertToOutputForExisting(path, format);
  106. cmGlobalFastbuildGenerator const* GG = this->GetGlobalFastbuildGenerator();
  107. if (GG->UsingRelativePaths && cmSystemTools::FileIsFullPath(path)) {
  108. std::string const binDir = this->ConvertToOutputFormat(
  109. GG->GetCMakeInstance()->GetHomeOutputDirectory(), OutputFormat::SHELL);
  110. if (binDir == converted) {
  111. return ".";
  112. }
  113. return cmSystemTools::RelativePath(binDir, converted);
  114. }
  115. return converted;
  116. }