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