cmTargetPropertyComputer.h 3.8 KB

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