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 "cmGeneratorTarget.h"
  5. #include "cmGlobalGenerator.h"
  6. #include "cmMakefile.h"
  7. #include "cmMessenger.h"
  8. #include "cmSourceFile.h"
  9. #include "cmSourceFileLocation.h"
  10. #include "cmTarget.h"
  11. #include "cm_unordered_set.hxx"
  12. bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
  13. std::string const& tgtName, cmMessenger* messenger,
  14. cmListFileBacktrace const& context)
  15. {
  16. std::ostringstream e;
  17. const char* modal = CM_NULLPTR;
  18. cmake::MessageType messageType = cmake::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 = cmake::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 != cmake::FATAL_ERROR;
  40. }
  41. bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
  42. const std::string& prop)
  43. {
  44. if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
  45. return true;
  46. }
  47. static CM_UNORDERED_SET<std::string> builtIns;
  48. if (builtIns.empty()) {
  49. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  50. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  51. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  52. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  53. builtIns.insert("EXPORT_NAME");
  54. builtIns.insert("IMPORTED");
  55. builtIns.insert("NAME");
  56. builtIns.insert("TYPE");
  57. }
  58. if (builtIns.count(prop)) {
  59. return true;
  60. }
  61. if (prop == "IMPORTED_CONFIGURATIONS" || prop == "IMPORTED_LIBNAME" ||
  62. cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME_") ||
  63. cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_")) {
  64. return true;
  65. }
  66. return false;
  67. }
  68. bool cmTargetPropertyComputer::PassesWhitelist(
  69. cmStateEnums::TargetType tgtType, std::string const& prop,
  70. cmMessenger* messenger, cmListFileBacktrace const& context)
  71. {
  72. if (tgtType == cmStateEnums::INTERFACE_LIBRARY &&
  73. !WhiteListedInterfaceProperty(prop)) {
  74. std::ostringstream e;
  75. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  76. "The property \""
  77. << prop << "\" is not allowed.";
  78. messenger->IssueMessage(cmake::FATAL_ERROR, e.str(), context);
  79. return false;
  80. }
  81. return true;
  82. }