cmGeneratorTarget_TargetPropertyEntry.cxx 5.4 KB

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