cmTargetPropertyComputer.cxx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <sstream>
  5. #include <unordered_set>
  6. #include "cmMessenger.h"
  7. #include "cmPolicies.h"
  8. #include "cmStateSnapshot.h"
  9. #include "cmake.h"
  10. bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
  11. std::string const& tgtName, cmMessenger* messenger,
  12. cmListFileBacktrace const& context)
  13. {
  14. std::ostringstream e;
  15. const char* modal = CM_NULLPTR;
  16. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  17. switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) {
  18. case cmPolicies::WARN:
  19. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
  20. modal = "should";
  21. case cmPolicies::OLD:
  22. break;
  23. case cmPolicies::REQUIRED_ALWAYS:
  24. case cmPolicies::REQUIRED_IF_USED:
  25. case cmPolicies::NEW:
  26. modal = "may";
  27. messageType = cmake::FATAL_ERROR;
  28. }
  29. if (modal) {
  30. e << "The LOCATION property " << modal << " not be read from target \""
  31. << tgtName
  32. << "\". Use the target name directly with "
  33. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  34. "as appropriate.\n";
  35. messenger->IssueMessage(messageType, e.str(), context);
  36. }
  37. return messageType != cmake::FATAL_ERROR;
  38. }
  39. bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
  40. const std::string& prop)
  41. {
  42. if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
  43. return true;
  44. }
  45. static std::unordered_set<std::string> builtIns;
  46. if (builtIns.empty()) {
  47. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  48. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  49. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  50. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  51. builtIns.insert("EXPORT_NAME");
  52. builtIns.insert("IMPORTED");
  53. builtIns.insert("NAME");
  54. builtIns.insert("TYPE");
  55. }
  56. if (builtIns.count(prop)) {
  57. return true;
  58. }
  59. if (prop == "IMPORTED_CONFIGURATIONS" || prop == "IMPORTED_LIBNAME" ||
  60. prop == "NO_SYSTEM_FROM_IMPORTED" ||
  61. cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME_") ||
  62. cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_")) {
  63. return true;
  64. }
  65. return false;
  66. }
  67. bool cmTargetPropertyComputer::PassesWhitelist(
  68. cmStateEnums::TargetType tgtType, std::string const& prop,
  69. cmMessenger* messenger, cmListFileBacktrace const& context)
  70. {
  71. if (tgtType == cmStateEnums::INTERFACE_LIBRARY &&
  72. !WhiteListedInterfaceProperty(prop)) {
  73. std::ostringstream e;
  74. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  75. "The property \""
  76. << prop << "\" is not allowed.";
  77. messenger->IssueMessage(cmake::FATAL_ERROR, e.str(), context);
  78. return false;
  79. }
  80. return true;
  81. }