cmPolicies.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 cmPolicies_h
  4. #define cmPolicies_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <bitset>
  7. #include <string>
  8. class cmMakefile;
  9. #define CM_FOR_EACH_POLICY_TABLE(POLICY, SELECT) \
  10. SELECT(POLICY, CMP0000, \
  11. "A minimum required CMake version must be specified.", 2, 6, 0, \
  12. cmPolicies::WARN) \
  13. SELECT(POLICY, CMP0001, \
  14. "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.", 2, 6, 0, \
  15. cmPolicies::WARN) \
  16. SELECT(POLICY, CMP0002, "Logical target names must be globally unique.", 2, \
  17. 6, 0, cmPolicies::WARN) \
  18. SELECT( \
  19. POLICY, CMP0003, \
  20. "Libraries linked via full path no longer produce linker search paths.", \
  21. 2, 6, 0, cmPolicies::WARN) \
  22. SELECT(POLICY, CMP0004, \
  23. "Libraries linked may not have leading or trailing whitespace.", 2, \
  24. 6, 0, cmPolicies::WARN) \
  25. SELECT(POLICY, CMP0005, \
  26. "Preprocessor definition values are now escaped automatically.", 2, \
  27. 6, 0, cmPolicies::WARN) \
  28. SELECT(POLICY, CMP0006, \
  29. "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.", \
  30. 2, 6, 0, cmPolicies::WARN) \
  31. SELECT(POLICY, CMP0007, "list command no longer ignores empty elements.", \
  32. 2, 6, 0, cmPolicies::WARN) \
  33. SELECT( \
  34. POLICY, CMP0008, \
  35. "Libraries linked by full-path must have a valid library file name.", 2, \
  36. 6, 1, cmPolicies::WARN) \
  37. SELECT(POLICY, CMP0009, \
  38. "FILE GLOB_RECURSE calls should not follow symlinks by default.", 2, \
  39. 6, 2, cmPolicies::WARN) \
  40. SELECT(POLICY, CMP0010, "Bad variable reference syntax is an error.", 2, 6, \
  41. 3, cmPolicies::WARN) \
  42. SELECT(POLICY, CMP0011, \
  43. "Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \
  44. cmPolicies::WARN) \
  45. SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \
  46. 2, 8, 0, cmPolicies::WARN) \
  47. SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \
  48. 8, 0, cmPolicies::WARN) \
  49. SELECT(POLICY, CMP0014, "Input directories must have CMakeLists.txt.", 2, \
  50. 8, 0, cmPolicies::WARN) \
  51. SELECT(POLICY, CMP0015, \
  52. "link_directories() treats paths relative to the source dir.", 2, 8, \
  53. 1, cmPolicies::WARN) \
  54. SELECT(POLICY, CMP0016, \
  55. "target_link_libraries() reports error if its only argument " \
  56. "is not a target.", \
  57. 2, 8, 3, cmPolicies::WARN) \
  58. SELECT(POLICY, CMP0017, \
  59. "Prefer files from the CMake module directory when including from " \
  60. "there.", \
  61. 2, 8, 4, cmPolicies::WARN) \
  62. SELECT(POLICY, CMP0018, \
  63. "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.", 2, 8, 9, \
  64. cmPolicies::WARN) \
  65. SELECT(POLICY, CMP0019, \
  66. "Do not re-expand variables in include and link information.", 2, 8, \
  67. 11, cmPolicies::WARN) \
  68. SELECT(POLICY, CMP0020, \
  69. "Automatically link Qt executables to qtmain target on Windows.", 2, \
  70. 8, 11, cmPolicies::WARN) \
  71. SELECT( \
  72. POLICY, CMP0021, \
  73. "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.", \
  74. 2, 8, 12, cmPolicies::WARN) \
  75. SELECT(POLICY, CMP0022, \
  76. "INTERFACE_LINK_LIBRARIES defines the link interface.", 2, 8, 12, \
  77. cmPolicies::WARN) \
  78. SELECT( \
  79. POLICY, CMP0023, \
  80. "Plain and keyword target_link_libraries signatures cannot be mixed.", 2, \
  81. 8, 12, cmPolicies::WARN) \
  82. SELECT(POLICY, CMP0024, "Disallow include export result.", 3, 0, 0, \
  83. cmPolicies::WARN) \
  84. SELECT(POLICY, CMP0025, "Compiler id for Apple Clang is now AppleClang.", \
  85. 3, 0, 0, cmPolicies::WARN) \
  86. SELECT(POLICY, CMP0026, "Disallow use of the LOCATION target property.", 3, \
  87. 0, 0, cmPolicies::WARN) \
  88. SELECT(POLICY, CMP0027, \
  89. "Conditionally linked imported targets with missing include " \
  90. "directories.", \
  91. 3, 0, 0, cmPolicies::WARN) \
  92. SELECT(POLICY, CMP0028, \
  93. "Double colon in target name means ALIAS or IMPORTED target.", 3, 0, \
  94. 0, cmPolicies::WARN) \
  95. SELECT(POLICY, CMP0029, "The subdir_depends command should not be called.", \
  96. 3, 0, 0, cmPolicies::WARN) \
  97. SELECT(POLICY, CMP0030, \
  98. "The use_mangled_mesa command should not be called.", 3, 0, 0, \
  99. cmPolicies::WARN) \
  100. SELECT(POLICY, CMP0031, "The load_command command should not be called.", \
  101. 3, 0, 0, cmPolicies::WARN) \
  102. SELECT(POLICY, CMP0032, \
  103. "The output_required_files command should not be called.", 3, 0, 0, \
  104. cmPolicies::WARN) \
  105. SELECT(POLICY, CMP0033, \
  106. "The export_library_dependencies command should not be called.", 3, \
  107. 0, 0, cmPolicies::WARN) \
  108. SELECT(POLICY, CMP0034, "The utility_source command should not be called.", \
  109. 3, 0, 0, cmPolicies::WARN) \
  110. SELECT(POLICY, CMP0035, \
  111. "The variable_requires command should not be called.", 3, 0, 0, \
  112. cmPolicies::WARN) \
  113. SELECT(POLICY, CMP0036, "The build_name command should not be called.", 3, \
  114. 0, 0, cmPolicies::WARN) \
  115. SELECT(POLICY, CMP0037, \
  116. "Target names should not be reserved and should match a validity " \
  117. "pattern.", \
  118. 3, 0, 0, cmPolicies::WARN) \
  119. SELECT(POLICY, CMP0038, "Targets may not link directly to themselves.", 3, \
  120. 0, 0, cmPolicies::WARN) \
  121. SELECT(POLICY, CMP0039, "Utility targets may not have link dependencies.", \
  122. 3, 0, 0, cmPolicies::WARN) \
  123. SELECT(POLICY, CMP0040, \
  124. "The target in the TARGET signature of add_custom_command() must " \
  125. "exist and must be defined in the current directory.", \
  126. 3, 0, 0, cmPolicies::WARN) \
  127. SELECT(POLICY, CMP0041, \
  128. "Error on relative include with generator expression.", 3, 0, 0, \
  129. cmPolicies::WARN) \
  130. SELECT(POLICY, CMP0042, "MACOSX_RPATH is enabled by default.", 3, 0, 0, \
  131. cmPolicies::WARN) \
  132. SELECT(POLICY, CMP0043, "Ignore COMPILE_DEFINITIONS_<Config> properties.", \
  133. 3, 0, 0, cmPolicies::WARN) \
  134. SELECT(POLICY, CMP0044, \
  135. "Case sensitive <LANG>_COMPILER_ID generator expressions.", 3, 0, 0, \
  136. cmPolicies::WARN) \
  137. SELECT(POLICY, CMP0045, \
  138. "Error on non-existent target in get_target_property.", 3, 0, 0, \
  139. cmPolicies::WARN) \
  140. SELECT(POLICY, CMP0046, \
  141. "Error on non-existent dependency in add_dependencies.", 3, 0, 0, \
  142. cmPolicies::WARN) \
  143. SELECT(POLICY, CMP0047, "Use QCC compiler id for the qcc drivers on QNX.", \
  144. 3, 0, 0, cmPolicies::WARN) \
  145. SELECT(POLICY, CMP0048, "project() command manages VERSION variables.", 3, \
  146. 0, 0, cmPolicies::WARN) \
  147. SELECT(POLICY, CMP0049, \
  148. "Do not expand variables in target source entries.", 3, 0, 0, \
  149. cmPolicies::WARN) \
  150. SELECT(POLICY, CMP0050, "Disallow add_custom_command SOURCE signatures.", \
  151. 3, 0, 0, cmPolicies::WARN) \
  152. SELECT(POLICY, CMP0051, "List TARGET_OBJECTS in SOURCES target property.", \
  153. 3, 1, 0, cmPolicies::WARN) \
  154. SELECT(POLICY, CMP0052, "Reject source and build dirs in installed " \
  155. "INTERFACE_INCLUDE_DIRECTORIES.", \
  156. 3, 1, 0, cmPolicies::WARN) \
  157. SELECT(POLICY, CMP0053, \
  158. "Simplify variable reference and escape sequence evaluation.", 3, 1, \
  159. 0, cmPolicies::WARN) \
  160. SELECT( \
  161. POLICY, CMP0054, \
  162. "Only interpret if() arguments as variables or keywords when unquoted.", \
  163. 3, 1, 0, cmPolicies::WARN) \
  164. SELECT(POLICY, CMP0055, "Strict checking for break() command.", 3, 2, 0, \
  165. cmPolicies::WARN) \
  166. SELECT(POLICY, CMP0056, \
  167. "Honor link flags in try_compile() source-file signature.", 3, 2, 0, \
  168. cmPolicies::WARN) \
  169. SELECT(POLICY, CMP0057, "Support new IN_LIST if() operator.", 3, 3, 0, \
  170. cmPolicies::WARN) \
  171. SELECT(POLICY, CMP0058, \
  172. "Ninja requires custom command byproducts to be explicit.", 3, 3, 0, \
  173. cmPolicies::WARN) \
  174. SELECT(POLICY, CMP0059, \
  175. "Do not treat DEFINITIONS as a built-in directory property.", 3, 3, \
  176. 0, cmPolicies::WARN) \
  177. SELECT(POLICY, CMP0060, \
  178. "Link libraries by full path even in implicit directories.", 3, 3, \
  179. 0, cmPolicies::WARN) \
  180. SELECT(POLICY, CMP0061, \
  181. "CTest does not by default tell make to ignore errors (-i).", 3, 3, \
  182. 0, cmPolicies::WARN) \
  183. SELECT(POLICY, CMP0062, "Disallow install() of export() result.", 3, 3, 0, \
  184. cmPolicies::WARN) \
  185. SELECT(POLICY, CMP0063, \
  186. "Honor visibility properties for all target types.", 3, 3, 0, \
  187. cmPolicies::WARN) \
  188. SELECT(POLICY, CMP0064, "Support new TEST if() operator.", 3, 4, 0, \
  189. cmPolicies::WARN) \
  190. SELECT(POLICY, CMP0065, \
  191. "Do not add flags to export symbols from executables without " \
  192. "the ENABLE_EXPORTS target property.", \
  193. 3, 4, 0, cmPolicies::WARN) \
  194. SELECT(POLICY, CMP0066, \
  195. "Honor per-config flags in try_compile() source-file signature.", 3, \
  196. 7, 0, cmPolicies::WARN) \
  197. SELECT(POLICY, CMP0067, \
  198. "Honor language standard in try_compile() source-file signature.", \
  199. 3, 8, 0, cmPolicies::WARN) \
  200. SELECT(POLICY, CMP0068, \
  201. "RPATH settings on macOS do not affect install_name.", 3, 9, 0, \
  202. cmPolicies::WARN) \
  203. SELECT(POLICY, CMP0069, \
  204. "INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \
  205. cmPolicies::WARN) \
  206. SELECT(POLICY, CMP0070, \
  207. "Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \
  208. cmPolicies::WARN) \
  209. SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \
  210. 3, 10, 0, cmPolicies::WARN) \
  211. SELECT(POLICY, CMP0072, \
  212. "FindOpenGL prefers GLVND by default when available.", 3, 11, 0, \
  213. cmPolicies::WARN)
  214. #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
  215. #define CM_FOR_EACH_POLICY_ID(POLICY) \
  216. CM_FOR_EACH_POLICY_TABLE(POLICY, CM_SELECT_ID)
  217. #define CM_FOR_EACH_TARGET_POLICY(F) \
  218. F(CMP0003) \
  219. F(CMP0004) \
  220. F(CMP0008) \
  221. F(CMP0020) \
  222. F(CMP0021) \
  223. F(CMP0022) \
  224. F(CMP0027) \
  225. F(CMP0037) \
  226. F(CMP0038) \
  227. F(CMP0041) \
  228. F(CMP0042) \
  229. F(CMP0046) \
  230. F(CMP0052) \
  231. F(CMP0060) \
  232. F(CMP0063) \
  233. F(CMP0065) \
  234. F(CMP0068) \
  235. F(CMP0069)
  236. /** \class cmPolicies
  237. * \brief Handles changes in CMake behavior and policies
  238. *
  239. * See the cmake wiki section on
  240. * <a href="https://cmake.org/Wiki/CMake/Policies">policies</a>
  241. * for an overview of this class's purpose
  242. */
  243. class cmPolicies
  244. {
  245. public:
  246. /// Status of a policy
  247. enum PolicyStatus
  248. {
  249. OLD, ///< Use old behavior
  250. WARN, ///< Use old behavior but issue a warning
  251. NEW, ///< Use new behavior
  252. /// Issue an error if user doesn't set policy status to NEW and hits the
  253. /// check
  254. REQUIRED_IF_USED,
  255. REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
  256. };
  257. /// Policy identifiers
  258. enum PolicyID
  259. {
  260. #define POLICY_ENUM(POLICY_ID) POLICY_ID,
  261. CM_FOR_EACH_POLICY_ID(POLICY_ENUM)
  262. #undef POLICY_ENUM
  263. /** \brief Always the last entry.
  264. *
  265. * Useful mostly to avoid adding a comma the last policy when adding a new
  266. * one.
  267. */
  268. CMPCOUNT
  269. };
  270. ///! convert a string policy ID into a number
  271. static bool GetPolicyID(const char* id, /* out */ cmPolicies::PolicyID& pid);
  272. ///! Get the default status for a policy
  273. static cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  274. ///! Set a policy level for this listfile
  275. static bool ApplyPolicyVersion(cmMakefile* mf, const char* version);
  276. ///! return a warning string for a given policy
  277. static std::string GetPolicyWarning(cmPolicies::PolicyID id);
  278. static std::string GetPolicyDeprecatedWarning(cmPolicies::PolicyID id);
  279. ///! return an error string for when a required policy is unspecified
  280. static std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
  281. ///! return an error string for when a required policy is unspecified
  282. static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
  283. /** Represent a set of policy values. */
  284. struct PolicyMap
  285. {
  286. PolicyStatus Get(PolicyID id) const;
  287. void Set(PolicyID id, PolicyStatus status);
  288. bool IsDefined(PolicyID id) const;
  289. bool IsEmpty() const;
  290. private:
  291. #define POLICY_STATUS_COUNT 3
  292. std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;
  293. };
  294. };
  295. #endif