cmLocalFastbuildGenerator.cxx 2.9 KB

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