cmPolicies.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. SELECT(POLICY, CMP0085, "$<IN_LIST:...> handles empty list items.", 3, 14, \
  250. 0, cmPolicies::WARN) \
  251. SELECT(POLICY, CMP0086, \
  252. "UseSWIG honors SWIG_MODULE_NAME via -module flag.", 3, 14, 0, \
  253. cmPolicies::WARN) \
  254. SELECT(POLICY, CMP0087, \
  255. "Install CODE|SCRIPT allow the use of generator " \
  256. "expressions.", \
  257. 3, 14, 0, cmPolicies::WARN) \
  258. SELECT(POLICY, CMP0088, \
  259. "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.", \
  260. 3, 14, 0, cmPolicies::WARN) \
  261. SELECT(POLICY, CMP0089, \
  262. "Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \
  263. 15, 0, cmPolicies::WARN) \
  264. SELECT(POLICY, CMP0090, \
  265. "export(PACKAGE) does not populate package registry by default.", 3, \
  266. 15, 0, cmPolicies::WARN) \
  267. SELECT(POLICY, CMP0091, \
  268. "MSVC runtime library flags are selected by an abstraction.", 3, 15, \
  269. 0, cmPolicies::WARN) \
  270. SELECT(POLICY, CMP0092, \
  271. "MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.", 3, \
  272. 15, 0, cmPolicies::WARN) \
  273. SELECT(POLICY, CMP0093, "FindBoost reports Boost_VERSION in x.y.z format.", \
  274. 3, 15, 0, cmPolicies::WARN) \
  275. SELECT(POLICY, CMP0094, \
  276. "FindPython3, FindPython2 and FindPyton use " \
  277. "LOCATION for lookup strategy.", \
  278. 3, 15, 0, cmPolicies::WARN) \
  279. SELECT(POLICY, CMP0095, \
  280. "RPATH entries are properly escaped in the intermediary CMake " \
  281. "install script.", \
  282. 3, 16, 0, cmPolicies::WARN) \
  283. SELECT(POLICY, CMP0096, \
  284. "project() preserves leading zeros in version components.", 3, 16, \
  285. 0, cmPolicies::WARN) \
  286. SELECT(POLICY, CMP0097, \
  287. "ExternalProject_Add with GIT_SUBMODULES \"\" initializes no " \
  288. "submodules.", \
  289. 3, 16, 0, cmPolicies::WARN) \
  290. SELECT(POLICY, CMP0098, \
  291. "FindFLEX runs flex in CMAKE_CURRENT_BINARY_DIR when executing.", 3, \
  292. 17, 0, cmPolicies::WARN) \
  293. SELECT(POLICY, CMP0099, \
  294. "Link properties are transitive over private dependency on static " \
  295. "libraries.", \
  296. 3, 17, 0, cmPolicies::WARN) \
  297. SELECT(POLICY, CMP0100, "Let AUTOMOC and AUTOUIC process .hh files.", 3, \
  298. 17, 0, cmPolicies::WARN) \
  299. SELECT(POLICY, CMP0101, \
  300. "target_compile_options honors BEFORE keyword in all scopes.", 3, \
  301. 17, 0, cmPolicies::WARN) \
  302. SELECT(POLICY, CMP0102, \
  303. "mark_as_advanced() does nothing if a cache entry does not exist.", \
  304. 3, 17, 0, cmPolicies::WARN) \
  305. SELECT(POLICY, CMP0103, \
  306. "multiple export() with same FILE without APPEND is not allowed.", \
  307. 3, 18, 0, cmPolicies::WARN)
  308. #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
  309. #define CM_FOR_EACH_POLICY_ID(POLICY) \
  310. CM_FOR_EACH_POLICY_TABLE(POLICY, CM_SELECT_ID)
  311. #define CM_FOR_EACH_TARGET_POLICY(F) \
  312. F(CMP0003) \
  313. F(CMP0004) \
  314. F(CMP0008) \
  315. F(CMP0020) \
  316. F(CMP0021) \
  317. F(CMP0022) \
  318. F(CMP0027) \
  319. F(CMP0037) \
  320. F(CMP0038) \
  321. F(CMP0041) \
  322. F(CMP0042) \
  323. F(CMP0046) \
  324. F(CMP0052) \
  325. F(CMP0060) \
  326. F(CMP0063) \
  327. F(CMP0065) \
  328. F(CMP0068) \
  329. F(CMP0069) \
  330. F(CMP0073) \
  331. F(CMP0076) \
  332. F(CMP0081) \
  333. F(CMP0083) \
  334. F(CMP0095) \
  335. F(CMP0099)
  336. /** \class cmPolicies
  337. * \brief Handles changes in CMake behavior and policies
  338. *
  339. * See the cmake-policies(7) manual for an overview of this class's purpose.
  340. */
  341. class cmPolicies
  342. {
  343. public:
  344. /// Status of a policy
  345. enum PolicyStatus
  346. {
  347. OLD, ///< Use old behavior
  348. WARN, ///< Use old behavior but issue a warning
  349. NEW, ///< Use new behavior
  350. /// Issue an error if user doesn't set policy status to NEW and hits the
  351. /// check
  352. REQUIRED_IF_USED,
  353. REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
  354. };
  355. /// Policy identifiers
  356. enum PolicyID
  357. {
  358. #define POLICY_ENUM(POLICY_ID) POLICY_ID,
  359. CM_FOR_EACH_POLICY_ID(POLICY_ENUM)
  360. #undef POLICY_ENUM
  361. /** \brief Always the last entry.
  362. *
  363. * Useful mostly to avoid adding a comma the last policy when adding a new
  364. * one.
  365. */
  366. CMPCOUNT
  367. };
  368. //! convert a string policy ID into a number
  369. static bool GetPolicyID(const char* id, /* out */ cmPolicies::PolicyID& pid);
  370. //! Get the default status for a policy
  371. static cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  372. //! Set a policy level for this listfile
  373. static bool ApplyPolicyVersion(cmMakefile* mf,
  374. std::string const& version_min,
  375. std::string const& version_max);
  376. static bool ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
  377. unsigned int minorVer, unsigned int patchVer);
  378. //! return a warning string for a given policy
  379. static std::string GetPolicyWarning(cmPolicies::PolicyID id);
  380. static std::string GetPolicyDeprecatedWarning(cmPolicies::PolicyID id);
  381. //! return an error string for when a required policy is unspecified
  382. static std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
  383. //! return an error string for when a required policy is unspecified
  384. static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
  385. /** Represent a set of policy values. */
  386. struct PolicyMap
  387. {
  388. PolicyStatus Get(PolicyID id) const;
  389. void Set(PolicyID id, PolicyStatus status);
  390. bool IsDefined(PolicyID id) const;
  391. bool IsEmpty() const;
  392. private:
  393. #define POLICY_STATUS_COUNT 3
  394. std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;
  395. };
  396. };
  397. #endif