Fix memory and process leak in ctest_run_script.
[cmake.git] / Source / cmPolicies.cxx
blob576ccd7aa95532ab20f031072c4fbf45f787507b
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);
391 this->DefinePolicy(
392 CMP0014, "CMP0014",
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);
404 cmPolicies::~cmPolicies()
406 // free the policies
407 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
408 = this->Policies.begin();
409 for (;i != this->Policies.end(); ++i)
411 delete i->second;
415 void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
416 const char *idString,
417 const char *shortDescription,
418 const char *longDescription,
419 unsigned int majorVersionIntroduced,
420 unsigned int minorVersionIntroduced,
421 unsigned int patchVersionIntroduced,
422 cmPolicies::PolicyStatus status)
424 // a policy must be unique and can only be defined once
425 if (this->Policies.find(iD) != this->Policies.end())
427 cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
428 "ID ", this->GetPolicyIDString(iD).c_str());
429 return;
432 this->Policies[iD] = new cmPolicy(iD, idString,
433 shortDescription,
434 longDescription,
435 majorVersionIntroduced,
436 minorVersionIntroduced,
437 patchVersionIntroduced,
438 status);
439 this->PolicyStringMap[idString] = iD;
442 //----------------------------------------------------------------------------
443 bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
444 const char *version)
446 std::string ver = "2.4.0";
448 if (version && strlen(version) > 0)
450 ver = version;
453 unsigned int majorVer = 2;
454 unsigned int minorVer = 0;
455 unsigned int patchVer = 0;
457 // parse the string
458 if(sscanf(ver.c_str(), "%u.%u.%u",
459 &majorVer, &minorVer, &patchVer) < 2)
461 cmOStringStream e;
462 e << "Invalid policy version value \"" << ver << "\". "
463 << "A numeric major.minor[.patch] must be given.";
464 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
465 return false;
468 // it is an error if the policy version is less than 2.4
469 if (majorVer < 2 || majorVer == 2 && minorVer < 4)
471 mf->IssueMessage(cmake::FATAL_ERROR,
472 "An attempt was made to set the policy version of CMake to something "
473 "earlier than \"2.4\". "
474 "In CMake 2.4 and below backwards compatibility was handled with the "
475 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
476 "In order to get compatibility features supporting versions earlier "
477 "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
478 "CMAKE_BACKWARDS_COMPATIBILITY variable. "
479 "One way to do this is to set the policy version to 2.4 exactly."
481 return false;
484 // It is an error if the policy version is greater than the running
485 // CMake.
486 if (majorVer > cmVersion::GetMajorVersion() ||
487 (majorVer == cmVersion::GetMajorVersion() &&
488 minorVer > cmVersion::GetMinorVersion()) ||
489 (majorVer == cmVersion::GetMajorVersion() &&
490 minorVer == cmVersion::GetMinorVersion() &&
491 patchVer > cmVersion::GetPatchVersion()))
493 cmOStringStream e;
494 e << "An attempt was made to set the policy version of CMake to \""
495 << version << "\" which is greater than this version of CMake. "
496 << "This is not allowed because the greater version may have new "
497 << "policies not known to this CMake. "
498 << "You may need a newer CMake version to build this project.";
499 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
500 return false;
503 // now loop over all the policies and set them as appropriate
504 std::vector<cmPolicies::PolicyID> ancientPolicies;
505 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
506 = this->Policies.begin();
507 for (;i != this->Policies.end(); ++i)
509 if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
511 if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
513 ancientPolicies.push_back(i->first);
515 else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
517 return false;
520 else
522 if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
524 return false;
529 // Make sure the project does not use any ancient policies.
530 if(!ancientPolicies.empty())
532 this->DiagnoseAncientPolicies(ancientPolicies,
533 majorVer, minorVer, patchVer, mf);
534 cmSystemTools::SetFatalErrorOccured();
535 return false;
538 return true;
541 bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
543 if (!id || strlen(id) < 1)
545 return false;
547 std::map<std::string,cmPolicies::PolicyID>::iterator pos =
548 this->PolicyStringMap.find(id);
549 if (pos == this->PolicyStringMap.end())
551 return false;
553 pid = pos->second;
554 return true;
557 std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
559 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
560 this->Policies.find(pid);
561 if (pos == this->Policies.end())
563 return "";
565 return pos->second->IDString;
569 ///! return a warning string for a given policy
570 std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
572 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
573 this->Policies.find(id);
574 if (pos == this->Policies.end())
576 cmSystemTools::Error(
577 "Request for warning text for undefined policy!");
578 return "Request for warning text for undefined policy!";
581 cmOStringStream msg;
582 msg <<
583 "Policy " << pos->second->IDString << " is not set: "
584 "" << pos->second->ShortDescription << " "
585 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
586 "policy details. "
587 "Use the cmake_policy command to set the policy "
588 "and suppress this warning.";
589 return msg.str();
593 ///! return an error string for when a required policy is unspecified
594 std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
596 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
597 this->Policies.find(id);
598 if (pos == this->Policies.end())
600 cmSystemTools::Error(
601 "Request for error text for undefined policy!");
602 return "Request for warning text for undefined policy!";
605 cmOStringStream error;
606 error <<
607 "Policy " << pos->second->IDString << " is not set to NEW: "
608 "" << pos->second->ShortDescription << " "
609 "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
610 "policy details. "
611 "CMake now requires this policy to be set to NEW by the project. "
612 "The policy may be set explicitly using the code\n"
613 " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
614 "or by upgrading all policies with the code\n"
615 " cmake_policy(VERSION " << pos->second->GetVersionString() <<
616 ") # or later\n"
617 "Run \"cmake --help-command cmake_policy\" for more information.";
618 return error.str();
621 ///! Get the default status for a policy
622 cmPolicies::PolicyStatus
623 cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
625 // if the policy is not know then what?
626 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
627 this->Policies.find(id);
628 if (pos == this->Policies.end())
630 // TODO is this right?
631 return cmPolicies::WARN;
634 return pos->second->Status;
637 void cmPolicies::GetDocumentation(std::vector<cmDocumentationEntry>& v)
639 // now loop over all the policies and set them as appropriate
640 std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
641 = this->Policies.begin();
642 for (;i != this->Policies.end(); ++i)
644 cmOStringStream full;
645 full << i->second->LongDescription;
646 full << "\nThis policy was introduced in CMake version ";
647 full << i->second->GetVersionString() << ".";
648 if(i->first != cmPolicies::CMP0000)
650 full << " "
651 << "CMake version " << cmVersion::GetMajorVersion()
652 << "." << cmVersion::GetMinorVersion() << " ";
653 // add in some more text here based on status
654 switch (i->second->Status)
656 case cmPolicies::WARN:
657 full << "warns when the policy is not set and uses OLD behavior. "
658 << "Use the cmake_policy command to set it to OLD or NEW "
659 << "explicitly.";
660 break;
661 case cmPolicies::OLD:
662 full << "defaults to the OLD behavior for this policy.";
663 break;
664 case cmPolicies::NEW:
665 full << "defaults to the NEW behavior for this policy.";
666 break;
667 case cmPolicies::REQUIRED_IF_USED:
668 full << "requires the policy to be set to NEW if you use it. "
669 << "Use the cmake_policy command to set it to NEW.";
670 break;
671 case cmPolicies::REQUIRED_ALWAYS:
672 full << "requires the policy to be set to NEW. "
673 << "Use the cmake_policy command to set it to NEW.";
674 break;
677 cmDocumentationEntry e(i->second->IDString.c_str(),
678 i->second->ShortDescription.c_str(),
679 full.str().c_str());
680 v.push_back(e);
684 //----------------------------------------------------------------------------
685 std::string
686 cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
688 std::string pid = this->GetPolicyIDString(id);
689 cmOStringStream e;
690 e << "Policy " << pid << " may not be set to OLD behavior because this "
691 << "version of CMake no longer supports it. "
692 << "The policy was introduced in "
693 << "CMake version " << this->Policies[id]->GetVersionString()
694 << ", and use of NEW behavior is now required."
695 << "\n"
696 << "Please either update your CMakeLists.txt files to conform to "
697 << "the new behavior or use an older version of CMake that still "
698 << "supports the old behavior. "
699 << "Run cmake --help-policy " << pid << " for more information.";
700 return e.str();
703 //----------------------------------------------------------------------------
704 void
705 cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
706 unsigned int majorVer,
707 unsigned int minorVer,
708 unsigned int patchVer,
709 cmMakefile* mf)
711 cmOStringStream e;
712 e << "The project requests behavior compatible with CMake version \""
713 << majorVer << "." << minorVer << "." << patchVer
714 << "\", which requires the OLD behavior for some policies:\n";
715 for(std::vector<PolicyID>::const_iterator
716 i = ancient.begin(); i != ancient.end(); ++i)
718 cmPolicy const* policy = this->Policies[*i];
719 e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
721 e << "However, this version of CMake no longer supports the OLD "
722 << "behavior for these policies. "
723 << "Please either update your CMakeLists.txt files to conform to "
724 << "the new behavior or use an older version of CMake that still "
725 << "supports the old behavior.";
726 mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());