cmPolicies.h 19 KB

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