cmLocalFastbuildGenerator.cxx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. this->FillCustomInstallObjectLocations(*sf, config, nullptr,
  61. si.second.InstallLongLoc);
  62. }
  63. }
  64. void cmLocalFastbuildGenerator::AppendFlagEscape(
  65. std::string& flags, std::string const& rawFlag) const
  66. {
  67. std::string escapedFlag = this->EscapeForShell(rawFlag);
  68. // Other make systems will remove the double $ but
  69. // fastbuild uses ^$ to escape it. So switch to that.
  70. // cmSystemTools::ReplaceString(escapedFlag, "$$", "^$");
  71. this->AppendFlags(flags, escapedFlag);
  72. }
  73. void cmLocalFastbuildGenerator::AdditionalCleanFiles(std::string const& config)
  74. {
  75. if (cmValue prop_value =
  76. this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
  77. cmList cleanFiles{ cmGeneratorExpression::Evaluate(*prop_value, this,
  78. config) };
  79. std::string const& binaryDir = this->GetCurrentBinaryDirectory();
  80. auto* gg = this->GetGlobalFastbuildGenerator();
  81. for (auto const& cleanFile : cleanFiles) {
  82. // Support relative paths
  83. gg->AddFileToClean(gg->ConvertToFastbuildPath(
  84. cmSystemTools::CollapseFullPath(cleanFile, binaryDir)));
  85. }
  86. }
  87. }