cmGeneratorTarget_TargetPropertyEntry.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. /* clang-format off */
  4. #include "cmGeneratorTarget.h"
  5. /* clang-format on */
  6. #include <map>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include <cm/memory>
  11. #include "cmFileSet.h"
  12. #include "cmGeneratorExpression.h"
  13. #include "cmLinkItem.h"
  14. #include "cmList.h"
  15. #include "cmListFileCache.h"
  16. class cmake;
  17. cmLinkItem cmGeneratorTarget::TargetPropertyEntry::NoLinkItem;
  18. class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry
  19. {
  20. public:
  21. TargetPropertyEntryString(BT<std::string> propertyValue,
  22. cmLinkItem const& item = NoLinkItem)
  23. : cmGeneratorTarget::TargetPropertyEntry(item)
  24. , PropertyValue(std::move(propertyValue))
  25. {
  26. }
  27. std::string const& Evaluate(cm::GenEx::Context const&,
  28. cmGeneratorTarget const*,
  29. cmGeneratorExpressionDAGChecker*) const override
  30. {
  31. return this->PropertyValue.Value;
  32. }
  33. cmListFileBacktrace GetBacktrace() const override
  34. {
  35. return this->PropertyValue.Backtrace;
  36. }
  37. std::string const& GetInput() const override
  38. {
  39. return this->PropertyValue.Value;
  40. }
  41. private:
  42. BT<std::string> PropertyValue;
  43. };
  44. class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
  45. {
  46. public:
  47. TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  48. cmLinkItem const& item = NoLinkItem)
  49. : cmGeneratorTarget::TargetPropertyEntry(item)
  50. , ge(std::move(cge))
  51. {
  52. }
  53. std::string const& Evaluate(
  54. cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget,
  55. cmGeneratorExpressionDAGChecker* dagChecker) const override
  56. {
  57. return this->ge->Evaluate(context, dagChecker, headTarget);
  58. }
  59. cmListFileBacktrace GetBacktrace() const override
  60. {
  61. return this->ge->GetBacktrace();
  62. }
  63. std::string const& GetInput() const override { return this->ge->GetInput(); }
  64. bool GetHadContextSensitiveCondition() const override
  65. {
  66. return this->ge->GetHadContextSensitiveCondition();
  67. }
  68. private:
  69. std::unique_ptr<cmCompiledGeneratorExpression> const ge;
  70. };
  71. class TargetPropertyEntryFileSet
  72. : public cmGeneratorTarget::TargetPropertyEntry
  73. {
  74. public:
  75. TargetPropertyEntryFileSet(
  76. std::vector<std::string> dirs, bool contextSensitiveDirs,
  77. std::unique_ptr<cmCompiledGeneratorExpression> entryCge,
  78. cmFileSet const* fileSet, cmLinkItem const& item = NoLinkItem)
  79. : cmGeneratorTarget::TargetPropertyEntry(item)
  80. , BaseDirs(std::move(dirs))
  81. , ContextSensitiveDirs(contextSensitiveDirs)
  82. , EntryCge(std::move(entryCge))
  83. , FileSet(fileSet)
  84. {
  85. }
  86. std::string const& Evaluate(
  87. cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget,
  88. cmGeneratorExpressionDAGChecker* dagChecker) const override
  89. {
  90. std::map<std::string, std::vector<std::string>> filesPerDir;
  91. this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir,
  92. this->EntryCge, context, headTarget,
  93. dagChecker);
  94. std::vector<std::string> files;
  95. for (auto const& it : filesPerDir) {
  96. files.insert(files.end(), it.second.begin(), it.second.end());
  97. }
  98. static std::string filesStr;
  99. filesStr = cmList::to_string(files);
  100. return filesStr;
  101. }
  102. cmListFileBacktrace GetBacktrace() const override
  103. {
  104. return this->EntryCge->GetBacktrace();
  105. }
  106. std::string const& GetInput() const override
  107. {
  108. return this->EntryCge->GetInput();
  109. }
  110. bool GetHadContextSensitiveCondition() const override
  111. {
  112. return this->ContextSensitiveDirs ||
  113. this->EntryCge->GetHadContextSensitiveCondition();
  114. }
  115. private:
  116. std::vector<std::string> const BaseDirs;
  117. bool const ContextSensitiveDirs;
  118. std::unique_ptr<cmCompiledGeneratorExpression> const EntryCge;
  119. cmFileSet const* FileSet;
  120. };
  121. std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
  122. cmGeneratorTarget::TargetPropertyEntry::Create(
  123. cmake& cmakeInstance, const BT<std::string>& propertyValue,
  124. bool evaluateForBuildsystem)
  125. {
  126. if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) {
  127. cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace);
  128. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  129. ge.Parse(propertyValue.Value);
  130. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  131. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  132. cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
  133. }
  134. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  135. cm::make_unique<TargetPropertyEntryString>(propertyValue));
  136. }
  137. std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
  138. cmGeneratorTarget::TargetPropertyEntry::CreateFileSet(
  139. std::vector<std::string> dirs, bool contextSensitiveDirs,
  140. std::unique_ptr<cmCompiledGeneratorExpression> entryCge,
  141. cmFileSet const* fileSet, cmLinkItem const& item)
  142. {
  143. return cm::make_unique<TargetPropertyEntryFileSet>(
  144. std::move(dirs), contextSensitiveDirs, std::move(entryCge), fileSet, item);
  145. }
  146. cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry(
  147. cmLinkItem const& item)
  148. : LinkItem(item)
  149. {
  150. }
  151. bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition()
  152. const
  153. {
  154. return false;
  155. }