cmLocalGhsMultiGenerator.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "cmLocalGhsMultiGenerator.h"
  4. #include <algorithm>
  5. #include <utility>
  6. #include <cmext/algorithm>
  7. #include "cmGeneratorTarget.h"
  8. #include "cmGhsMultiTargetGenerator.h"
  9. #include "cmGlobalGenerator.h"
  10. #include "cmSourceFile.h"
  11. #include "cmStringAlgorithms.h"
  12. #include "cmSystemTools.h"
  13. cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
  14. cmMakefile* mf)
  15. : cmLocalGenerator(gg, mf)
  16. {
  17. }
  18. cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() = default;
  19. std::string cmLocalGhsMultiGenerator::GetTargetDirectory(
  20. cmGeneratorTarget const* target) const
  21. {
  22. std::string dir = cmStrCat(target->GetName(), ".dir");
  23. return dir;
  24. }
  25. void cmLocalGhsMultiGenerator::GenerateTargetsDepthFirst(
  26. cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
  27. {
  28. if (!target->IsInBuildSystem()) {
  29. return;
  30. }
  31. // Find this target in the list of remaining targets.
  32. auto it = std::find(remaining.begin(), remaining.end(), target);
  33. if (it == remaining.end()) {
  34. // This target was already handled.
  35. return;
  36. }
  37. // Remove this target from the list of remaining targets because
  38. // we are handling it now.
  39. *it = nullptr;
  40. cmGhsMultiTargetGenerator tg(target);
  41. tg.Generate();
  42. }
  43. void cmLocalGhsMultiGenerator::Generate()
  44. {
  45. std::vector<cmGeneratorTarget*> remaining;
  46. cm::append(remaining, this->GetGeneratorTargets());
  47. for (auto& t : remaining) {
  48. if (t) {
  49. this->GenerateTargetsDepthFirst(t, remaining);
  50. }
  51. }
  52. }
  53. void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
  54. std::map<cmSourceFile const*, std::string>& mapping,
  55. cmGeneratorTarget const* gt)
  56. {
  57. std::string dir_max = cmStrCat(this->GetCurrentBinaryDirectory(), '/',
  58. this->GetTargetDirectory(gt), '/');
  59. // Count the number of object files with each name. Note that
  60. // filesystem may not be case sensitive.
  61. std::map<std::string, int> counts;
  62. for (auto const& si : mapping) {
  63. cmSourceFile const* sf = si.first;
  64. std::string objectNameLower = cmStrCat(
  65. cmSystemTools::LowerCase(
  66. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())),
  67. this->GlobalGenerator->GetLanguageOutputExtension(*sf));
  68. counts[objectNameLower] += 1;
  69. }
  70. // For all source files producing duplicate names we need unique
  71. // object name computation.
  72. for (auto& si : mapping) {
  73. cmSourceFile const* sf = si.first;
  74. std::string objectName = cmStrCat(
  75. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()),
  76. this->GlobalGenerator->GetLanguageOutputExtension(*sf));
  77. if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
  78. const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
  79. bool keptSourceExtension;
  80. objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max,
  81. &keptSourceExtension);
  82. cmsys::SystemTools::ReplaceString(objectName, "/", "_");
  83. }
  84. si.second = objectName;
  85. }
  86. }