cmTargetPropertyComputer.cxx 2.9 KB

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