cmTargetPropertyComputer.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmTargetPropertyComputer.h"
  4. #include <cctype>
  5. #include <sstream>
  6. #include <unordered_set>
  7. #include "cmMessageType.h"
  8. #include "cmMessenger.h"
  9. #include "cmPolicies.h"
  10. #include "cmStateSnapshot.h"
  11. #include "cmStringAlgorithms.h"
  12. bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
  13. std::string const& tgtName, cmMessenger* messenger,
  14. cmListFileBacktrace const& context)
  15. {
  16. std::ostringstream e;
  17. const char* modal = nullptr;
  18. MessageType messageType = MessageType::AUTHOR_WARNING;
  19. switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) {
  20. case cmPolicies::WARN:
  21. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  22. modal = "should";
  23. case cmPolicies::OLD:
  24. break;
  25. case cmPolicies::REQUIRED_ALWAYS:
  26. case cmPolicies::REQUIRED_IF_USED:
  27. case cmPolicies::NEW:
  28. modal = "may";
  29. messageType = MessageType::FATAL_ERROR;
  30. }
  31. if (modal) {
  32. e << "The LOCATION property " << modal << " not be read from target \""
  33. << tgtName
  34. << "\". Use the target name directly with "
  35. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  36. "as appropriate.\n";
  37. messenger->IssueMessage(messageType, e.str(), context);
  38. }
  39. return messageType != MessageType::FATAL_ERROR;
  40. }
  41. bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
  42. const std::string& prop)
  43. {
  44. if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
  45. return true;
  46. }
  47. if (cmHasLiteralPrefix(prop, "_")) {
  48. return true;
  49. }
  50. if (std::islower(prop[0])) {
  51. return true;
  52. }
  53. static std::unordered_set<std::string> const builtIns{
  54. "COMPATIBLE_INTERFACE_BOOL",
  55. "COMPATIBLE_INTERFACE_NUMBER_MAX",
  56. "COMPATIBLE_INTERFACE_NUMBER_MIN",
  57. "COMPATIBLE_INTERFACE_STRING",
  58. "DEPRECATION",
  59. "EXPORT_NAME",
  60. "EXPORT_PROPERTIES",
  61. "IMPORTED",
  62. "IMPORTED_GLOBAL",
  63. "MANUALLY_ADDED_DEPENDENCIES",
  64. "NAME",
  65. "PRIVATE_HEADER",
  66. "PUBLIC_HEADER",
  67. "TYPE"
  68. };
  69. if (builtIns.count(prop)) {
  70. return true;
  71. }
  72. if (prop == "IMPORTED_CONFIGURATIONS" || prop == "IMPORTED_LIBNAME" ||
  73. cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME_") ||
  74. cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_")) {
  75. return true;
  76. }
  77. // This property should not be allowed but was incorrectly added in
  78. // CMake 3.8. We can't remove it from the whitelist without breaking
  79. // projects that try to set it. One day we could warn about this, but
  80. // for now silently accept it.
  81. if (prop == "NO_SYSTEM_FROM_IMPORTED") {
  82. return true;
  83. }
  84. return false;
  85. }
  86. bool cmTargetPropertyComputer::PassesWhitelist(
  87. cmStateEnums::TargetType tgtType, std::string const& prop,
  88. cmMessenger* messenger, cmListFileBacktrace const& context)
  89. {
  90. if (tgtType == cmStateEnums::INTERFACE_LIBRARY &&
  91. !WhiteListedInterfaceProperty(prop)) {
  92. std::ostringstream e;
  93. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  94. "The property \""
  95. << prop << "\" is not allowed.";
  96. messenger->IssueMessage(MessageType::FATAL_ERROR, e.str(), context);
  97. return false;
  98. }
  99. return true;
  100. }