cmLocalFastbuildGenerator.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "cmMakefile.h"
  13. #include "cmObjectLocation.h"
  14. #include "cmSystemTools.h"
  15. #include "cmValue.h"
  16. #include "cmake.h"
  17. class cmGlobalGenerator;
  18. cmLocalFastbuildGenerator::cmLocalFastbuildGenerator(cmGlobalGenerator* gg,
  19. cmMakefile* makefile)
  20. : cmLocalCommonGenerator(gg, makefile)
  21. {
  22. }
  23. void cmLocalFastbuildGenerator::Generate()
  24. {
  25. auto const& targets = this->GetGeneratorTargets();
  26. for (auto const& target : targets) {
  27. if (!target->IsInBuildSystem()) {
  28. continue;
  29. }
  30. for (std::string config : this->GetConfigNames()) {
  31. cmFastbuildTargetGenerator* tg =
  32. cmFastbuildTargetGenerator::New(target.get(), std::move(config));
  33. if (tg) {
  34. tg->Generate();
  35. delete tg;
  36. }
  37. // Directory level.
  38. this->AdditionalCleanFiles(config);
  39. }
  40. }
  41. }
  42. cmGlobalFastbuildGenerator const*
  43. cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator() const
  44. {
  45. return static_cast<cmGlobalFastbuildGenerator const*>(
  46. this->GetGlobalGenerator());
  47. }
  48. cmGlobalFastbuildGenerator*
  49. cmLocalFastbuildGenerator::GetGlobalFastbuildGenerator()
  50. {
  51. return static_cast<cmGlobalFastbuildGenerator*>(this->GetGlobalGenerator());
  52. }
  53. void cmLocalFastbuildGenerator::ComputeObjectFilenames(
  54. std::map<cmSourceFile const*, cmObjectLocations>& mapping,
  55. std::string const& config, cmGeneratorTarget const* gt)
  56. {
  57. for (auto& si : mapping) {
  58. cmSourceFile const* sf = si.first;
  59. si.second.LongLoc =
  60. this->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory);
  61. this->FillCustomInstallObjectLocations(*sf, config, nullptr,
  62. si.second.InstallLongLoc);
  63. }
  64. }
  65. void cmLocalFastbuildGenerator::AppendFlagEscape(
  66. std::string& flags, std::string const& rawFlag) const
  67. {
  68. std::string escapedFlag = this->EscapeForShell(rawFlag);
  69. // Other make systems will remove the double $ but
  70. // fastbuild uses ^$ to escape it. So switch to that.
  71. // cmSystemTools::ReplaceString(escapedFlag, "$$", "^$");
  72. this->AppendFlags(flags, escapedFlag);
  73. }
  74. void cmLocalFastbuildGenerator::AdditionalCleanFiles(std::string const& config)
  75. {
  76. if (cmValue prop_value =
  77. this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
  78. cmList cleanFiles{ cmGeneratorExpression::Evaluate(*prop_value, this,
  79. config) };
  80. std::string const& binaryDir = this->GetCurrentBinaryDirectory();
  81. auto* gg = this->GetGlobalFastbuildGenerator();
  82. for (auto const& cleanFile : cleanFiles) {
  83. // Support relative paths
  84. gg->AddFileToClean(gg->ConvertToFastbuildPath(
  85. cmSystemTools::CollapseFullPath(cleanFile, binaryDir)));
  86. }
  87. }
  88. }
  89. std::string cmLocalFastbuildGenerator::ConvertToIncludeReference(
  90. std::string const& path, cmOutputConverter::OutputFormat format)
  91. {
  92. std::string converted = this->ConvertToOutputForExisting(path, format);
  93. cmGlobalFastbuildGenerator const* GG = this->GetGlobalFastbuildGenerator();
  94. if (GG->UsingRelativePaths && cmSystemTools::FileIsFullPath(path)) {
  95. std::string const& binDir =
  96. GG->GetCMakeInstance()->GetHomeOutputDirectory();
  97. return cmSystemTools::RelativePath(binDir, converted);
  98. }
  99. return converted;
  100. }