1 #include "cmPolicies.h"
3 #include "cmMakefile.h"
4 #include "cmSourceFile.h"
11 const char* cmPolicies::PolicyStatusNames
[] = {
12 "OLD", "WARN", "NEW", "REQUIRED_IF_USED", "REQUIRED_ALWAYS"
18 cmPolicy(cmPolicies::PolicyID iD
,
20 const char *shortDescription
,
21 const char *longDescription
,
22 unsigned int majorVersionIntroduced
,
23 unsigned int minorVersionIntroduced
,
24 unsigned int patchVersionIntroduced
,
25 cmPolicies::PolicyStatus status
)
27 if (!idString
|| !shortDescription
|| ! longDescription
)
29 cmSystemTools::Error("Attempt to define a policy without "
30 "all parameters being specified!");
34 this->IDString
= idString
;
35 this->ShortDescription
= shortDescription
;
36 this->LongDescription
= longDescription
;
37 this->MajorVersionIntroduced
= majorVersionIntroduced
;
38 this->MinorVersionIntroduced
= minorVersionIntroduced
;
39 this->PatchVersionIntroduced
= patchVersionIntroduced
;
40 this->Status
= status
;
43 std::string
GetVersionString()
45 cmOStringStream error
;
46 error
<< this->MajorVersionIntroduced
<< "." <<
47 this->MinorVersionIntroduced
<< "." <<
48 this->PatchVersionIntroduced
;
52 bool IsPolicyNewerThan(unsigned int majorV
,
56 if (majorV
< this->MajorVersionIntroduced
)
60 if (majorV
> this->MajorVersionIntroduced
)
64 if (minorV
< this->MinorVersionIntroduced
)
68 if (minorV
> this->MinorVersionIntroduced
)
72 return (patchV
< this->PatchVersionIntroduced
);
75 cmPolicies::PolicyID ID
;
77 std::string ShortDescription
;
78 std::string LongDescription
;
79 unsigned int MajorVersionIntroduced
;
80 unsigned int MinorVersionIntroduced
;
81 unsigned int PatchVersionIntroduced
;
82 cmPolicies::PolicyStatus Status
;
85 cmPolicies::cmPolicies()
87 // define all the policies
90 "A minimum required CMake version must be specified.",
91 "CMake requires that projects specify the version of CMake to which "
92 "they have been written. "
93 "This policy has been put in place so users trying to build the project "
94 "may be told when they need to update their CMake. "
95 "Specifying a version also helps the project build with CMake versions "
96 "newer than that specified. "
97 "Use the cmake_minimum_required command at the top of your main "
98 " CMakeLists.txt file:\n"
99 " cmake_minimum_required(VERSION <major>.<minor>)\n"
100 "where \"<major>.<minor>\" is the version of CMake you want to support "
101 "(such as \"2.6\"). "
102 "The command will ensure that at least the given version of CMake is "
103 "running and help newer versions be compatible with the project. "
104 "See documentation of cmake_minimum_required for details.\n"
105 "Note that the command invocation must appear in the CMakeLists.txt "
106 "file itself; a call in an included file is not sufficient. "
107 "However, the cmake_policy command may be called to set policy "
108 "CMP0000 to OLD or NEW behavior explicitly. "
109 "The OLD behavior is to silently ignore the missing invocation. "
110 "The NEW behavior is to issue an error instead of a warning. "
111 "An included file may set CMP0000 explicitly to affect how this "
112 "policy is enforced for the main CMakeLists.txt file.",
113 2,6,0, cmPolicies::WARN
118 "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
119 "The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present "
121 "The NEW behavior is to ignore CMAKE_BACKWARDS_COMPATIBILITY "
123 "In CMake 2.4 and below the variable CMAKE_BACKWARDS_COMPATIBILITY was "
124 "used to request compatibility with earlier versions of CMake. "
125 "In CMake 2.6 and above all compatibility issues are handled by policies "
126 "and the cmake_policy command. "
127 "However, CMake must still check CMAKE_BACKWARDS_COMPATIBILITY for "
128 "projects written for CMake 2.4 and below.",
129 2,6,0, cmPolicies::WARN
134 "Logical target names must be globally unique.",
135 "Targets names created with "
136 "add_executable, add_library, or add_custom_target "
137 "are logical build target names. "
138 "Logical target names must be globally unique because:\n"
139 " - Unique names may be referenced unambiguously both in CMake\n"
140 " code and on make tool command lines.\n"
141 " - Logical names are used by Xcode and VS IDE generators\n"
142 " to produce meaningful project names for the targets.\n"
143 "The logical name of executable and library targets does not "
144 "have to correspond to the physical file names built. "
145 "Consider using the OUTPUT_NAME target property to create two "
146 "targets with the same physical name while keeping logical "
148 "Custom targets must simply have globally unique names (unless one "
149 "uses the global property ALLOW_DUPLICATE_CUSTOM_TARGETS with a "
150 "Makefiles generator).",
151 2,6,0, cmPolicies::WARN
156 "Libraries linked via full path no longer produce linker search paths.",
157 "This policy affects how libraries whose full paths are NOT known "
158 "are found at link time, but was created due to a change in how CMake "
159 "deals with libraries whose full paths are known. "
160 "Consider the code\n"
161 " target_link_libraries(myexe /path/to/libA.so)\n"
162 "CMake 2.4 and below implemented linking to libraries whose full paths "
163 "are known by splitting them on the link line into separate components "
164 "consisting of the linker search path and the library name. "
165 "The example code might have produced something like\n"
166 " ... -L/path/to -lA ...\n"
167 "in order to link to library A. "
168 "An analysis was performed to order multiple link directories such that "
169 "the linker would find library A in the desired location, but there "
170 "are cases in which this does not work. "
171 "CMake versions 2.6 and above use the more reliable approach of passing "
172 "the full path to libraries directly to the linker in most cases. "
173 "The example code now produces something like\n"
174 " ... /path/to/libA.so ....\n"
175 "Unfortunately this change can break code like\n"
176 " target_link_libraries(myexe /path/to/libA.so B)\n"
177 "where \"B\" is meant to find \"/path/to/libB.so\". "
178 "This code is wrong because the user is asking the linker to find "
179 "library B but has not provided a linker search path (which may be "
180 "added with the link_directories command). "
181 "However, with the old linking implementation the code would work "
182 "accidentally because the linker search path added for library A "
183 "allowed library B to be found."
185 "In order to support projects depending on linker search paths "
186 "added by linking to libraries with known full paths, the OLD "
187 "behavior for this policy will add the linker search paths even "
188 "though they are not needed for their own libraries. "
189 "When this policy is set to OLD, CMake will produce a link line such as\n"
190 " ... -L/path/to /path/to/libA.so -lB ...\n"
191 "which will allow library B to be found as it was previously. "
192 "When this policy is set to NEW, CMake will produce a link line such as\n"
193 " ... /path/to/libA.so -lB ...\n"
194 "which more accurately matches what the project specified."
196 "The setting for this policy used when generating the link line is that "
197 "in effect when the target is created by an add_executable or "
198 "add_library command. For the example described above, the code\n"
199 " cmake_policy(SET CMP0003 OLD) # or cmake_policy(VERSION 2.4)\n"
200 " add_executable(myexe myexe.c)\n"
201 " target_link_libraries(myexe /path/to/libA.so B)\n"
202 "will work and suppress the warning for this policy. "
203 "It may also be updated to work with the corrected linking approach:\n"
204 " cmake_policy(SET CMP0003 NEW) # or cmake_policy(VERSION 2.6)\n"
205 " link_directories(/path/to) # needed to find library B\n"
206 " add_executable(myexe myexe.c)\n"
207 " target_link_libraries(myexe /path/to/libA.so B)\n"
208 "Even better, library B may be specified with a full path:\n"
209 " add_executable(myexe myexe.c)\n"
210 " target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)\n"
211 "When all items on the link line have known paths CMake does not check "
212 "this policy so it has no effect.\n"
213 "Note that the warning for this policy will be issued for at most "
214 "one target. This avoids flooding users with messages for every "
215 "target when setting the policy once will probably fix all targets.",
216 2,6,0, cmPolicies::WARN
);
220 "Libraries linked may not have leading or trailing whitespace.",
221 "CMake versions 2.4 and below silently removed leading and trailing "
222 "whitespace from libraries linked with code like\n"
223 " target_link_libraries(myexe \" A \")\n"
224 "This could lead to subtle errors in user projects.\n"
225 "The OLD behavior for this policy is to silently remove leading and "
226 "trailing whitespace. "
227 "The NEW behavior for this policy is to diagnose the existence of "
228 "such whitespace as an error. "
229 "The setting for this policy used when checking the library names is "
230 "that in effect when the target is created by an add_executable or "
231 "add_library command.",
232 2,6,0, cmPolicies::WARN
);
236 "Preprocessor definition values are now escaped automatically.",
237 "This policy determines whether or not CMake should generate escaped "
238 "preprocessor definition values added via add_definitions. "
239 "CMake versions 2.4 and below assumed that only trivial values would "
240 "be given for macros in add_definitions calls. "
241 "It did not attempt to escape non-trivial values such as string "
242 "literals in generated build rules. "
243 "CMake versions 2.6 and above support escaping of most values, but "
244 "cannot assume the user has not added escapes already in an attempt to "
245 "work around limitations in earlier versions.\n"
246 "The OLD behavior for this policy is to place definition values given "
247 "to add_definitions directly in the generated build rules without "
248 "attempting to escape anything. "
249 "The NEW behavior for this policy is to generate correct escapes "
250 "for all native build tools automatically. "
251 "See documentation of the COMPILE_DEFINITIONS target property for "
252 "limitations of the escaping implementation.",
253 2,6,0, cmPolicies::WARN
);
257 "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.",
258 "This policy determines whether the install(TARGETS) command must be "
259 "given a BUNDLE DESTINATION when asked to install a target with the "
260 "MACOSX_BUNDLE property set. "
261 "CMake 2.4 and below did not distinguish application bundles from "
262 "normal executables when installing targets. "
263 "CMake 2.6 provides a BUNDLE option to the install(TARGETS) command "
264 "that specifies rules specific to application bundles on the Mac. "
265 "Projects should use this option when installing a target with the "
266 "MACOSX_BUNDLE property set.\n"
267 "The OLD behavior for this policy is to fall back to the RUNTIME "
268 "DESTINATION if a BUNDLE DESTINATION is not given. "
269 "The NEW behavior for this policy is to produce an error if a bundle "
270 "target is installed without a BUNDLE DESTINATION.",
271 2,6,0, cmPolicies::WARN
);
275 "list command no longer ignores empty elements.",
276 "This policy determines whether the list command will "
277 "ignore empty elements in the list. "
278 "CMake 2.4 and below list commands ignored all empty elements"
279 " in the list. For example, a;b;;c would have length 3 and not 4. "
280 "The OLD behavior for this policy is to ignore empty list elements. "
281 "The NEW behavior for this policy is to correctly count empty "
282 "elements in a list. ",
283 2,6,0, cmPolicies::WARN
);
287 "Libraries linked by full-path must have a valid library file name.",
288 "In CMake 2.4 and below it is possible to write code like\n"
289 " target_link_libraries(myexe /full/path/to/somelib)\n"
290 "where \"somelib\" is supposed to be a valid library file name "
291 "such as \"libsomelib.a\" or \"somelib.lib\". "
292 "For Makefile generators this produces an error at build time "
293 "because the dependency on the full path cannot be found. "
294 "For VS IDE and Xcode generators this used to work by accident because "
295 "CMake would always split off the library directory and ask the "
296 "linker to search for the library by name (-lsomelib or somelib.lib). "
297 "Despite the failure with Makefiles, some projects have code like this "
298 "and build only with VS and/or Xcode. "
299 "This version of CMake prefers to pass the full path directly to the "
300 "native build tool, which will fail in this case because it does "
301 "not name a valid library file."
303 "This policy determines what to do with full paths that do not appear "
304 "to name a valid library file. "
305 "The OLD behavior for this policy is to split the library name from the "
306 "path and ask the linker to search for it. "
307 "The NEW behavior for this policy is to trust the given path and "
308 "pass it directly to the native build tool unchanged.",
309 2,6,1, cmPolicies::WARN
);
313 "FILE GLOB_RECURSE calls should not follow symlinks by default.",
314 "In CMake 2.6.1 and below, FILE GLOB_RECURSE calls would follow "
315 "through symlinks, sometimes coming up with unexpectedly large "
316 "result sets because of symlinks to top level directories that "
317 "contain hundreds of thousands of files."
319 "This policy determines whether or not to follow symlinks "
320 "encountered during a FILE GLOB_RECURSE call. "
321 "The OLD behavior for this policy is to follow the symlinks. "
322 "The NEW behavior for this policy is not to follow the symlinks "
323 "by default, but only if FOLLOW_SYMLINKS is given as an additional "
324 "argument to the FILE command.",
325 2,6,2, cmPolicies::WARN
);
329 "Bad variable reference syntax is an error.",
330 "In CMake 2.6.2 and below, incorrect variable reference syntax such as "
331 "a missing close-brace (\"${FOO\") was reported but did not stop "
332 "processing of CMake code. "
333 "This policy determines whether a bad variable reference is an error. "
334 "The OLD behavior for this policy is to warn about the error, leave "
335 "the string untouched, and continue. "
336 "The NEW behavior for this policy is to report an error.",
337 2,6,3, cmPolicies::WARN
);
341 "Included scripts do automatic cmake_policy PUSH and POP.",
342 "In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by "
343 "the include() and find_package() commands would affect the includer. "
344 "Explicit invocations of cmake_policy(PUSH) and cmake_policy(POP) were "
345 "required to isolate policy changes and protect the includer. "
346 "While some scripts intend to affect the policies of their includer, "
348 "In CMake 2.6.3 and above, include() and find_package() by default PUSH "
349 "and POP an entry on the policy stack around an included script, "
350 "but provide a NO_POLICY_SCOPE option to disable it. "
351 "This policy determines whether or not to imply NO_POLICY_SCOPE for "
353 "The OLD behavior for this policy is to imply NO_POLICY_SCOPE for "
354 "include() and find_package() commands. "
355 "The NEW behavior for this policy is to allow the commands to do their "
356 "default cmake_policy PUSH and POP.",
357 2,6,3, cmPolicies::WARN
);
361 "The if() command can recognize named boolean constants.",
362 "In CMake versions prior to 2.6.5 the only boolean constants were 0 "
363 "and 1. Other boolean constants such as true, false, yes, no, "
364 "on, off, y, n, notfound, ignore (all case insensitive) were recognized "
365 "in some cases but not all. In later versions of cmake these values are "
366 "treated as boolean constants more consistently and should not be used "
367 "as variable names. "
368 "The OLD behavior for this policy is to allow variables to have names "
369 "such as true and to dereference them. "
370 "The NEW behavior for this policy is to treat strings like true as a "
372 2,6,5, cmPolicies::WARN
);
376 "Duplicate binary directories are not allowed.",
377 "CMake 2.6.3 and below silently permitted add_subdirectory() calls "
378 "to create the same binary directory multiple times. "
379 "During build system generation files would be written and then "
380 "overwritten in the build tree and could lead to strange behavior. "
381 "CMake 2.6.4 and above explicitly detect duplicate binary directories. "
382 "CMake 2.6.4 always considers this case an error. "
383 "In CMake 2.6.5 and above this policy determines whether or not "
384 "the case is an error. "
385 "The OLD behavior for this policy is to allow duplicate binary "
387 "The NEW behavior for this policy is to disallow duplicate binary "
388 "directories with an error.",
389 2,6,5, cmPolicies::WARN
);
393 "Input directories must have CMakeLists.txt.",
394 "CMake versions before 2.8 silently ignored missing CMakeLists.txt "
395 "files in directories referenced by add_subdirectory() or subdirs(), "
396 "treating them as if present but empty. "
397 "In CMake 2.8.0 and above this policy determines whether or not "
398 "the case is an error. "
399 "The OLD behavior for this policy is to silently ignore the problem. "
400 "The NEW behavior for this policy is to report an error.",
401 2,7,20090902, cmPolicies::WARN
);
405 "The set() CACHE mode and option() command make the cache value visible.",
406 "In CMake 2.6 and below the CACHE mode of the set() command and the "
407 "option() command did not expose the value from the named cache entry "
408 "if it was already set both in the cache and as a local variable. "
409 "This led to subtle differences between first and later configurations "
410 "because a conflicting local variable would be overridden only when the "
411 "cache value was first created. "
412 "For example, the code\n"
414 " set(before ${x})\n"
415 " set(x 2 CACHE STRING \"X\")\n"
417 " message(STATUS \"${before},${after}\")\n"
418 "would print \"1,2\" on the first run and \"1,1\" on future runs."
420 "CMake 2.8.0 and above prefer to expose the cache value in all cases by "
421 "removing the local variable definition, but this changes behavior in "
422 "subtle cases when the local variable has a different value than that "
423 "exposed from the cache. "
424 "The example above will always print \"1,2\"."
426 "This policy determines whether the commands should always expose the "
428 "The OLD behavior for this policy is to leave conflicting local "
429 "variable values untouched and hide the true cache value. "
430 "The NEW behavior for this policy is to always expose the cache value.",
431 2,7,20090910, cmPolicies::WARN
);
435 cmPolicies::~cmPolicies()
438 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator i
439 = this->Policies
.begin();
440 for (;i
!= this->Policies
.end(); ++i
)
446 void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD
,
447 const char *idString
,
448 const char *shortDescription
,
449 const char *longDescription
,
450 unsigned int majorVersionIntroduced
,
451 unsigned int minorVersionIntroduced
,
452 unsigned int patchVersionIntroduced
,
453 cmPolicies::PolicyStatus status
)
455 // a policy must be unique and can only be defined once
456 if (this->Policies
.find(iD
) != this->Policies
.end())
458 cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
459 "ID ", this->GetPolicyIDString(iD
).c_str());
463 this->Policies
[iD
] = new cmPolicy(iD
, idString
,
466 majorVersionIntroduced
,
467 minorVersionIntroduced
,
468 patchVersionIntroduced
,
470 this->PolicyStringMap
[idString
] = iD
;
473 //----------------------------------------------------------------------------
474 bool cmPolicies::ApplyPolicyVersion(cmMakefile
*mf
,
477 std::string ver
= "2.4.0";
479 if (version
&& strlen(version
) > 0)
484 unsigned int majorVer
= 2;
485 unsigned int minorVer
= 0;
486 unsigned int patchVer
= 0;
489 if(sscanf(ver
.c_str(), "%u.%u.%u",
490 &majorVer
, &minorVer
, &patchVer
) < 2)
493 e
<< "Invalid policy version value \"" << ver
<< "\". "
494 << "A numeric major.minor[.patch] must be given.";
495 mf
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
499 // it is an error if the policy version is less than 2.4
500 if (majorVer
< 2 || (majorVer
== 2 && minorVer
< 4))
502 mf
->IssueMessage(cmake::FATAL_ERROR
,
503 "An attempt was made to set the policy version of CMake to something "
504 "earlier than \"2.4\". "
505 "In CMake 2.4 and below backwards compatibility was handled with the "
506 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
507 "In order to get compatibility features supporting versions earlier "
508 "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
509 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
510 "One way to do this is to set the policy version to 2.4 exactly."
515 // It is an error if the policy version is greater than the running
517 if (majorVer
> cmVersion::GetMajorVersion() ||
518 (majorVer
== cmVersion::GetMajorVersion() &&
519 minorVer
> cmVersion::GetMinorVersion()) ||
520 (majorVer
== cmVersion::GetMajorVersion() &&
521 minorVer
== cmVersion::GetMinorVersion() &&
522 patchVer
> cmVersion::GetPatchVersion()))
525 e
<< "An attempt was made to set the policy version of CMake to \""
526 << version
<< "\" which is greater than this version of CMake. "
527 << "This is not allowed because the greater version may have new "
528 << "policies not known to this CMake. "
529 << "You may need a newer CMake version to build this project.";
530 mf
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
534 // now loop over all the policies and set them as appropriate
535 std::vector
<cmPolicies::PolicyID
> ancientPolicies
;
536 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator i
537 = this->Policies
.begin();
538 for (;i
!= this->Policies
.end(); ++i
)
540 if (i
->second
->IsPolicyNewerThan(majorVer
,minorVer
,patchVer
))
542 if(i
->second
->Status
== cmPolicies::REQUIRED_ALWAYS
)
544 ancientPolicies
.push_back(i
->first
);
546 else if (!mf
->SetPolicy(i
->second
->ID
, cmPolicies::WARN
))
553 if (!mf
->SetPolicy(i
->second
->ID
, cmPolicies::NEW
))
560 // Make sure the project does not use any ancient policies.
561 if(!ancientPolicies
.empty())
563 this->DiagnoseAncientPolicies(ancientPolicies
,
564 majorVer
, minorVer
, patchVer
, mf
);
565 cmSystemTools::SetFatalErrorOccured();
572 bool cmPolicies::GetPolicyID(const char *id
, cmPolicies::PolicyID
&pid
)
574 if (!id
|| strlen(id
) < 1)
578 std::map
<std::string
,cmPolicies::PolicyID
>::iterator pos
=
579 this->PolicyStringMap
.find(id
);
580 if (pos
== this->PolicyStringMap
.end())
588 std::string
cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid
)
590 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator pos
=
591 this->Policies
.find(pid
);
592 if (pos
== this->Policies
.end())
596 return pos
->second
->IDString
;
600 ///! return a warning string for a given policy
601 std::string
cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id
)
603 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator pos
=
604 this->Policies
.find(id
);
605 if (pos
== this->Policies
.end())
607 cmSystemTools::Error(
608 "Request for warning text for undefined policy!");
609 return "Request for warning text for undefined policy!";
614 "Policy " << pos
->second
->IDString
<< " is not set: "
615 "" << pos
->second
->ShortDescription
<< " "
616 "Run \"cmake --help-policy " << pos
->second
->IDString
<< "\" for "
618 "Use the cmake_policy command to set the policy "
619 "and suppress this warning.";
624 ///! return an error string for when a required policy is unspecified
625 std::string
cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id
)
627 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator pos
=
628 this->Policies
.find(id
);
629 if (pos
== this->Policies
.end())
631 cmSystemTools::Error(
632 "Request for error text for undefined policy!");
633 return "Request for warning text for undefined policy!";
636 cmOStringStream error
;
638 "Policy " << pos
->second
->IDString
<< " is not set to NEW: "
639 "" << pos
->second
->ShortDescription
<< " "
640 "Run \"cmake --help-policy " << pos
->second
->IDString
<< "\" for "
642 "CMake now requires this policy to be set to NEW by the project. "
643 "The policy may be set explicitly using the code\n"
644 " cmake_policy(SET " << pos
->second
->IDString
<< " NEW)\n"
645 "or by upgrading all policies with the code\n"
646 " cmake_policy(VERSION " << pos
->second
->GetVersionString() <<
648 "Run \"cmake --help-command cmake_policy\" for more information.";
652 ///! Get the default status for a policy
653 cmPolicies::PolicyStatus
654 cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id
)
656 // if the policy is not know then what?
657 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator pos
=
658 this->Policies
.find(id
);
659 if (pos
== this->Policies
.end())
661 // TODO is this right?
662 return cmPolicies::WARN
;
665 return pos
->second
->Status
;
668 void cmPolicies::GetDocumentation(std::vector
<cmDocumentationEntry
>& v
)
670 // now loop over all the policies and set them as appropriate
671 std::map
<cmPolicies::PolicyID
,cmPolicy
*>::iterator i
672 = this->Policies
.begin();
673 for (;i
!= this->Policies
.end(); ++i
)
675 cmOStringStream full
;
676 full
<< i
->second
->LongDescription
;
677 full
<< "\nThis policy was introduced in CMake version ";
678 full
<< i
->second
->GetVersionString() << ".";
679 if(i
->first
!= cmPolicies::CMP0000
)
682 << "CMake version " << cmVersion::GetMajorVersion()
683 << "." << cmVersion::GetMinorVersion() << " ";
684 // add in some more text here based on status
685 switch (i
->second
->Status
)
687 case cmPolicies::WARN
:
688 full
<< "warns when the policy is not set and uses OLD behavior. "
689 << "Use the cmake_policy command to set it to OLD or NEW "
692 case cmPolicies::OLD
:
693 full
<< "defaults to the OLD behavior for this policy.";
695 case cmPolicies::NEW
:
696 full
<< "defaults to the NEW behavior for this policy.";
698 case cmPolicies::REQUIRED_IF_USED
:
699 full
<< "requires the policy to be set to NEW if you use it. "
700 << "Use the cmake_policy command to set it to NEW.";
702 case cmPolicies::REQUIRED_ALWAYS
:
703 full
<< "requires the policy to be set to NEW. "
704 << "Use the cmake_policy command to set it to NEW.";
708 cmDocumentationEntry
e(i
->second
->IDString
.c_str(),
709 i
->second
->ShortDescription
.c_str(),
715 //----------------------------------------------------------------------------
717 cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id
)
719 std::string pid
= this->GetPolicyIDString(id
);
721 e
<< "Policy " << pid
<< " may not be set to OLD behavior because this "
722 << "version of CMake no longer supports it. "
723 << "The policy was introduced in "
724 << "CMake version " << this->Policies
[id
]->GetVersionString()
725 << ", and use of NEW behavior is now required."
727 << "Please either update your CMakeLists.txt files to conform to "
728 << "the new behavior or use an older version of CMake that still "
729 << "supports the old behavior. "
730 << "Run cmake --help-policy " << pid
<< " for more information.";
734 //----------------------------------------------------------------------------
736 cmPolicies::DiagnoseAncientPolicies(std::vector
<PolicyID
> const& ancient
,
737 unsigned int majorVer
,
738 unsigned int minorVer
,
739 unsigned int patchVer
,
743 e
<< "The project requests behavior compatible with CMake version \""
744 << majorVer
<< "." << minorVer
<< "." << patchVer
745 << "\", which requires the OLD behavior for some policies:\n";
746 for(std::vector
<PolicyID
>::const_iterator
747 i
= ancient
.begin(); i
!= ancient
.end(); ++i
)
749 cmPolicy
const* policy
= this->Policies
[*i
];
750 e
<< " " << policy
->IDString
<< ": " << policy
->ShortDescription
<< "\n";
752 e
<< "However, this version of CMake no longer supports the OLD "
753 << "behavior for these policies. "
754 << "Please either update your CMakeLists.txt files to conform to "
755 << "the new behavior or use an older version of CMake that still "
756 << "supports the old behavior.";
757 mf
->IssueMessage(cmake::FATAL_ERROR
, e
.str().c_str());