Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmPolicies.cxx
blob211f351a97d63cde7ff1e35c57a4de2c3524ccf5
1 #include "cmPolicies.h"
2 #include "cmake.h"
3 #include "cmMakefile.h"
4 #include "cmSourceFile.h"
5 #include "cmVersion.h"
6 #include <map>
7 #include <set>
8 #include <queue>
9 #include <assert.h>
11 const char* cmPolicies::PolicyStatusNames[] = {
12 "OLD", "WARN", "NEW", "REQUIRED_IF_USED", "REQUIRED_ALWAYS"
15 class cmPolicy
17 public:
18 cmPolicy(cmPolicies::PolicyID iD,
19 const char *idString,
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!");
31 return;
33 this->ID = iD;
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;
49 return error.str();
52 bool IsPolicyNewerThan(unsigned int majorV,
53 unsigned int minorV,
54 unsigned int patchV)
56 if (majorV < this->MajorVersionIntroduced)
58 return true;
60 if (majorV > this->MajorVersionIntroduced)
62 return false;
64 if (minorV < this->MinorVersionIntroduced)
66 return true;
68 if (minorV > this->MinorVersionIntroduced)
70 return false;
72 return (patchV < this->PatchVersionIntroduced);
75 cmPolicies::PolicyID ID;
76 std::string IDString;
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
88 this->DefinePolicy(
89 CMP0000, "CMP0000",
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
116 this->DefinePolicy(
117 CMP0001, "CMP0001",
118 "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
119 "The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present "
120 "it to the user. "
121 "The NEW behavior is to ignore CMAKE_BACKWARDS_COMPATIBILITY "
122 "completely.\n"
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
132 this->DefinePolicy(
133 CMP0002, "CMP0002",
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 "
147 "names distinct. "
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
154 this->DefinePolicy(
155 CMP0003, "CMP0003",
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."
184 "\n"
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."
195 "\n"
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);
218 this->DefinePolicy(
219 CMP0004, "CMP0004",
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);
234 this->DefinePolicy(
235 CMP0005, "CMP0005",
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);
255 this->DefinePolicy(
256 CMP0006, "CMP0006",
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);
273 this->DefinePolicy(
274 CMP0007, "CMP0007",
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);
285 this->DefinePolicy(
286 CMP0008, "CMP0008",
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."
302 "\n"
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);
311 this->DefinePolicy(
312 CMP0009, "CMP0009",
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."
318 "\n"
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);
327 this->DefinePolicy(
328 CMP0010, "CMP0010",
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);
339 this->DefinePolicy(
340 CMP0011, "CMP0011",
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, "
347 "most do not. "
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 "
352 "compatibility. "
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);
359 this->DefinePolicy(
360 CMP0012, "CMP0012",
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 "
371 "boolean constant.",
372 2,6,5, cmPolicies::WARN);
374 this->DefinePolicy(
375 CMP0013, "CMP0013",
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 "
386 "directories. "
387 "The NEW behavior for this policy is to disallow duplicate binary "
388 "directories with an error.",
389 2,6,5, cmPolicies::WARN);
392 cmPolicies::~cmPolicies()
394 // free the policies
395 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
396 = this->Policies.begin();
397 for (;i != this->Policies.end(); ++i)
399 delete i->second;
403 void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
404 const char *idString,
405 const char *shortDescription,
406 const char *longDescription,
407 unsigned int majorVersionIntroduced,
408 unsigned int minorVersionIntroduced,
409 unsigned int patchVersionIntroduced,
410 cmPolicies::PolicyStatus status)
412 // a policy must be unique and can only be defined once
413 if (this->Policies.find(iD) != this->Policies.end())
415 cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
416 "ID ", this->GetPolicyIDString(iD).c_str());
417 return;
420 this->Policies[iD] = new cmPolicy(iD, idString,
421 shortDescription,
422 longDescription,
423 majorVersionIntroduced,
424 minorVersionIntroduced,
425 patchVersionIntroduced,
426 status);
427 this->PolicyStringMap[idString] = iD;
430 //----------------------------------------------------------------------------
431 bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
432 const char *version)
434 std::string ver = "2.4.0";
436 if (version && strlen(version) > 0)
438 ver = version;
441 unsigned int majorVer = 2;
442 unsigned int minorVer = 0;
443 unsigned int patchVer = 0;
445 // parse the string
446 if(sscanf(ver.c_str(), "%u.%u.%u",
447 &majorVer, &minorVer, &patchVer) < 2)
449 cmOStringStream e;
450 e << "Invalid policy version value \"" << ver << "\". "
451 << "A numeric major.minor[.patch] must be given.";
452 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
453 return false;
456 // it is an error if the policy version is less than 2.4
457 if (majorVer < 2 || majorVer == 2 && minorVer < 4)
459 mf->IssueMessage(cmake::FATAL_ERROR,
460 "An attempt was made to set the policy version of CMake to something "
461 "earlier than \"2.4\". "
462 "In CMake 2.4 and below backwards compatibility was handled with the "
463 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
464 "In order to get compatibility features supporting versions earlier "
465 "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
466 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
467 "One way to do this is to set the policy version to 2.4 exactly."
469 return false;
472 // It is an error if the policy version is greater than the running
473 // CMake.
474 if (majorVer > cmVersion::GetMajorVersion() ||
475 (majorVer == cmVersion::GetMajorVersion() &&
476 minorVer > cmVersion::GetMinorVersion()) ||
477 (majorVer == cmVersion::GetMajorVersion() &&
478 minorVer == cmVersion::GetMinorVersion() &&
479 patchVer > cmVersion::GetPatchVersion()))
481 cmOStringStream e;
482 e << "An attempt was made to set the policy version of CMake to \""
483 << version << "\" which is greater than this version of CMake. "
484 << "This is not allowed because the greater version may have new "
485 << "policies not known to this CMake. "
486 << "You may need a newer CMake version to build this project.";
487 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
488 return false;
491 // now loop over all the policies and set them as appropriate
492 std::vector<cmPolicies::PolicyID> ancientPolicies;
493 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
494 = this->Policies.begin();
495 for (;i != this->Policies.end(); ++i)
497 if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
499 if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
501 ancientPolicies.push_back(i->first);
503 else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
505 return false;
508 else
510 if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
512 return false;
517 // Make sure the project does not use any ancient policies.
518 if(!ancientPolicies.empty())
520 this->DiagnoseAncientPolicies(ancientPolicies,
521 majorVer, minorVer, patchVer, mf);
522 cmSystemTools::SetFatalErrorOccured();
523 return false;
526 return true;
529 bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
531 if (!id || strlen(id) < 1)
533 return false;
535 std::map<std::string,cmPolicies::PolicyID>::iterator pos =
536 this->PolicyStringMap.find(id);
537 if (pos == this->PolicyStringMap.end())
539 return false;
541 pid = pos->second;
542 return true;
545 std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
547 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
548 this->Policies.find(pid);
549 if (pos == this->Policies.end())
551 return "";
553 return pos->second->IDString;
557 ///! return a warning string for a given policy
558 std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
560 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
561 this->Policies.find(id);
562 if (pos == this->Policies.end())
564 cmSystemTools::Error(
565 "Request for warning text for undefined policy!");
566 return "Request for warning text for undefined policy!";
569 cmOStringStream msg;
570 msg <<
571 "Policy " << pos->second->IDString << " is not set: "
572 "" << pos->second->ShortDescription << " "
573 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
574 "policy details. "
575 "Use the cmake_policy command to set the policy "
576 "and suppress this warning.";
577 return msg.str();
581 ///! return an error string for when a required policy is unspecified
582 std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
584 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
585 this->Policies.find(id);
586 if (pos == this->Policies.end())
588 cmSystemTools::Error(
589 "Request for error text for undefined policy!");
590 return "Request for warning text for undefined policy!";
593 cmOStringStream error;
594 error <<
595 "Policy " << pos->second->IDString << " is not set to NEW: "
596 "" << pos->second->ShortDescription << " "
597 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
598 "policy details. "
599 "CMake now requires this policy to be set to NEW by the project. "
600 "The policy may be set explicitly using the code\n"
601 " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
602 "or by upgrading all policies with the code\n"
603 " cmake_policy(VERSION " << pos->second->GetVersionString() <<
604 ") # or later\n"
605 "Run \"cmake --help-command cmake_policy\" for more information.";
606 return error.str();
609 ///! Get the default status for a policy
610 cmPolicies::PolicyStatus
611 cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
613 // if the policy is not know then what?
614 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
615 this->Policies.find(id);
616 if (pos == this->Policies.end())
618 // TODO is this right?
619 return cmPolicies::WARN;
622 return pos->second->Status;
625 void cmPolicies::GetDocumentation(std::vector<cmDocumentationEntry>& v)
627 // now loop over all the policies and set them as appropriate
628 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
629 = this->Policies.begin();
630 for (;i != this->Policies.end(); ++i)
632 cmOStringStream full;
633 full << i->second->LongDescription;
634 full << "\nThis policy was introduced in CMake version ";
635 full << i->second->GetVersionString() << ".";
636 if(i->first != cmPolicies::CMP0000)
638 full << " "
639 << "CMake version " << cmVersion::GetMajorVersion()
640 << "." << cmVersion::GetMinorVersion() << " ";
641 // add in some more text here based on status
642 switch (i->second->Status)
644 case cmPolicies::WARN:
645 full << "warns when the policy is not set and uses OLD behavior. "
646 << "Use the cmake_policy command to set it to OLD or NEW "
647 << "explicitly.";
648 break;
649 case cmPolicies::OLD:
650 full << "defaults to the OLD behavior for this policy.";
651 break;
652 case cmPolicies::NEW:
653 full << "defaults to the NEW behavior for this policy.";
654 break;
655 case cmPolicies::REQUIRED_IF_USED:
656 full << "requires the policy to be set to NEW if you use it. "
657 << "Use the cmake_policy command to set it to NEW.";
658 break;
659 case cmPolicies::REQUIRED_ALWAYS:
660 full << "requires the policy to be set to NEW. "
661 << "Use the cmake_policy command to set it to NEW.";
662 break;
665 cmDocumentationEntry e(i->second->IDString.c_str(),
666 i->second->ShortDescription.c_str(),
667 full.str().c_str());
668 v.push_back(e);
672 //----------------------------------------------------------------------------
673 std::string
674 cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
676 std::string pid = this->GetPolicyIDString(id);
677 cmOStringStream e;
678 e << "Policy " << pid << " may not be set to OLD behavior because this "
679 << "version of CMake no longer supports it. "
680 << "The policy was introduced in "
681 << "CMake version " << this->Policies[id]->GetVersionString()
682 << ", and use of NEW behavior is now required."
683 << "\n"
684 << "Please either update your CMakeLists.txt files to conform to "
685 << "the new behavior or use an older version of CMake that still "
686 << "supports the old behavior. "
687 << "Run cmake --help-policy " << pid << " for more information.";
688 return e.str();
691 //----------------------------------------------------------------------------
692 void
693 cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
694 unsigned int majorVer,
695 unsigned int minorVer,
696 unsigned int patchVer,
697 cmMakefile* mf)
699 cmOStringStream e;
700 e << "The project requests behavior compatible with CMake version \""
701 << majorVer << "." << minorVer << "." << patchVer
702 << "\", which requires OLD the behavior for some policies:\n";
703 for(std::vector<PolicyID>::const_iterator
704 i = ancient.begin(); i != ancient.end(); ++i)
706 cmPolicy const* policy = this->Policies[*i];
707 e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
709 e << "However, this version of CMake no longer supports the OLD "
710 << "behavior for these policies. "
711 << "Please either update your CMakeLists.txt files to conform to "
712 << "the new behavior or use an older version of CMake that still "
713 << "supports the old behavior.";
714 mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());