cmTargetPropertyComputer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmTargetPropertyComputer_h
  4. #define cmTargetPropertyComputer_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include "cmListFileCache.h"
  8. #include "cmProperty.h"
  9. #include "cmStateTypes.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmSystemTools.h"
  12. class cmMessenger;
  13. class cmTargetPropertyComputer
  14. {
  15. public:
  16. template <typename Target>
  17. static cmProp GetProperty(Target const* tgt, const std::string& prop,
  18. cmMessenger* messenger,
  19. cmListFileBacktrace const& context)
  20. {
  21. if (cmProp loc = GetLocation(tgt, prop, messenger, context)) {
  22. return loc;
  23. }
  24. if (cmSystemTools::GetFatalErrorOccured()) {
  25. return nullptr;
  26. }
  27. if (prop == "SOURCES") {
  28. return GetSources(tgt, messenger, context);
  29. }
  30. return nullptr;
  31. }
  32. static bool WhiteListedInterfaceProperty(const std::string& prop);
  33. static bool PassesWhitelist(cmStateEnums::TargetType tgtType,
  34. std::string const& prop, cmMessenger* messenger,
  35. cmListFileBacktrace const& context);
  36. private:
  37. static bool HandleLocationPropertyPolicy(std::string const& tgtName,
  38. cmMessenger* messenger,
  39. cmListFileBacktrace const& context);
  40. template <typename Target>
  41. static const std::string& ComputeLocationForBuild(Target const* tgt);
  42. template <typename Target>
  43. static const std::string& ComputeLocation(Target const* tgt,
  44. std::string const& config);
  45. template <typename Target>
  46. static cmProp GetLocation(Target const* tgt, std::string const& prop,
  47. cmMessenger* messenger,
  48. cmListFileBacktrace const& context)
  49. {
  50. // Watch for special "computed" properties that are dependent on
  51. // other properties or variables. Always recompute them.
  52. if (tgt->GetType() == cmStateEnums::EXECUTABLE ||
  53. tgt->GetType() == cmStateEnums::STATIC_LIBRARY ||
  54. tgt->GetType() == cmStateEnums::SHARED_LIBRARY ||
  55. tgt->GetType() == cmStateEnums::MODULE_LIBRARY ||
  56. tgt->GetType() == cmStateEnums::UNKNOWN_LIBRARY) {
  57. static const std::string propLOCATION = "LOCATION";
  58. if (prop == propLOCATION) {
  59. if (!tgt->IsImported() &&
  60. !HandleLocationPropertyPolicy(tgt->GetName(), messenger,
  61. context)) {
  62. return nullptr;
  63. }
  64. return &ComputeLocationForBuild(tgt);
  65. }
  66. // Support "LOCATION_<CONFIG>".
  67. if (cmHasLiteralPrefix(prop, "LOCATION_")) {
  68. if (!tgt->IsImported() &&
  69. !HandleLocationPropertyPolicy(tgt->GetName(), messenger,
  70. context)) {
  71. return nullptr;
  72. }
  73. std::string configName = prop.substr(9);
  74. return &ComputeLocation(tgt, configName);
  75. }
  76. // Support "<CONFIG>_LOCATION".
  77. if (cmHasLiteralSuffix(prop, "_LOCATION") &&
  78. !cmHasLiteralPrefix(prop, "XCODE_ATTRIBUTE_")) {
  79. std::string configName(prop.c_str(), prop.size() - 9);
  80. if (configName != "IMPORTED") {
  81. if (!tgt->IsImported() &&
  82. !HandleLocationPropertyPolicy(tgt->GetName(), messenger,
  83. context)) {
  84. return nullptr;
  85. }
  86. return &ComputeLocation(tgt, configName);
  87. }
  88. }
  89. }
  90. return nullptr;
  91. }
  92. template <typename Target>
  93. static cmProp GetSources(Target const* tgt, cmMessenger* messenger,
  94. cmListFileBacktrace const& context);
  95. };
  96. #endif