cmLocalGhsMultiGenerator.cxx 3.2 KB

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