1 #include "cmPolicies.h"
3 #include "cmMakefile.h"
4 #include "cmSourceFile.h"
6 #include "cmVersionMacros.h"
12 const char* cmPolicies::PolicyStatusNames[] = {
13 "OLD", "WARN", "NEW", "REQUIRED_IF_USED", "REQUIRED_ALWAYS"
19 cmPolicy(cmPolicies::PolicyID iD,
21 const char *shortDescription,
22 const char *longDescription,
23 unsigned int majorVersionIntroduced,
24 unsigned int minorVersionIntroduced,
25 unsigned int patchVersionIntroduced,
26 unsigned int tweakVersionIntroduced,
27 cmPolicies::PolicyStatus status)
29 if (!idString || !shortDescription || ! longDescription)
31 cmSystemTools::Error("Attempt to define a policy without "
32 "all parameters being specified!");
36 this->IDString = idString;
37 this->ShortDescription = shortDescription;
38 this->LongDescription = longDescription;
39 this->MajorVersionIntroduced = majorVersionIntroduced;
40 this->MinorVersionIntroduced = minorVersionIntroduced;
41 this->PatchVersionIntroduced = patchVersionIntroduced;
42 this->TweakVersionIntroduced = tweakVersionIntroduced;
43 this->Status = status;
46 std::string GetVersionString()
49 v << this->MajorVersionIntroduced << "." << this->MinorVersionIntroduced;
50 v << "." << this->PatchVersionIntroduced;
51 if(this->TweakVersionIntroduced > 0)
53 v << "." << this->TweakVersionIntroduced;
58 bool IsPolicyNewerThan(unsigned int majorV,
63 if (majorV < this->MajorVersionIntroduced)
67 if (majorV > this->MajorVersionIntroduced)
71 if (minorV < this->MinorVersionIntroduced)
75 if (minorV > this->MinorVersionIntroduced)
79 if (patchV < this->PatchVersionIntroduced)
83 if (patchV > this->PatchVersionIntroduced)
87 return (tweakV < this->TweakVersionIntroduced);
90 cmPolicies::PolicyID ID;
92 std::string ShortDescription;
93 std::string LongDescription;
94 unsigned int MajorVersionIntroduced;
95 unsigned int MinorVersionIntroduced;
96 unsigned int PatchVersionIntroduced;
97 unsigned int TweakVersionIntroduced;
98 cmPolicies::PolicyStatus Status;
101 cmPolicies::cmPolicies()
103 // define all the policies
106 "A minimum required CMake version must be specified.",
107 "CMake requires that projects specify the version of CMake to which "
108 "they have been written. "
109 "This policy has been put in place so users trying to build the project "
110 "may be told when they need to update their CMake. "
111 "Specifying a version also helps the project build with CMake versions "
112 "newer than that specified. "
113 "Use the cmake_minimum_required command at the top of your main "
114 " CMakeLists.txt file:\n"
115 " cmake_minimum_required(VERSION <major>.<minor>)\n"
116 "where \"<major>.<minor>\" is the version of CMake you want to support "
117 "(such as \"2.6\"). "
118 "The command will ensure that at least the given version of CMake is "
119 "running and help newer versions be compatible with the project. "
120 "See documentation of cmake_minimum_required for details.\n"
121 "Note that the command invocation must appear in the CMakeLists.txt "
122 "file itself; a call in an included file is not sufficient. "
123 "However, the cmake_policy command may be called to set policy "
124 "CMP0000 to OLD or NEW behavior explicitly. "
125 "The OLD behavior is to silently ignore the missing invocation. "
126 "The NEW behavior is to issue an error instead of a warning. "
127 "An included file may set CMP0000 explicitly to affect how this "
128 "policy is enforced for the main CMakeLists.txt file.",
129 2,6,0,0, cmPolicies::WARN
134 "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
135 "The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present "
137 "The NEW behavior is to ignore CMAKE_BACKWARDS_COMPATIBILITY "
139 "In CMake 2.4 and below the variable CMAKE_BACKWARDS_COMPATIBILITY was "
140 "used to request compatibility with earlier versions of CMake. "
141 "In CMake 2.6 and above all compatibility issues are handled by policies "
142 "and the cmake_policy command. "
143 "However, CMake must still check CMAKE_BACKWARDS_COMPATIBILITY for "
144 "projects written for CMake 2.4 and below.",
145 2,6,0,0, cmPolicies::WARN
150 "Logical target names must be globally unique.",
151 "Targets names created with "
152 "add_executable, add_library, or add_custom_target "
153 "are logical build target names. "
154 "Logical target names must be globally unique because:\n"
155 " - Unique names may be referenced unambiguously both in CMake\n"
156 " code and on make tool command lines.\n"
157 " - Logical names are used by Xcode and VS IDE generators\n"
158 " to produce meaningful project names for the targets.\n"
159 "The logical name of executable and library targets does not "
160 "have to correspond to the physical file names built. "
161 "Consider using the OUTPUT_NAME target property to create two "
162 "targets with the same physical name while keeping logical "
164 "Custom targets must simply have globally unique names (unless one "
165 "uses the global property ALLOW_DUPLICATE_CUSTOM_TARGETS with a "
166 "Makefiles generator).",
167 2,6,0,0, cmPolicies::WARN
172 "Libraries linked via full path no longer produce linker search paths.",
173 "This policy affects how libraries whose full paths are NOT known "
174 "are found at link time, but was created due to a change in how CMake "
175 "deals with libraries whose full paths are known. "
176 "Consider the code\n"
177 " target_link_libraries(myexe /path/to/libA.so)\n"
178 "CMake 2.4 and below implemented linking to libraries whose full paths "
179 "are known by splitting them on the link line into separate components "
180 "consisting of the linker search path and the library name. "
181 "The example code might have produced something like\n"
182 " ... -L/path/to -lA ...\n"
183 "in order to link to library A. "
184 "An analysis was performed to order multiple link directories such that "
185 "the linker would find library A in the desired location, but there "
186 "are cases in which this does not work. "
187 "CMake versions 2.6 and above use the more reliable approach of passing "
188 "the full path to libraries directly to the linker in most cases. "
189 "The example code now produces something like\n"
190 " ... /path/to/libA.so ....\n"
191 "Unfortunately this change can break code like\n"
192 " target_link_libraries(myexe /path/to/libA.so B)\n"
193 "where \"B\" is meant to find \"/path/to/libB.so\". "
194 "This code is wrong because the user is asking the linker to find "
195 "library B but has not provided a linker search path (which may be "
196 "added with the link_directories command). "
197 "However, with the old linking implementation the code would work "
198 "accidentally because the linker search path added for library A "
199 "allowed library B to be found."
201 "In order to support projects depending on linker search paths "
202 "added by linking to libraries with known full paths, the OLD "
203 "behavior for this policy will add the linker search paths even "
204 "though they are not needed for their own libraries. "
205 "When this policy is set to OLD, CMake will produce a link line such as\n"
206 " ... -L/path/to /path/to/libA.so -lB ...\n"
207 "which will allow library B to be found as it was previously. "
208 "When this policy is set to NEW, CMake will produce a link line such as\n"
209 " ... /path/to/libA.so -lB ...\n"
210 "which more accurately matches what the project specified."
212 "The setting for this policy used when generating the link line is that "
213 "in effect when the target is created by an add_executable or "
214 "add_library command. For the example described above, the code\n"
215 " cmake_policy(SET CMP0003 OLD) # or cmake_policy(VERSION 2.4)\n"
216 " add_executable(myexe myexe.c)\n"
217 " target_link_libraries(myexe /path/to/libA.so B)\n"
218 "will work and suppress the warning for this policy. "
219 "It may also be updated to work with the corrected linking approach:\n"
220 " cmake_policy(SET CMP0003 NEW) # or cmake_policy(VERSION 2.6)\n"
221 " link_directories(/path/to) # needed to find library B\n"
222 " add_executable(myexe myexe.c)\n"
223 " target_link_libraries(myexe /path/to/libA.so B)\n"
224 "Even better, library B may be specified with a full path:\n"
225 " add_executable(myexe myexe.c)\n"
226 " target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)\n"
227 "When all items on the link line have known paths CMake does not check "
228 "this policy so it has no effect.\n"
229 "Note that the warning for this policy will be issued for at most "
230 "one target. This avoids flooding users with messages for every "
231 "target when setting the policy once will probably fix all targets.",
232 2,6,0,0, cmPolicies::WARN);
236 "Libraries linked may not have leading or trailing whitespace.",
237 "CMake versions 2.4 and below silently removed leading and trailing "
238 "whitespace from libraries linked with code like\n"
239 " target_link_libraries(myexe \" A \")\n"
240 "This could lead to subtle errors in user projects.\n"
241 "The OLD behavior for this policy is to silently remove leading and "
242 "trailing whitespace. "
243 "The NEW behavior for this policy is to diagnose the existence of "
244 "such whitespace as an error. "
245 "The setting for this policy used when checking the library names is "
246 "that in effect when the target is created by an add_executable or "
247 "add_library command.",
248 2,6,0,0, cmPolicies::WARN);
252 "Preprocessor definition values are now escaped automatically.",
253 "This policy determines whether or not CMake should generate escaped "
254 "preprocessor definition values added via add_definitions. "
255 "CMake versions 2.4 and below assumed that only trivial values would "
256 "be given for macros in add_definitions calls. "
257 "It did not attempt to escape non-trivial values such as string "
258 "literals in generated build rules. "
259 "CMake versions 2.6 and above support escaping of most values, but "
260 "cannot assume the user has not added escapes already in an attempt to "
261 "work around limitations in earlier versions.\n"
262 "The OLD behavior for this policy is to place definition values given "
263 "to add_definitions directly in the generated build rules without "
264 "attempting to escape anything. "
265 "The NEW behavior for this policy is to generate correct escapes "
266 "for all native build tools automatically. "
267 "See documentation of the COMPILE_DEFINITIONS target property for "
268 "limitations of the escaping implementation.",
269 2,6,0,0, cmPolicies::WARN);
273 "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.",
274 "This policy determines whether the install(TARGETS) command must be "
275 "given a BUNDLE DESTINATION when asked to install a target with the "
276 "MACOSX_BUNDLE property set. "
277 "CMake 2.4 and below did not distinguish application bundles from "
278 "normal executables when installing targets. "
279 "CMake 2.6 provides a BUNDLE option to the install(TARGETS) command "
280 "that specifies rules specific to application bundles on the Mac. "
281 "Projects should use this option when installing a target with the "
282 "MACOSX_BUNDLE property set.\n"
283 "The OLD behavior for this policy is to fall back to the RUNTIME "
284 "DESTINATION if a BUNDLE DESTINATION is not given. "
285 "The NEW behavior for this policy is to produce an error if a bundle "
286 "target is installed without a BUNDLE DESTINATION.",
287 2,6,0,0, cmPolicies::WARN);
291 "list command no longer ignores empty elements.",
292 "This policy determines whether the list command will "
293 "ignore empty elements in the list. "
294 "CMake 2.4 and below list commands ignored all empty elements"
295 " in the list. For example, a;b;;c would have length 3 and not 4. "
296 "The OLD behavior for this policy is to ignore empty list elements. "
297 "The NEW behavior for this policy is to correctly count empty "
298 "elements in a list. ",
299 2,6,0,0, cmPolicies::WARN);
303 "Libraries linked by full-path must have a valid library file name.",
304 "In CMake 2.4 and below it is possible to write code like\n"
305 " target_link_libraries(myexe /full/path/to/somelib)\n"
306 "where \"somelib\" is supposed to be a valid library file name "
307 "such as \"libsomelib.a\" or \"somelib.lib\". "
308 "For Makefile generators this produces an error at build time "
309 "because the dependency on the full path cannot be found. "
310 "For VS IDE and Xcode generators this used to work by accident because "
311 "CMake would always split off the library directory and ask the "
312 "linker to search for the library by name (-lsomelib or somelib.lib). "
313 "Despite the failure with Makefiles, some projects have code like this "
314 "and build only with VS and/or Xcode. "
315 "This version of CMake prefers to pass the full path directly to the "
316 "native build tool, which will fail in this case because it does "
317 "not name a valid library file."
319 "This policy determines what to do with full paths that do not appear "
320 "to name a valid library file. "
321 "The OLD behavior for this policy is to split the library name from the "
322 "path and ask the linker to search for it. "
323 "The NEW behavior for this policy is to trust the given path and "
324 "pass it directly to the native build tool unchanged.",
325 2,6,1,0, cmPolicies::WARN);
329 "FILE GLOB_RECURSE calls should not follow symlinks by default.",
330 "In CMake 2.6.1 and below, FILE GLOB_RECURSE calls would follow "
331 "through symlinks, sometimes coming up with unexpectedly large "
332 "result sets because of symlinks to top level directories that "
333 "contain hundreds of thousands of files."
335 "This policy determines whether or not to follow symlinks "
336 "encountered during a FILE GLOB_RECURSE call. "
337 "The OLD behavior for this policy is to follow the symlinks. "
338 "The NEW behavior for this policy is not to follow the symlinks "
339 "by default, but only if FOLLOW_SYMLINKS is given as an additional "
340 "argument to the FILE command.",
341 2,6,2,0, cmPolicies::WARN);
345 "Bad variable reference syntax is an error.",
346 "In CMake 2.6.2 and below, incorrect variable reference syntax such as "
347 "a missing close-brace (\"${FOO\") was reported but did not stop "
348 "processing of CMake code. "
349 "This policy determines whether a bad variable reference is an error. "
350 "The OLD behavior for this policy is to warn about the error, leave "
351 "the string untouched, and continue. "
352 "The NEW behavior for this policy is to report an error.",
353 2,6,3,0, cmPolicies::WARN);
357 "Included scripts do automatic cmake_policy PUSH and POP.",
358 "In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by "
359 "the include() and find_package() commands would affect the includer. "
360 "Explicit invocations of cmake_policy(PUSH) and cmake_policy(POP) were "
361 "required to isolate policy changes and protect the includer. "
362 "While some scripts intend to affect the policies of their includer, "
364 "In CMake 2.6.3 and above, include() and find_package() by default PUSH "
365 "and POP an entry on the policy stack around an included script, "
366 "but provide a NO_POLICY_SCOPE option to disable it. "
367 "This policy determines whether or not to imply NO_POLICY_SCOPE for "
369 "The OLD behavior for this policy is to imply NO_POLICY_SCOPE for "
370 "include() and find_package() commands. "
371 "The NEW behavior for this policy is to allow the commands to do their "
372 "default cmake_policy PUSH and POP.",
373 2,6,3,0, cmPolicies::WARN);
377 "if() recognizes numbers and boolean constants.",
378 "In CMake versions 2.6.4 and lower the if() command implicitly "
379 "dereferenced arguments corresponding to variables, even those named "
380 "like numbers or boolean constants, except for 0 and 1. "
381 "Numbers and boolean constants such as true, false, yes, no, "
382 "on, off, y, n, notfound, ignore (all case insensitive) were recognized "
383 "in some cases but not all. "
384 "For example, the code \"if(TRUE)\" might have evaluated as false. "
385 "Numbers such as 2 were recognized only in "
386 "boolean expressions like \"if(NOT 2)\" (leading to false) "
387 "but not as a single-argument like \"if(2)\" (also leading to false). "
388 "Later versions of CMake prefer to treat numbers and boolean constants "
389 "literally, so they should not be used as variable names."
391 "The OLD behavior for this policy is to implicitly dereference variables "
392 "named like numbers and boolean constants. "
393 "The NEW behavior for this policy is to recognize numbers and "
394 "boolean constants without dereferencing variables with such names.",
395 2,8,0,0, cmPolicies::WARN);
399 "Duplicate binary directories are not allowed.",
400 "CMake 2.6.3 and below silently permitted add_subdirectory() calls "
401 "to create the same binary directory multiple times. "
402 "During build system generation files would be written and then "
403 "overwritten in the build tree and could lead to strange behavior. "
404 "CMake 2.6.4 and above explicitly detect duplicate binary directories. "
405 "CMake 2.6.4 always considers this case an error. "
406 "In CMake 2.8.0 and above this policy determines whether or not "
407 "the case is an error. "
408 "The OLD behavior for this policy is to allow duplicate binary "
410 "The NEW behavior for this policy is to disallow duplicate binary "
411 "directories with an error.",
412 2,8,0,0, cmPolicies::WARN);
416 "Input directories must have CMakeLists.txt.",
417 "CMake versions before 2.8 silently ignored missing CMakeLists.txt "
418 "files in directories referenced by add_subdirectory() or subdirs(), "
419 "treating them as if present but empty. "
420 "In CMake 2.8.0 and above this policy determines whether or not "
421 "the case is an error. "
422 "The OLD behavior for this policy is to silently ignore the problem. "
423 "The NEW behavior for this policy is to report an error.",
424 2,8,0,0, cmPolicies::WARN);
428 "link_directories() treats paths relative to the source dir.",
429 "In CMake 2.8.0 and lower the link_directories() command passed relative "
430 "paths unchanged to the linker. "
431 "In CMake 2.8.1 and above the link_directories() command prefers to "
432 "interpret relative paths with respect to CMAKE_CURRENT_SOURCE_DIR, "
433 "which is consistent with include_directories() and other commands. "
434 "The OLD behavior for this policy is to use relative paths verbatim in "
435 "the linker command. "
436 "The NEW behavior for this policy is to convert relative paths to "
437 "absolute paths by appending the relative path to "
438 "CMAKE_CURRENT_SOURCE_DIR.",
439 2,8,1,0, cmPolicies::WARN);
443 "target_link_libraries() reports error if its only argument "
445 "In CMake 2.8.2 and lower the target_link_libraries() command silently "
446 "ignored if it was called with only one argument, and this argument "
447 "wasn't a valid target. "
448 "In CMake 2.8.3 and above it reports an error in this case.",
449 2,8,3,0, cmPolicies::WARN);
453 "Prefer files from the CMake module directory when including from there.",
454 "Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e. "
455 "located in the CMake module directory) calls include() or "
456 "find_package(), the files located in the CMake module directory are "
457 "preferred over the files in CMAKE_MODULE_PATH. "
458 "This makes sure that the modules belonging to "
459 "CMake always get those files included which they expect, and against "
460 "which they were developed and tested. "
461 "In all other cases, the files found in "
462 "CMAKE_MODULE_PATH still take precedence over the ones in "
463 "the CMake module directory. "
464 "The OLD behaviour is to always prefer files from CMAKE_MODULE_PATH over "
465 "files from the CMake modules directory.",
466 2,8,4,0, cmPolicies::WARN);
470 "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.",
471 "CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries "
472 "using the value of the undocumented CMAKE_SHARED_LIBRARY_<Lang>_FLAGS "
473 "platform variable. The variable contained platform-specific flags "
474 "needed to compile objects for shared libraries. Typically it included "
475 "a flag such as -fPIC for position independent code but also included "
476 "other flags needed on certain platforms. CMake 2.8.9 and higher "
477 "prefer instead to use the POSITION_INDEPENDENT_CODE target property to "
478 "determine what targets should be position independent, and new "
479 "undocumented platform variables to select flags while ignoring "
480 "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS completely."
482 "The default for either approach produces identical compilation flags, "
483 "but if a project modifies CMAKE_SHARED_LIBRARY_<Lang>_FLAGS from its "
484 "original value this policy determines which approach to use."
486 "The OLD behavior for this policy is to ignore the "
487 "POSITION_INDEPENDENT_CODE property for all targets and use the modified "
488 "value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS for SHARED and MODULE "
491 "The NEW behavior for this policy is to ignore "
492 "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS whether it is modified or not and "
493 "honor the POSITION_INDEPENDENT_CODE target property.",
494 2,8,9,0, cmPolicies::WARN);
498 "Do not re-expand variables in include and link information.",
499 "CMake 2.8.10 and lower re-evaluated values given to the "
500 "include_directories, link_directories, and link_libraries "
501 "commands to expand any leftover variable references at the "
502 "end of the configuration step. "
503 "This was for strict compatibility with VERY early CMake versions "
504 "because all variable references are now normally evaluated during "
505 "CMake language processing. "
506 "CMake 2.8.11 and higher prefer to skip the extra evaluation."
508 "The OLD behavior for this policy is to re-evaluate the values "
509 "for strict compatibility. "
510 "The NEW behavior for this policy is to leave the values untouched.",
511 2,8,11,0, cmPolicies::WARN);
515 "Automatically link Qt executables to qtmain target on Windows.",
516 "CMake 2.8.10 and lower required users of Qt to always specify a link "
517 "dependency to the qtmain.lib static library manually on Windows. CMake "
518 "2.8.11 gained the ability to evaluate generator expressions while "
519 "determining the link dependencies from IMPORTED targets. This allows "
520 "CMake itself to automatically link executables which link to Qt to the "
521 "qtmain.lib library when using IMPORTED Qt targets. For applications "
522 "already linking to qtmain.lib, this should have little impact. For "
523 "applications which supply their own alternative WinMain implementation "
524 "and for applications which use the QAxServer library, this automatic "
525 "linking will need to be disabled as per the documentation."
527 "The OLD behavior for this policy is not to link executables to "
528 "qtmain.lib automatically when they link to the QtCore IMPORTED"
530 "The NEW behavior for this policy is to link executables to "
531 "qtmain.lib automatically when they link to QtCore IMPORTED target.",
532 2,8,11,0, cmPolicies::WARN);
536 "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.",
537 "CMake 2.8.10.2 and lower allowed the INCLUDE_DIRECTORIES target "
538 "property to contain relative paths. The base path for such relative "
539 "entries is not well defined. CMake 2.8.12 issues a FATAL_ERROR if the "
540 "INCLUDE_DIRECTORIES property contains a relative path."
542 "The OLD behavior for this policy is not to warn about relative paths in "
543 "the INCLUDE_DIRECTORIES target property. "
544 "The NEW behavior for this policy is to issue a FATAL_ERROR if "
545 "INCLUDE_DIRECTORIES contains a relative path.",
546 2,8,12,0, cmPolicies::WARN);
550 "INTERFACE_LINK_LIBRARIES defines the link interface.",
551 "CMake 2.8.11 constructed the 'link interface' of a target from "
552 "properties matching (IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?. "
553 "The modern way to specify config-sensitive content is to use generator "
554 "expressions and the IMPORTED_ prefix makes uniform processing of the "
555 "link interface with generator expressions impossible. The "
556 "INTERFACE_LINK_LIBRARIES target property was introduced as a "
557 "replacement in CMake 2.8.12. This new property is named consistently "
558 "with the INTERFACE_COMPILE_DEFINITIONS, INTERFACE_INCLUDE_DIRECTORIES "
559 "and INTERFACE_COMPILE_OPTIONS properties. For in-build targets, CMake "
560 "will use the INTERFACE_LINK_LIBRARIES property as the source of the "
561 "link interface only if policy CMP0022 is NEW. "
562 "When exporting a target which has this policy set to NEW, only the "
563 "INTERFACE_LINK_LIBRARIES property will be processed and generated for "
564 "the IMPORTED target by default. A new option to the install(EXPORT) "
565 "and export commands allows export of the old-style properties for "
566 "compatibility with downstream users of CMake versions older than "
568 "The target_link_libraries command will no longer populate the "
569 "properties matching LINK_INTERFACE_LIBRARIES(_<CONFIG>)? if this policy "
572 "The OLD behavior for this policy is to ignore the "
573 "INTERFACE_LINK_LIBRARIES property for in-build targets. "
574 "The NEW behavior for this policy is to use the INTERFACE_LINK_LIBRARIES "
575 "property for in-build targets, and ignore the old properties matching "
576 "(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?.",
577 2,8,12,0, cmPolicies::WARN);
581 "Plain and keyword target_link_libraries signatures cannot be mixed.",
582 "CMake 2.8.12 introduced the target_link_libraries signature using "
583 "the PUBLIC, PRIVATE, and INTERFACE keywords to generalize the "
584 "LINK_PUBLIC and LINK_PRIVATE keywords introduced in CMake 2.8.7. "
585 "Use of signatures with any of these keywords sets the link interface "
586 "of a target explicitly, even if empty. "
587 "This produces confusing behavior when used in combination with the "
588 "historical behavior of the plain target_link_libraries signature. "
589 "For example, consider the code:\n"
590 " target_link_libraries(mylib A)\n"
591 " target_link_libraries(mylib PRIVATE B)\n"
592 "After the first line the link interface has not been set explicitly "
593 "so CMake would use the link implementation, A, as the link interface. "
594 "However, the second line sets the link interface to empty. "
595 "In order to avoid this subtle behavior CMake now prefers to disallow "
596 "mixing the plain and keyword signatures of target_link_libraries for "
599 "The OLD behavior for this policy is to allow keyword and plain "
600 "target_link_libraries signatures to be mixed. "
601 "The NEW behavior for this policy is to not to allow mixing of the "
602 "keyword and plain signatures.",
603 2,8,12,0, cmPolicies::WARN);
606 cmPolicies::~cmPolicies()
609 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
610 = this->Policies.begin();
611 for (;i != this->Policies.end(); ++i)
617 void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
618 const char *idString,
619 const char *shortDescription,
620 const char *longDescription,
621 unsigned int majorVersionIntroduced,
622 unsigned int minorVersionIntroduced,
623 unsigned int patchVersionIntroduced,
624 unsigned int tweakVersionIntroduced,
625 cmPolicies::PolicyStatus status)
627 // a policy must be unique and can only be defined once
628 if (this->Policies.find(iD) != this->Policies.end())
630 cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
631 "ID ", this->GetPolicyIDString(iD).c_str());
635 this->Policies[iD] = new cmPolicy(iD, idString,
638 majorVersionIntroduced,
639 minorVersionIntroduced,
640 patchVersionIntroduced,
641 tweakVersionIntroduced,
643 this->PolicyStringMap[idString] = iD;
646 //----------------------------------------------------------------------------
647 bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
650 std::string ver = "2.4.0";
652 if (version && strlen(version) > 0)
657 unsigned int majorVer = 2;
658 unsigned int minorVer = 0;
659 unsigned int patchVer = 0;
660 unsigned int tweakVer = 0;
663 if(sscanf(ver.c_str(), "%u.%u.%u.%u",
664 &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
667 e << "Invalid policy version value \"" << ver << "\". "
668 << "A numeric major.minor[.patch[.tweak]] must be given.";
669 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
673 // it is an error if the policy version is less than 2.4
674 if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
676 mf->IssueMessage(cmake::FATAL_ERROR,
677 "An attempt was made to set the policy version of CMake to something "
678 "earlier than \"2.4\". "
679 "In CMake 2.4 and below backwards compatibility was handled with the "
680 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
681 "In order to get compatibility features supporting versions earlier "
682 "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
683 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
684 "One way to do this is to set the policy version to 2.4 exactly."
689 // It is an error if the policy version is greater than the running
691 if (majorVer > cmVersion::GetMajorVersion() ||
692 (majorVer == cmVersion::GetMajorVersion() &&
693 minorVer > cmVersion::GetMinorVersion()) ||
694 (majorVer == cmVersion::GetMajorVersion() &&
695 minorVer == cmVersion::GetMinorVersion() &&
696 patchVer > cmVersion::GetPatchVersion()) ||
697 (majorVer == cmVersion::GetMajorVersion() &&
698 minorVer == cmVersion::GetMinorVersion() &&
699 patchVer == cmVersion::GetPatchVersion() &&
700 tweakVer > cmVersion::GetTweakVersion()))
703 e << "An attempt was made to set the policy version of CMake to \""
704 << version << "\" which is greater than this version of CMake. "
705 << "This is not allowed because the greater version may have new "
706 << "policies not known to this CMake. "
707 << "You may need a newer CMake version to build this project.";
708 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
712 // now loop over all the policies and set them as appropriate
713 std::vector<cmPolicies::PolicyID> ancientPolicies;
714 for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
715 = this->Policies.begin(); i != this->Policies.end(); ++i)
717 if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
719 if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
721 ancientPolicies.push_back(i->first);
725 cmPolicies::PolicyStatus status = cmPolicies::WARN;
726 if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
727 !mf->SetPolicy(i->second->ID, status))
735 if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
742 // Make sure the project does not use any ancient policies.
743 if(!ancientPolicies.empty())
745 this->DiagnoseAncientPolicies(ancientPolicies,
746 majorVer, minorVer, patchVer, mf);
747 cmSystemTools::SetFatalErrorOccured();
754 //----------------------------------------------------------------------------
755 bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
756 cmPolicies::PolicyStatus* defaultSetting)
758 std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
759 std::string defaultValue = mf->GetSafeDefinition(defaultVar.c_str());
760 if(defaultValue == "NEW")
762 *defaultSetting = cmPolicies::NEW;
764 else if(defaultValue == "OLD")
766 *defaultSetting = cmPolicies::OLD;
768 else if(defaultValue == "")
770 *defaultSetting = cmPolicies::WARN;
775 e << defaultVar << " has value \"" << defaultValue
776 << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
777 mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
784 bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
786 if (!id || strlen(id) < 1)
790 std::map<std::string,cmPolicies::PolicyID>::iterator pos =
791 this->PolicyStringMap.find(id);
792 if (pos == this->PolicyStringMap.end())
800 std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
802 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
803 this->Policies.find(pid);
804 if (pos == this->Policies.end())
808 return pos->second->IDString;
812 ///! return a warning string for a given policy
813 std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
815 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
816 this->Policies.find(id);
817 if (pos == this->Policies.end())
819 cmSystemTools::Error(
820 "Request for warning text for undefined policy!");
821 return "Request for warning text for undefined policy!";
826 "Policy " << pos->second->IDString << " is not set: "
827 "" << pos->second->ShortDescription << " "
828 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
830 "Use the cmake_policy command to set the policy "
831 "and suppress this warning.";
836 ///! return an error string for when a required policy is unspecified
837 std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
839 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
840 this->Policies.find(id);
841 if (pos == this->Policies.end())
843 cmSystemTools::Error(
844 "Request for error text for undefined policy!");
845 return "Request for error text for undefined policy!";
848 cmOStringStream error;
850 "Policy " << pos->second->IDString << " is not set to NEW: "
851 "" << pos->second->ShortDescription << " "
852 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
854 "CMake now requires this policy to be set to NEW by the project. "
855 "The policy may be set explicitly using the code\n"
856 " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
857 "or by upgrading all policies with the code\n"
858 " cmake_policy(VERSION " << pos->second->GetVersionString() <<
860 "Run \"cmake --help-command cmake_policy\" for more information.";
864 ///! Get the default status for a policy
865 cmPolicies::PolicyStatus
866 cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
868 // if the policy is not know then what?
869 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
870 this->Policies.find(id);
871 if (pos == this->Policies.end())
873 // TODO is this right?
874 return cmPolicies::WARN;
877 return pos->second->Status;
880 void cmPolicies::GetDocumentation(std::vector<cmDocumentationEntry>& v)
882 // now loop over all the policies and set them as appropriate
883 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
884 = this->Policies.begin();
885 for (;i != this->Policies.end(); ++i)
887 cmOStringStream full;
888 full << i->second->LongDescription;
889 full << "\nThis policy was introduced in CMake version ";
890 full << i->second->GetVersionString() << ".";
891 if(i->first != cmPolicies::CMP0000)
894 << "CMake version " << cmVersion::GetCMakeVersion() << " ";
895 // add in some more text here based on status
896 switch (i->second->Status)
898 case cmPolicies::WARN:
899 full << "warns when the policy is not set and uses OLD behavior. "
900 << "Use the cmake_policy command to set it to OLD or NEW "
903 case cmPolicies::OLD:
904 full << "defaults to the OLD behavior for this policy.";
906 case cmPolicies::NEW:
907 full << "defaults to the NEW behavior for this policy.";
909 case cmPolicies::REQUIRED_IF_USED:
910 full << "requires the policy to be set to NEW if you use it. "
911 << "Use the cmake_policy command to set it to NEW.";
913 case cmPolicies::REQUIRED_ALWAYS:
914 full << "requires the policy to be set to NEW. "
915 << "Use the cmake_policy command to set it to NEW.";
919 cmDocumentationEntry e(i->second->IDString.c_str(),
920 i->second->ShortDescription.c_str(),
926 //----------------------------------------------------------------------------
928 cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
930 std::string pid = this->GetPolicyIDString(id);
932 e << "Policy " << pid << " may not be set to OLD behavior because this "
933 << "version of CMake no longer supports it. "
934 << "The policy was introduced in "
935 << "CMake version " << this->Policies[id]->GetVersionString()
936 << ", and use of NEW behavior is now required."
938 << "Please either update your CMakeLists.txt files to conform to "
939 << "the new behavior or use an older version of CMake that still "
940 << "supports the old behavior. "
941 << "Run cmake --help-policy " << pid << " for more information.";
945 //----------------------------------------------------------------------------
947 cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
948 unsigned int majorVer,
949 unsigned int minorVer,
950 unsigned int patchVer,
954 e << "The project requests behavior compatible with CMake version \""
955 << majorVer << "." << minorVer << "." << patchVer
956 << "\", which requires the OLD behavior for some policies:\n";
957 for(std::vector<PolicyID>::const_iterator
958 i = ancient.begin(); i != ancient.end(); ++i)
960 cmPolicy const* policy = this->Policies[*i];
961 e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
963 e << "However, this version of CMake no longer supports the OLD "
964 << "behavior for these policies. "
965 << "Please either update your CMakeLists.txt files to conform to "
966 << "the new behavior or use an older version of CMake that still "
967 << "supports the old behavior.";
968 mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());