1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
12 #define CM_FOR_EACH_POLICY_TABLE(POLICY, SELECT) \
13 SELECT(POLICY, CMP0000, \
14 "A minimum required CMake version must be specified.", 2, 6, 0, \
16 SELECT(POLICY, CMP0001, \
17 "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.", 2, 6, 0, \
19 SELECT(POLICY, CMP0002, "Logical target names must be globally unique.", 2, \
20 6, 0, cmPolicies::WARN) \
23 "Libraries linked via full path no longer produce linker search paths.", \
24 2, 6, 0, cmPolicies::WARN) \
25 SELECT(POLICY, CMP0004, \
26 "Libraries linked may not have leading or trailing whitespace.", 2, \
27 6, 0, cmPolicies::WARN) \
28 SELECT(POLICY, CMP0005, \
29 "Preprocessor definition values are now escaped automatically.", 2, \
30 6, 0, cmPolicies::WARN) \
31 SELECT(POLICY, CMP0006, \
32 "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.", \
33 2, 6, 0, cmPolicies::WARN) \
34 SELECT(POLICY, CMP0007, "list command no longer ignores empty elements.", \
35 2, 6, 0, cmPolicies::WARN) \
38 "Libraries linked by full-path must have a valid library file name.", 2, \
39 6, 1, cmPolicies::WARN) \
40 SELECT(POLICY, CMP0009, \
41 "FILE GLOB_RECURSE calls should not follow symlinks by default.", 2, \
42 6, 2, cmPolicies::WARN) \
43 SELECT(POLICY, CMP0010, "Bad variable reference syntax is an error.", 2, 6, \
44 3, cmPolicies::WARN) \
45 SELECT(POLICY, CMP0011, \
46 "Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \
48 SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \
49 2, 8, 0, cmPolicies::WARN) \
50 SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \
51 8, 0, cmPolicies::WARN) \
52 SELECT(POLICY, CMP0014, "Input directories must have CMakeLists.txt.", 2, \
53 8, 0, cmPolicies::WARN) \
54 SELECT(POLICY, CMP0015, \
55 "link_directories() treats paths relative to the source dir.", 2, 8, \
56 1, cmPolicies::WARN) \
57 SELECT(POLICY, CMP0016, \
58 "target_link_libraries() reports error if its only argument " \
60 2, 8, 3, cmPolicies::WARN) \
61 SELECT(POLICY, CMP0017, \
62 "Prefer files from the CMake module directory when including from " \
64 2, 8, 4, cmPolicies::WARN) \
65 SELECT(POLICY, CMP0018, \
66 "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.", 2, 8, 9, \
68 SELECT(POLICY, CMP0019, \
69 "Do not re-expand variables in include and link information.", 2, 8, \
70 11, cmPolicies::WARN) \
71 SELECT(POLICY, CMP0020, \
72 "Automatically link Qt executables to qtmain target on Windows.", 2, \
73 8, 11, cmPolicies::WARN) \
76 "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.", \
77 2, 8, 12, cmPolicies::WARN) \
78 SELECT(POLICY, CMP0022, \
79 "INTERFACE_LINK_LIBRARIES defines the link interface.", 2, 8, 12, \
83 "Plain and keyword target_link_libraries signatures cannot be mixed.", 2, \
84 8, 12, cmPolicies::WARN) \
85 SELECT(POLICY, CMP0024, "Disallow include export result.", 3, 0, 0, \
87 SELECT(POLICY, CMP0025, "Compiler id for Apple Clang is now AppleClang.", \
88 3, 0, 0, cmPolicies::WARN) \
89 SELECT(POLICY, CMP0026, "Disallow use of the LOCATION target property.", 3, \
90 0, 0, cmPolicies::WARN) \
91 SELECT(POLICY, CMP0027, \
92 "Conditionally linked imported targets with missing include " \
94 3, 0, 0, cmPolicies::WARN) \
95 SELECT(POLICY, CMP0028, \
96 "Double colon in target name means ALIAS or IMPORTED target.", 3, 0, \
97 0, cmPolicies::WARN) \
98 SELECT(POLICY, CMP0029, "The subdir_depends command should not be called.", \
99 3, 0, 0, cmPolicies::WARN) \
100 SELECT(POLICY, CMP0030, \
101 "The use_mangled_mesa command should not be called.", 3, 0, 0, \
103 SELECT(POLICY, CMP0031, "The load_command command should not be called.", \
104 3, 0, 0, cmPolicies::WARN) \
105 SELECT(POLICY, CMP0032, \
106 "The output_required_files command should not be called.", 3, 0, 0, \
108 SELECT(POLICY, CMP0033, \
109 "The export_library_dependencies command should not be called.", 3, \
110 0, 0, cmPolicies::WARN) \
111 SELECT(POLICY, CMP0034, "The utility_source command should not be called.", \
112 3, 0, 0, cmPolicies::WARN) \
113 SELECT(POLICY, CMP0035, \
114 "The variable_requires command should not be called.", 3, 0, 0, \
116 SELECT(POLICY, CMP0036, "The build_name command should not be called.", 3, \
117 0, 0, cmPolicies::WARN) \
118 SELECT(POLICY, CMP0037, \
119 "Target names should not be reserved and should match a validity " \
121 3, 0, 0, cmPolicies::WARN) \
122 SELECT(POLICY, CMP0038, "Targets may not link directly to themselves.", 3, \
123 0, 0, cmPolicies::WARN) \
124 SELECT(POLICY, CMP0039, "Utility targets may not have link dependencies.", \
125 3, 0, 0, cmPolicies::WARN) \
126 SELECT(POLICY, CMP0040, \
127 "The target in the TARGET signature of add_custom_command() must " \
128 "exist and must be defined in the current directory.", \
129 3, 0, 0, cmPolicies::WARN) \
130 SELECT(POLICY, CMP0041, \
131 "Error on relative include with generator expression.", 3, 0, 0, \
133 SELECT(POLICY, CMP0042, "MACOSX_RPATH is enabled by default.", 3, 0, 0, \
135 SELECT(POLICY, CMP0043, "Ignore COMPILE_DEFINITIONS_<Config> properties.", \
136 3, 0, 0, cmPolicies::WARN) \
137 SELECT(POLICY, CMP0044, \
138 "Case sensitive <LANG>_COMPILER_ID generator expressions.", 3, 0, 0, \
140 SELECT(POLICY, CMP0045, \
141 "Error on non-existent target in get_target_property.", 3, 0, 0, \
143 SELECT(POLICY, CMP0046, \
144 "Error on non-existent dependency in add_dependencies.", 3, 0, 0, \
146 SELECT(POLICY, CMP0047, "Use QCC compiler id for the qcc drivers on QNX.", \
147 3, 0, 0, cmPolicies::WARN) \
148 SELECT(POLICY, CMP0048, "project() command manages VERSION variables.", 3, \
149 0, 0, cmPolicies::WARN) \
150 SELECT(POLICY, CMP0049, \
151 "Do not expand variables in target source entries.", 3, 0, 0, \
153 SELECT(POLICY, CMP0050, "Disallow add_custom_command SOURCE signatures.", \
154 3, 0, 0, cmPolicies::WARN) \
155 SELECT(POLICY, CMP0051, "List TARGET_OBJECTS in SOURCES target property.", \
156 3, 1, 0, cmPolicies::WARN) \
157 SELECT(POLICY, CMP0052, \
158 "Reject source and build dirs in installed " \
159 "INTERFACE_INCLUDE_DIRECTORIES.", \
160 3, 1, 0, cmPolicies::WARN) \
161 SELECT(POLICY, CMP0053, \
162 "Simplify variable reference and escape sequence evaluation.", 3, 1, \
163 0, cmPolicies::WARN) \
166 "Only interpret if() arguments as variables or keywords when unquoted.", \
167 3, 1, 0, cmPolicies::WARN) \
168 SELECT(POLICY, CMP0055, "Strict checking for break() command.", 3, 2, 0, \
170 SELECT(POLICY, CMP0056, \
171 "Honor link flags in try_compile() source-file signature.", 3, 2, 0, \
173 SELECT(POLICY, CMP0057, "Support new IN_LIST if() operator.", 3, 3, 0, \
175 SELECT(POLICY, CMP0058, \
176 "Ninja requires custom command byproducts to be explicit.", 3, 3, 0, \
178 SELECT(POLICY, CMP0059, \
179 "Do not treat DEFINITIONS as a built-in directory property.", 3, 3, \
180 0, cmPolicies::WARN) \
181 SELECT(POLICY, CMP0060, \
182 "Link libraries by full path even in implicit directories.", 3, 3, \
183 0, cmPolicies::WARN) \
184 SELECT(POLICY, CMP0061, \
185 "CTest does not by default tell make to ignore errors (-i).", 3, 3, \
186 0, cmPolicies::WARN) \
187 SELECT(POLICY, CMP0062, "Disallow install() of export() result.", 3, 3, 0, \
189 SELECT(POLICY, CMP0063, \
190 "Honor visibility properties for all target types.", 3, 3, 0, \
192 SELECT(POLICY, CMP0064, "Support new TEST if() operator.", 3, 4, 0, \
194 SELECT(POLICY, CMP0065, \
195 "Do not add flags to export symbols from executables without " \
196 "the ENABLE_EXPORTS target property.", \
197 3, 4, 0, cmPolicies::WARN) \
198 SELECT(POLICY, CMP0066, \
199 "Honor per-config flags in try_compile() source-file signature.", 3, \
200 7, 0, cmPolicies::WARN) \
201 SELECT(POLICY, CMP0067, \
202 "Honor language standard in try_compile() source-file signature.", \
203 3, 8, 0, cmPolicies::WARN) \
204 SELECT(POLICY, CMP0068, \
205 "RPATH settings on macOS do not affect install_name.", 3, 9, 0, \
207 SELECT(POLICY, CMP0069, \
208 "INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \
210 SELECT(POLICY, CMP0070, \
211 "Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \
213 SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \
214 3, 10, 0, cmPolicies::WARN) \
215 SELECT(POLICY, CMP0072, \
216 "FindOpenGL prefers GLVND by default when available.", 3, 11, 0, \
218 SELECT(POLICY, CMP0073, \
219 "Do not produce legacy _LIB_DEPENDS cache entries.", 3, 12, 0, \
221 SELECT(POLICY, CMP0074, "find_package uses <PackageName>_ROOT variables.", \
222 3, 12, 0, cmPolicies::WARN) \
223 SELECT(POLICY, CMP0075, \
224 "Include file check macros honor CMAKE_REQUIRED_LIBRARIES.", 3, 12, \
225 0, cmPolicies::WARN) \
226 SELECT(POLICY, CMP0076, \
227 "target_sources() command converts relative paths to absolute.", 3, \
228 13, 0, cmPolicies::WARN) \
229 SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \
231 SELECT(POLICY, CMP0078, "UseSWIG generates standard target names.", 3, 13, \
232 0, cmPolicies::WARN) \
235 "target_link_libraries allows use with targets in other directories.", 3, \
236 13, 0, cmPolicies::WARN) \
237 SELECT(POLICY, CMP0080, \
238 "BundleUtilities cannot be included at configure time.", 3, 13, 0, \
240 SELECT(POLICY, CMP0081, \
241 "Relative paths not allowed in LINK_DIRECTORIES target property.", \
242 3, 13, 0, cmPolicies::WARN) \
243 SELECT(POLICY, CMP0082, \
244 "Install rules from add_subdirectory() are interleaved with those " \
246 3, 14, 0, cmPolicies::WARN) \
247 SELECT(POLICY, CMP0083, "Add PIE options when linking executable.", 3, 14, \
248 0, cmPolicies::WARN) \
249 SELECT(POLICY, CMP0084, \
250 "The FindQt module does not exist for find_package().", 3, 14, 0, \
252 SELECT(POLICY, CMP0085, "$<IN_LIST:...> handles empty list items.", 3, 14, \
253 0, cmPolicies::WARN) \
254 SELECT(POLICY, CMP0086, \
255 "UseSWIG honors SWIG_MODULE_NAME via -module flag.", 3, 14, 0, \
257 SELECT(POLICY, CMP0087, \
258 "Install CODE|SCRIPT allow the use of generator " \
260 3, 14, 0, cmPolicies::WARN) \
261 SELECT(POLICY, CMP0088, \
262 "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.", \
263 3, 14, 0, cmPolicies::WARN) \
264 SELECT(POLICY, CMP0089, \
265 "Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \
266 15, 0, cmPolicies::WARN) \
267 SELECT(POLICY, CMP0090, \
268 "export(PACKAGE) does not populate package registry by default.", 3, \
269 15, 0, cmPolicies::WARN) \
270 SELECT(POLICY, CMP0091, \
271 "MSVC runtime library flags are selected by an abstraction.", 3, 15, \
272 0, cmPolicies::WARN) \
273 SELECT(POLICY, CMP0092, \
274 "MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.", 3, \
275 15, 0, cmPolicies::WARN) \
276 SELECT(POLICY, CMP0093, "FindBoost reports Boost_VERSION in x.y.z format.", \
277 3, 15, 0, cmPolicies::WARN) \
278 SELECT(POLICY, CMP0094, \
279 "FindPython3, FindPython2 and FindPyton use " \
280 "LOCATION for lookup strategy.", \
281 3, 15, 0, cmPolicies::WARN) \
282 SELECT(POLICY, CMP0095, \
283 "RPATH entries are properly escaped in the intermediary CMake " \
285 3, 16, 0, cmPolicies::WARN) \
286 SELECT(POLICY, CMP0096, \
287 "project() preserves leading zeros in version components.", 3, 16, \
288 0, cmPolicies::WARN) \
289 SELECT(POLICY, CMP0097, \
290 "ExternalProject_Add with GIT_SUBMODULES \"\" initializes no " \
292 3, 16, 0, cmPolicies::WARN) \
293 SELECT(POLICY, CMP0098, \
294 "FindFLEX runs flex in CMAKE_CURRENT_BINARY_DIR when executing.", 3, \
295 17, 0, cmPolicies::WARN) \
296 SELECT(POLICY, CMP0099, \
297 "Link properties are transitive over private dependency on static " \
299 3, 17, 0, cmPolicies::WARN) \
300 SELECT(POLICY, CMP0100, "Let AUTOMOC and AUTOUIC process .hh files.", 3, \
301 17, 0, cmPolicies::WARN) \
302 SELECT(POLICY, CMP0101, \
303 "target_compile_options honors BEFORE keyword in all scopes.", 3, \
304 17, 0, cmPolicies::WARN) \
305 SELECT(POLICY, CMP0102, \
306 "mark_as_advanced() does nothing if a cache entry does not exist.", \
307 3, 17, 0, cmPolicies::WARN) \
308 SELECT(POLICY, CMP0103, \
309 "Multiple export() with same FILE without APPEND is not allowed.", \
310 3, 18, 0, cmPolicies::WARN) \
311 SELECT(POLICY, CMP0104, \
312 "CMAKE_CUDA_ARCHITECTURES now detected for NVCC, empty " \
313 "CUDA_ARCHITECTURES not allowed.", \
314 3, 18, 0, cmPolicies::WARN) \
315 SELECT(POLICY, CMP0105, "Device link step uses the link options.", 3, 18, \
316 0, cmPolicies::WARN) \
317 SELECT(POLICY, CMP0106, "The Documentation module is removed.", 3, 18, 0, \
319 SELECT(POLICY, CMP0107, "An ALIAS target cannot overwrite another target.", \
320 3, 18, 0, cmPolicies::WARN) \
321 SELECT(POLICY, CMP0108, "A target cannot link to itself through an alias.", \
322 3, 18, 0, cmPolicies::WARN) \
323 SELECT(POLICY, CMP0109, \
324 "find_program() requires permission to execute but not to read.", 3, \
325 19, 0, cmPolicies::WARN) \
326 SELECT(POLICY, CMP0110, \
327 "add_test() supports arbitrary characters in test names.", 3, 19, 0, \
329 SELECT(POLICY, CMP0111, \
330 "An imported target missing its location property fails during " \
332 3, 19, 0, cmPolicies::WARN) \
333 SELECT(POLICY, CMP0112, \
334 "Target file component generator expressions do not add target " \
336 3, 19, 0, cmPolicies::WARN) \
337 SELECT(POLICY, CMP0113, \
338 "Makefile generators do not repeat custom commands from target " \
340 3, 19, 0, cmPolicies::WARN) \
341 SELECT(POLICY, CMP0114, \
342 "ExternalProject step targets fully adopt their steps.", 3, 19, 0, \
344 SELECT(POLICY, CMP0115, "Source file extensions must be explicit.", 3, 20, \
345 0, cmPolicies::WARN) \
346 SELECT(POLICY, CMP0116, \
347 "Ninja generators transform DEPFILEs from add_custom_command().", 3, \
348 20, 0, cmPolicies::WARN) \
349 SELECT(POLICY, CMP0117, \
350 "MSVC RTTI flag /GR is not added to CMAKE_CXX_FLAGS by default.", 3, \
351 20, 0, cmPolicies::WARN) \
354 "The GENERATED source file property is now visible in all directories.", \
355 3, 20, 0, cmPolicies::WARN) \
356 SELECT(POLICY, CMP0119, \
357 "LANGUAGE source file property explicitly compiles as specified " \
359 3, 20, 0, cmPolicies::WARN) \
360 SELECT(POLICY, CMP0120, \
361 "The WriteCompilerDetectionHeader module is removed.", 3, 20, 0, \
363 SELECT(POLICY, CMP0121, \
364 "The list() command now validates parsing of index arguments.", 3, \
365 21, 0, cmPolicies::WARN) \
368 "UseSWIG use standard library name conventions for csharp language.", 3, \
369 21, 0, cmPolicies::WARN) \
370 SELECT(POLICY, CMP0123, \
371 "ARMClang cpu/arch compile and link flags must be set explicitly.", \
372 3, 21, 0, cmPolicies::WARN) \
373 SELECT(POLICY, CMP0124, \
374 "foreach() loop variables are only available in the loop scope.", 3, \
375 21, 0, cmPolicies::WARN) \
376 SELECT(POLICY, CMP0125, \
377 "find_(path|file|library|program) have consistent behavior for " \
378 "cache variables.", \
379 3, 21, 0, cmPolicies::WARN) \
380 SELECT(POLICY, CMP0126, \
381 "set(CACHE) does not remove a normal variable of the same name.", 3, \
382 21, 0, cmPolicies::WARN) \
383 SELECT(POLICY, CMP0127, \
384 "cmake_dependent_option() supports full Condition Syntax.", 3, 22, \
385 0, cmPolicies::WARN) \
386 SELECT(POLICY, CMP0128, \
387 "Selection of language standard and extension flags improved.", 3, \
388 22, 0, cmPolicies::WARN) \
389 SELECT(POLICY, CMP0129, \
390 "Compiler id for MCST LCC compilers is now LCC, not GNU.", 3, 23, 0, \
392 SELECT(POLICY, CMP0130, "while() diagnoses condition evaluation errors.", \
393 3, 24, 0, cmPolicies::WARN) \
394 SELECT(POLICY, CMP0131, \
395 "LINK_LIBRARIES supports the LINK_ONLY generator expression.", 3, \
396 24, 0, cmPolicies::WARN) \
397 SELECT(POLICY, CMP0132, \
398 "Do not set compiler environment variables on first run", 3, 24, 0, \
400 SELECT(POLICY, CMP0133, \
401 "The CPack module disables SLA by default in the CPack DragNDrop " \
403 3, 24, 0, cmPolicies::WARN) \
404 SELECT(POLICY, CMP0134, \
405 "Fallback to \"HOST\" Windows registry view when \"TARGET\" view " \
407 3, 24, 0, cmPolicies::WARN) \
408 SELECT(POLICY, CMP0135, \
409 "ExternalProject ignores timestamps in archives by default for the " \
410 "URL download method", \
411 3, 24, 0, cmPolicies::WARN) \
412 SELECT(POLICY, CMP0136, \
413 "Watcom runtime library flags are selected by an abstraction.", 3, \
414 24, 0, cmPolicies::WARN) \
415 SELECT(POLICY, CMP0137, \
416 "try_compile() passes platform variables in project mode", 3, 24, 0, \
418 SELECT(POLICY, CMP0138, \
419 "CheckIPOSupported uses flags from calling project.", 3, 24, 0, \
423 "The if() command supports path comparisons using PATH_EQUAL operator.", \
424 3, 24, 0, cmPolicies::WARN)
426 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
427 #define CM_FOR_EACH_POLICY_ID(POLICY) \
428 CM_FOR_EACH_POLICY_TABLE(POLICY, CM_SELECT_ID)
430 #define CM_FOR_EACH_TARGET_POLICY(F) \
463 /** \class cmPolicies
464 * \brief Handles changes in CMake behavior and policies
466 * See the cmake-policies(7) manual for an overview of this class's purpose.
471 /// Status of a policy
474 OLD, ///< Use old behavior
475 WARN, ///< Use old behavior but issue a warning
476 NEW, ///< Use new behavior
477 /// Issue an error if user doesn't set policy status to NEW and hits the
480 REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
483 /// Policy identifiers
486 #define POLICY_ENUM(POLICY_ID) POLICY_ID,
487 CM_FOR_EACH_POLICY_ID(POLICY_ENUM)
490 /** \brief Always the last entry.
492 * Useful mostly to avoid adding a comma the last policy when adding a new
498 //! convert a string policy ID into a number
499 static bool GetPolicyID(const char* id, /* out */ cmPolicies::PolicyID& pid);
501 //! Get the default status for a policy
502 static cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
504 enum class WarnCompat
510 //! Set a policy level for this listfile
511 static bool ApplyPolicyVersion(cmMakefile* mf,
512 std::string const& version_min,
513 std::string const& version_max,
514 WarnCompat warnCompat);
515 static bool ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
516 unsigned int minorVer, unsigned int patchVer,
517 WarnCompat warnCompat);
519 //! return a warning string for a given policy
520 static std::string GetPolicyWarning(cmPolicies::PolicyID id);
521 static std::string GetPolicyDeprecatedWarning(cmPolicies::PolicyID id);
523 //! return an error string for when a required policy is unspecified
524 static std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
526 //! return an error string for when a required policy is unspecified
527 static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
529 /** Represent a set of policy values. */
532 PolicyStatus Get(PolicyID id) const;
533 void Set(PolicyID id, PolicyStatus status);
534 bool IsDefined(PolicyID id) const;
535 bool IsEmpty() const;
538 #define POLICY_STATUS_COUNT 3
539 std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;