cmLocalGhsMultiGenerator.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "cmLocalGhsMultiGenerator.h"
  4. #include <utility>
  5. #include <vector>
  6. #include "cmGeneratorTarget.h"
  7. #include "cmGhsMultiTargetGenerator.h"
  8. #include "cmGlobalGenerator.h"
  9. #include "cmSourceFile.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmSystemTools.h"
  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 = cmStrCat(target->GetName(), ".dir");
  22. return dir;
  23. }
  24. void cmLocalGhsMultiGenerator::Generate()
  25. {
  26. for (cmGeneratorTarget* gt :
  27. this->GlobalGenerator->GetLocalGeneratorTargetsInOrder(this)) {
  28. if (!gt->IsInBuildSystem()) {
  29. continue;
  30. }
  31. cmGhsMultiTargetGenerator tg(gt);
  32. tg.Generate();
  33. }
  34. }
  35. void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
  36. std::map<cmSourceFile const*, std::string>& mapping,
  37. cmGeneratorTarget const* gt)
  38. {
  39. std::string dir_max = cmStrCat(gt->GetSupportDirectory(), '/');
  40. // Count the number of object files with each name. Note that
  41. // filesystem may not be case sensitive.
  42. std::map<std::string, int> counts;
  43. for (auto const& si : mapping) {
  44. cmSourceFile const* sf = si.first;
  45. std::string objectNameLower = cmStrCat(
  46. cmSystemTools::LowerCase(
  47. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())),
  48. this->GlobalGenerator->GetLanguageOutputExtension(*sf));
  49. counts[objectNameLower] += 1;
  50. }
  51. // For all source files producing duplicate names we need unique
  52. // object name computation.
  53. for (auto& si : mapping) {
  54. cmSourceFile const* sf = si.first;
  55. std::string objectName = cmStrCat(
  56. cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()),
  57. this->GlobalGenerator->GetLanguageOutputExtension(*sf));
  58. if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
  59. const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
  60. bool keptSourceExtension;
  61. objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max,
  62. &keptSourceExtension);
  63. cmsys::SystemTools::ReplaceString(objectName, "/", "_");
  64. }
  65. si.second = objectName;
  66. }
  67. }