cmPolicies.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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, \
  155. "Reject source and build dirs in installed " \
  156. "INTERFACE_INCLUDE_DIRECTORIES.", \
  157. 3, 1, 0, cmPolicies::WARN) \
  158. SELECT(POLICY, CMP0053, \
  159. "Simplify variable reference and escape sequence evaluation.", 3, 1, \
  160. 0, cmPolicies::WARN) \
  161. SELECT( \
  162. POLICY, CMP0054, \
  163. "Only interpret if() arguments as variables or keywords when unquoted.", \
  164. 3, 1, 0, cmPolicies::WARN) \
  165. SELECT(POLICY, CMP0055, "Strict checking for break() command.", 3, 2, 0, \
  166. cmPolicies::WARN) \
  167. SELECT(POLICY, CMP0056, \
  168. "Honor link flags in try_compile() source-file signature.", 3, 2, 0, \
  169. cmPolicies::WARN) \
  170. SELECT(POLICY, CMP0057, "Support new IN_LIST if() operator.", 3, 3, 0, \
  171. cmPolicies::WARN) \
  172. SELECT(POLICY, CMP0058, \
  173. "Ninja requires custom command byproducts to be explicit.", 3, 3, 0, \
  174. cmPolicies::WARN) \
  175. SELECT(POLICY, CMP0059, \
  176. "Do not treat DEFINITIONS as a built-in directory property.", 3, 3, \
  177. 0, cmPolicies::WARN) \
  178. SELECT(POLICY, CMP0060, \
  179. "Link libraries by full path even in implicit directories.", 3, 3, \
  180. 0, cmPolicies::WARN) \
  181. SELECT(POLICY, CMP0061, \
  182. "CTest does not by default tell make to ignore errors (-i).", 3, 3, \
  183. 0, cmPolicies::WARN) \
  184. SELECT(POLICY, CMP0062, "Disallow install() of export() result.", 3, 3, 0, \
  185. cmPolicies::WARN) \
  186. SELECT(POLICY, CMP0063, \
  187. "Honor visibility properties for all target types.", 3, 3, 0, \
  188. cmPolicies::WARN) \
  189. SELECT(POLICY, CMP0064, "Support new TEST if() operator.", 3, 4, 0, \
  190. cmPolicies::WARN) \
  191. SELECT(POLICY, CMP0065, \
  192. "Do not add flags to export symbols from executables without " \
  193. "the ENABLE_EXPORTS target property.", \
  194. 3, 4, 0, cmPolicies::WARN) \
  195. SELECT(POLICY, CMP0066, \
  196. "Honor per-config flags in try_compile() source-file signature.", 3, \
  197. 7, 0, cmPolicies::WARN) \
  198. SELECT(POLICY, CMP0067, \
  199. "Honor language standard in try_compile() source-file signature.", \
  200. 3, 8, 0, cmPolicies::WARN) \
  201. SELECT(POLICY, CMP0068, \
  202. "RPATH settings on macOS do not affect install_name.", 3, 9, 0, \
  203. cmPolicies::WARN) \
  204. SELECT(POLICY, CMP0069, \
  205. "INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \
  206. cmPolicies::WARN) \
  207. SELECT(POLICY, CMP0070, \
  208. "Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \
  209. cmPolicies::WARN) \
  210. SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \
  211. 3, 10, 0, cmPolicies::WARN) \
  212. SELECT(POLICY, CMP0072, \
  213. "FindOpenGL prefers GLVND by default when available.", 3, 11, 0, \
  214. cmPolicies::WARN) \
  215. SELECT(POLICY, CMP0073, \
  216. "Do not produce legacy _LIB_DEPENDS cache entries.", 3, 12, 0, \
  217. cmPolicies::WARN) \
  218. SELECT(POLICY, CMP0074, "find_package uses <PackageName>_ROOT variables.", \
  219. 3, 12, 0, cmPolicies::WARN) \
  220. SELECT(POLICY, CMP0075, \
  221. "Include file check macros honor CMAKE_REQUIRED_LIBRARIES.", 3, 12, \
  222. 0, cmPolicies::WARN) \
  223. SELECT(POLICY, CMP0076, \
  224. "target_sources() command converts relative paths to absolute.", 3, \
  225. 13, 0, cmPolicies::WARN) \
  226. SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \
  227. cmPolicies::WARN) \
  228. SELECT(POLICY, CMP0078, "UseSWIG generates standard target names.", 3, 13, \
  229. 0, cmPolicies::WARN) \
  230. SELECT( \
  231. POLICY, CMP0079, \
  232. "target_link_libraries allows use with targets in other directories.", 3, \
  233. 13, 0, cmPolicies::WARN) \
  234. SELECT(POLICY, CMP0080, \
  235. "BundleUtilities cannot be included at configure time.", 3, 13, 0, \
  236. cmPolicies::WARN) \
  237. SELECT(POLICY, CMP0081, \
  238. "Relative paths not allowed in LINK_DIRECTORIES target property.", \
  239. 3, 13, 0, cmPolicies::WARN) \
  240. SELECT(POLICY, CMP0082, \
  241. "Install rules from add_subdirectory() are interleaved with those " \
  242. "in caller.", \
  243. 3, 14, 0, cmPolicies::WARN) \
  244. SELECT(POLICY, CMP0083, "Add PIE options when linking executable.", 3, 14, \
  245. 0, cmPolicies::WARN) \
  246. SELECT(POLICY, CMP0084, \
  247. "The FindQt module does not exist for find_package().", 3, 14, 0, \
  248. cmPolicies::WARN)
  249. #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
  250. #define CM_FOR_EACH_POLICY_ID(POLICY) \
  251. CM_FOR_EACH_POLICY_TABLE(POLICY, CM_SELECT_ID)
  252. #define CM_FOR_EACH_TARGET_POLICY(F) \
  253. F(CMP0003) \
  254. F(CMP0004) \
  255. F(CMP0008) \
  256. F(CMP0020) \
  257. F(CMP0021) \
  258. F(CMP0022) \
  259. F(CMP0027) \
  260. F(CMP0037) \
  261. F(CMP0038) \
  262. F(CMP0041) \
  263. F(CMP0042) \
  264. F(CMP0046) \
  265. F(CMP0052) \
  266. F(CMP0060) \
  267. F(CMP0063) \
  268. F(CMP0065) \
  269. F(CMP0068) \
  270. F(CMP0069) \
  271. F(CMP0073) \
  272. F(CMP0076) \
  273. F(CMP0081) \
  274. F(CMP0083)
  275. /** \class cmPolicies
  276. * \brief Handles changes in CMake behavior and policies
  277. *
  278. * See the cmake-policies(7) manual for an overview of this class's purpose.
  279. */
  280. class cmPolicies
  281. {
  282. public:
  283. /// Status of a policy
  284. enum PolicyStatus
  285. {
  286. OLD, ///< Use old behavior
  287. WARN, ///< Use old behavior but issue a warning
  288. NEW, ///< Use new behavior
  289. /// Issue an error if user doesn't set policy status to NEW and hits the
  290. /// check
  291. REQUIRED_IF_USED,
  292. REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
  293. };
  294. /// Policy identifiers
  295. enum PolicyID
  296. {
  297. #define POLICY_ENUM(POLICY_ID) POLICY_ID,
  298. CM_FOR_EACH_POLICY_ID(POLICY_ENUM)
  299. #undef POLICY_ENUM
  300. /** \brief Always the last entry.
  301. *
  302. * Useful mostly to avoid adding a comma the last policy when adding a new
  303. * one.
  304. */
  305. CMPCOUNT
  306. };
  307. ///! convert a string policy ID into a number
  308. static bool GetPolicyID(const char* id, /* out */ cmPolicies::PolicyID& pid);
  309. ///! Get the default status for a policy
  310. static cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  311. ///! Set a policy level for this listfile
  312. static bool ApplyPolicyVersion(cmMakefile* mf,
  313. std::string const& version_min,
  314. std::string const& version_max);
  315. static bool ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
  316. unsigned int minorVer, unsigned int patchVer);
  317. ///! return a warning string for a given policy
  318. static std::string GetPolicyWarning(cmPolicies::PolicyID id);
  319. static std::string GetPolicyDeprecatedWarning(cmPolicies::PolicyID id);
  320. ///! return an error string for when a required policy is unspecified
  321. static std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
  322. ///! return an error string for when a required policy is unspecified
  323. static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
  324. /** Represent a set of policy values. */
  325. struct PolicyMap
  326. {
  327. PolicyStatus Get(PolicyID id) const;
  328. void Set(PolicyID id, PolicyStatus status);
  329. bool IsDefined(PolicyID id) const;
  330. bool IsEmpty() const;
  331. private:
  332. #define POLICY_STATUS_COUNT 3
  333. std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;
  334. };
  335. };
  336. #endif