cmLocalGhsMultiGenerator.cxx 3.1 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 "cmGeneratorTarget.h"
  5. #include "cmGhsMultiTargetGenerator.h"
  6. #include "cmGlobalGenerator.h"
  7. #include "cmSourceFile.h"
  8. #include "cmStateTypes.h"
  9. #include "cmSystemTools.h"
  10. #include <algorithm>
  11. #include <utility>
  12. cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
  13. cmMakefile* mf)
  14. : cmLocalGenerator(gg, mf)
  15. {
  16. }
  17. cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() = default;
  18. std::string cmLocalGhsMultiGenerator::GetTargetDirectory(
  19. cmGeneratorTarget const* target) const
  20. {
  21. std::string dir;
  22. dir += target->GetName();
  23. dir += ".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 = this->GetGeneratorTargets();
  47. for (auto& t : remaining) {
  48. if (t) {
  49. 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;
  58. dir_max += this->GetCurrentBinaryDirectory();
  59. dir_max += "/";
  60. dir_max += this->GetTargetDirectory(gt);
  61. dir_max += "/";
  62. // Count the number of object files with each name. Note that
  63. // filesystem may not be case sensitive.
  64. std::map<std::string, int> counts;
  65. for (auto const& si : mapping) {
  66. cmSourceFile const* sf = si.first;
  67. std::string objectNameLower = cmSystemTools::LowerCase(
  68. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
  69. objectNameLower += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
  70. counts[objectNameLower] += 1;
  71. }
  72. // For all source files producing duplicate names we need unique
  73. // object name computation.
  74. for (auto& si : mapping) {
  75. cmSourceFile const* sf = si.first;
  76. std::string objectName =
  77. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
  78. objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
  79. if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
  80. const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
  81. bool keptSourceExtension;
  82. objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max,
  83. &keptSourceExtension);
  84. cmsys::SystemTools::ReplaceString(objectName, "/", "_");
  85. }
  86. si.second = objectName;
  87. }
  88. }