cmPolicies.h 11 KB

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