cmPolicies.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. #include "cmPolicies.h"
  2. #include "cmake.h"
  3. #include "cmMakefile.h"
  4. #include "cmVersion.h"
  5. #include "cmVersionMacros.h"
  6. #include "cmAlgorithms.h"
  7. #include <map>
  8. #include <set>
  9. #include <queue>
  10. #include <assert.h>
  11. class cmPolicy
  12. {
  13. public:
  14. cmPolicy(cmPolicies::PolicyID iD,
  15. const char *idString,
  16. const char *shortDescription,
  17. unsigned int majorVersionIntroduced,
  18. unsigned int minorVersionIntroduced,
  19. unsigned int patchVersionIntroduced,
  20. cmPolicies::PolicyStatus status)
  21. {
  22. if (!idString || !shortDescription)
  23. {
  24. cmSystemTools::Error("Attempt to define a policy without "
  25. "all parameters being specified!");
  26. return;
  27. }
  28. this->ID = iD;
  29. this->IDString = idString;
  30. this->ShortDescription = shortDescription;
  31. this->MajorVersionIntroduced = majorVersionIntroduced;
  32. this->MinorVersionIntroduced = minorVersionIntroduced;
  33. this->PatchVersionIntroduced = patchVersionIntroduced;
  34. this->Status = status;
  35. }
  36. std::string GetVersionString()
  37. {
  38. std::ostringstream v;
  39. v << this->MajorVersionIntroduced << "." << this->MinorVersionIntroduced;
  40. if(this->PatchVersionIntroduced > 0)
  41. {
  42. v << "." << this->PatchVersionIntroduced;
  43. }
  44. return v.str();
  45. }
  46. bool IsPolicyNewerThan(unsigned int majorV,
  47. unsigned int minorV,
  48. unsigned int patchV)
  49. {
  50. if (majorV < this->MajorVersionIntroduced)
  51. {
  52. return true;
  53. }
  54. if (majorV > this->MajorVersionIntroduced)
  55. {
  56. return false;
  57. }
  58. if (minorV < this->MinorVersionIntroduced)
  59. {
  60. return true;
  61. }
  62. if (minorV > this->MinorVersionIntroduced)
  63. {
  64. return false;
  65. }
  66. return (patchV < this->PatchVersionIntroduced);
  67. }
  68. cmPolicies::PolicyID ID;
  69. std::string IDString;
  70. std::string ShortDescription;
  71. unsigned int MajorVersionIntroduced;
  72. unsigned int MinorVersionIntroduced;
  73. unsigned int PatchVersionIntroduced;
  74. cmPolicies::PolicyStatus Status;
  75. };
  76. cmPolicies::cmPolicies()
  77. {
  78. // define all the policies
  79. this->DefinePolicy(
  80. CMP0000, "CMP0000",
  81. "A minimum required CMake version must be specified.",
  82. 2,6,0, cmPolicies::WARN
  83. );
  84. this->DefinePolicy(
  85. CMP0001, "CMP0001",
  86. "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
  87. 2,6,0, cmPolicies::WARN
  88. );
  89. this->DefinePolicy(
  90. CMP0002, "CMP0002",
  91. "Logical target names must be globally unique.",
  92. 2,6,0, cmPolicies::WARN
  93. );
  94. this->DefinePolicy(
  95. CMP0003, "CMP0003",
  96. "Libraries linked via full path no longer produce linker search paths.",
  97. 2,6,0, cmPolicies::WARN);
  98. this->DefinePolicy(
  99. CMP0004, "CMP0004",
  100. "Libraries linked may not have leading or trailing whitespace.",
  101. 2,6,0, cmPolicies::WARN);
  102. this->DefinePolicy(
  103. CMP0005, "CMP0005",
  104. "Preprocessor definition values are now escaped automatically.",
  105. 2,6,0, cmPolicies::WARN);
  106. this->DefinePolicy(
  107. CMP0006, "CMP0006",
  108. "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.",
  109. 2,6,0, cmPolicies::WARN);
  110. this->DefinePolicy(
  111. CMP0007, "CMP0007",
  112. "list command no longer ignores empty elements.",
  113. 2,6,0, cmPolicies::WARN);
  114. this->DefinePolicy(
  115. CMP0008, "CMP0008",
  116. "Libraries linked by full-path must have a valid library file name.",
  117. 2,6,1, cmPolicies::WARN);
  118. this->DefinePolicy(
  119. CMP0009, "CMP0009",
  120. "FILE GLOB_RECURSE calls should not follow symlinks by default.",
  121. 2,6,2, cmPolicies::WARN);
  122. this->DefinePolicy(
  123. CMP0010, "CMP0010",
  124. "Bad variable reference syntax is an error.",
  125. 2,6,3, cmPolicies::WARN);
  126. this->DefinePolicy(
  127. CMP0011, "CMP0011",
  128. "Included scripts do automatic cmake_policy PUSH and POP.",
  129. 2,6,3, cmPolicies::WARN);
  130. this->DefinePolicy(
  131. CMP0012, "CMP0012",
  132. "if() recognizes numbers and boolean constants.",
  133. 2,8,0, cmPolicies::WARN);
  134. this->DefinePolicy(
  135. CMP0013, "CMP0013",
  136. "Duplicate binary directories are not allowed.",
  137. 2,8,0, cmPolicies::WARN);
  138. this->DefinePolicy(
  139. CMP0014, "CMP0014",
  140. "Input directories must have CMakeLists.txt.",
  141. 2,8,0, cmPolicies::WARN);
  142. this->DefinePolicy(
  143. CMP0015, "CMP0015",
  144. "link_directories() treats paths relative to the source dir.",
  145. 2,8,1, cmPolicies::WARN);
  146. this->DefinePolicy(
  147. CMP0016, "CMP0016",
  148. "target_link_libraries() reports error if its only argument "
  149. "is not a target.",
  150. 2,8,3, cmPolicies::WARN);
  151. this->DefinePolicy(
  152. CMP0017, "CMP0017",
  153. "Prefer files from the CMake module directory when including from there.",
  154. 2,8,4, cmPolicies::WARN);
  155. this->DefinePolicy(
  156. CMP0018, "CMP0018",
  157. "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.",
  158. 2,8,9, cmPolicies::WARN);
  159. this->DefinePolicy(
  160. CMP0019, "CMP0019",
  161. "Do not re-expand variables in include and link information.",
  162. 2,8,11, cmPolicies::WARN);
  163. this->DefinePolicy(
  164. CMP0020, "CMP0020",
  165. "Automatically link Qt executables to qtmain target on Windows.",
  166. 2,8,11, cmPolicies::WARN);
  167. this->DefinePolicy(
  168. CMP0021, "CMP0021",
  169. "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.",
  170. 2,8,12, cmPolicies::WARN);
  171. this->DefinePolicy(
  172. CMP0022, "CMP0022",
  173. "INTERFACE_LINK_LIBRARIES defines the link interface.",
  174. 2,8,12, cmPolicies::WARN);
  175. this->DefinePolicy(
  176. CMP0023, "CMP0023",
  177. "Plain and keyword target_link_libraries signatures cannot be mixed.",
  178. 2,8,12, cmPolicies::WARN);
  179. this->DefinePolicy(
  180. CMP0024, "CMP0024",
  181. "Disallow include export result.",
  182. 3,0,0, cmPolicies::WARN);
  183. this->DefinePolicy(
  184. CMP0025, "CMP0025",
  185. "Compiler id for Apple Clang is now AppleClang.",
  186. 3,0,0, cmPolicies::WARN);
  187. this->DefinePolicy(
  188. CMP0026, "CMP0026",
  189. "Disallow use of the LOCATION target property.",
  190. 3,0,0, cmPolicies::WARN);
  191. this->DefinePolicy(
  192. CMP0027, "CMP0027",
  193. "Conditionally linked imported targets with missing include directories.",
  194. 3,0,0, cmPolicies::WARN);
  195. this->DefinePolicy(
  196. CMP0028, "CMP0028",
  197. "Double colon in target name means ALIAS or IMPORTED target.",
  198. 3,0,0, cmPolicies::WARN);
  199. this->DefinePolicy(
  200. CMP0029, "CMP0029",
  201. "The subdir_depends command should not be called.",
  202. 3,0,0, cmPolicies::WARN);
  203. this->DefinePolicy(
  204. CMP0030, "CMP0030",
  205. "The use_mangled_mesa command should not be called.",
  206. 3,0,0, cmPolicies::WARN);
  207. this->DefinePolicy(
  208. CMP0031, "CMP0031",
  209. "The load_command command should not be called.",
  210. 3,0,0, cmPolicies::WARN);
  211. this->DefinePolicy(
  212. CMP0032, "CMP0032",
  213. "The output_required_files command should not be called.",
  214. 3,0,0, cmPolicies::WARN);
  215. this->DefinePolicy(
  216. CMP0033, "CMP0033",
  217. "The export_library_dependencies command should not be called.",
  218. 3,0,0, cmPolicies::WARN);
  219. this->DefinePolicy(
  220. CMP0034, "CMP0034",
  221. "The utility_source command should not be called.",
  222. 3,0,0, cmPolicies::WARN);
  223. this->DefinePolicy(
  224. CMP0035, "CMP0035",
  225. "The variable_requires command should not be called.",
  226. 3,0,0, cmPolicies::WARN);
  227. this->DefinePolicy(
  228. CMP0036, "CMP0036",
  229. "The build_name command should not be called.",
  230. 3,0,0, cmPolicies::WARN);
  231. this->DefinePolicy(
  232. CMP0037, "CMP0037",
  233. "Target names should not be reserved and should match a validity pattern.",
  234. 3,0,0, cmPolicies::WARN);
  235. this->DefinePolicy(
  236. CMP0038, "CMP0038",
  237. "Targets may not link directly to themselves.",
  238. 3,0,0, cmPolicies::WARN);
  239. this->DefinePolicy(
  240. CMP0039, "CMP0039",
  241. "Utility targets may not have link dependencies.",
  242. 3,0,0, cmPolicies::WARN);
  243. this->DefinePolicy(
  244. CMP0040, "CMP0040",
  245. "The target in the TARGET signature of add_custom_command() must exist.",
  246. 3,0,0, cmPolicies::WARN);
  247. this->DefinePolicy(
  248. CMP0041, "CMP0041",
  249. "Error on relative include with generator expression.",
  250. 3,0,0, cmPolicies::WARN);
  251. this->DefinePolicy(
  252. CMP0042, "CMP0042",
  253. "MACOSX_RPATH is enabled by default.",
  254. 3,0,0, cmPolicies::WARN);
  255. this->DefinePolicy(
  256. CMP0043, "CMP0043",
  257. "Ignore COMPILE_DEFINITIONS_<Config> properties.",
  258. 3,0,0, cmPolicies::WARN);
  259. this->DefinePolicy(
  260. CMP0044, "CMP0044",
  261. "Case sensitive <LANG>_COMPILER_ID generator expressions.",
  262. 3,0,0, cmPolicies::WARN);
  263. this->DefinePolicy(
  264. CMP0045, "CMP0045",
  265. "Error on non-existent target in get_target_property.",
  266. 3,0,0, cmPolicies::WARN);
  267. this->DefinePolicy(
  268. CMP0046, "CMP0046",
  269. "Error on non-existent dependency in add_dependencies.",
  270. 3,0,0, cmPolicies::WARN);
  271. this->DefinePolicy(
  272. CMP0047, "CMP0047",
  273. "Use QCC compiler id for the qcc drivers on QNX.",
  274. 3,0,0, cmPolicies::WARN);
  275. this->DefinePolicy(
  276. CMP0048, "CMP0048",
  277. "project() command manages VERSION variables.",
  278. 3,0,0, cmPolicies::WARN);
  279. this->DefinePolicy(
  280. CMP0049, "CMP0049",
  281. "Do not expand variables in target source entries.",
  282. 3,0,0, cmPolicies::WARN);
  283. this->DefinePolicy(
  284. CMP0050, "CMP0050",
  285. "Disallow add_custom_command SOURCE signatures.",
  286. 3,0,0, cmPolicies::WARN);
  287. this->DefinePolicy(
  288. CMP0051, "CMP0051",
  289. "List TARGET_OBJECTS in SOURCES target property.",
  290. 3,1,0, cmPolicies::WARN);
  291. this->DefinePolicy(
  292. CMP0052, "CMP0052",
  293. "Reject source and build dirs in installed "
  294. "INTERFACE_INCLUDE_DIRECTORIES.",
  295. 3,1,0, cmPolicies::WARN);
  296. this->DefinePolicy(
  297. CMP0053, "CMP0053",
  298. "Simplify variable reference and escape sequence evaluation.",
  299. 3,1,0, cmPolicies::WARN);
  300. this->DefinePolicy(
  301. CMP0054, "CMP0054",
  302. "Only interpret if() arguments as variables or keywords when unquoted.",
  303. 3,1,0, cmPolicies::WARN);
  304. this->DefinePolicy(
  305. CMP0055, "CMP0055",
  306. "Strict checking for break() command.",
  307. 3,2,0, cmPolicies::WARN);
  308. this->DefinePolicy(
  309. CMP0056, "CMP0056",
  310. "Honor link flags in try_compile() source-file signature.",
  311. 3,2,0, cmPolicies::WARN);
  312. this->DefinePolicy(
  313. CMP0058, "CMP0058",
  314. "Ninja requires custom command byproducts to be explicit.",
  315. 3,3,0, cmPolicies::WARN);
  316. this->DefinePolicy(
  317. CMP0059, "CMP0059",
  318. "Do no treat DEFINITIONS as a built-in directory property.",
  319. 3,3,0, cmPolicies::WARN);
  320. this->DefinePolicy(
  321. CMP0060, "CMP0060",
  322. "Link libraries by full path even in implicit directories.",
  323. 3,3,0, cmPolicies::WARN);
  324. this->DefinePolicy(
  325. CMP0057, "CMP0057",
  326. "Support new IN_LIST if() operator.",
  327. 3,3,0, cmPolicies::WARN);
  328. }
  329. cmPolicies::~cmPolicies()
  330. {
  331. cmDeleteAll(this->Policies);
  332. }
  333. void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
  334. const char *idString,
  335. const char *shortDescription,
  336. unsigned int majorVersionIntroduced,
  337. unsigned int minorVersionIntroduced,
  338. unsigned int patchVersionIntroduced,
  339. cmPolicies::PolicyStatus status)
  340. {
  341. // a policy must be unique and can only be defined once
  342. if (this->Policies.find(iD) != this->Policies.end())
  343. {
  344. cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
  345. "ID ", this->GetPolicyIDString(iD).c_str());
  346. return;
  347. }
  348. this->Policies[iD] = new cmPolicy(iD, idString,
  349. shortDescription,
  350. majorVersionIntroduced,
  351. minorVersionIntroduced,
  352. patchVersionIntroduced,
  353. status);
  354. this->PolicyStringMap[idString] = iD;
  355. }
  356. //----------------------------------------------------------------------------
  357. bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
  358. const char *version)
  359. {
  360. std::string ver = "2.4.0";
  361. if (version && strlen(version) > 0)
  362. {
  363. ver = version;
  364. }
  365. unsigned int majorVer = 2;
  366. unsigned int minorVer = 0;
  367. unsigned int patchVer = 0;
  368. unsigned int tweakVer = 0;
  369. // parse the string
  370. if(sscanf(ver.c_str(), "%u.%u.%u.%u",
  371. &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
  372. {
  373. std::ostringstream e;
  374. e << "Invalid policy version value \"" << ver << "\". "
  375. << "A numeric major.minor[.patch[.tweak]] must be given.";
  376. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  377. return false;
  378. }
  379. // it is an error if the policy version is less than 2.4
  380. if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
  381. {
  382. mf->IssueMessage(cmake::FATAL_ERROR,
  383. "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. "
  384. "For compatibility with older versions please use any CMake 2.8.x "
  385. "release or lower.");
  386. return false;
  387. }
  388. // It is an error if the policy version is greater than the running
  389. // CMake.
  390. if (majorVer > cmVersion::GetMajorVersion() ||
  391. (majorVer == cmVersion::GetMajorVersion() &&
  392. minorVer > cmVersion::GetMinorVersion()) ||
  393. (majorVer == cmVersion::GetMajorVersion() &&
  394. minorVer == cmVersion::GetMinorVersion() &&
  395. patchVer > cmVersion::GetPatchVersion()) ||
  396. (majorVer == cmVersion::GetMajorVersion() &&
  397. minorVer == cmVersion::GetMinorVersion() &&
  398. patchVer == cmVersion::GetPatchVersion() &&
  399. tweakVer > cmVersion::GetTweakVersion()))
  400. {
  401. std::ostringstream e;
  402. e << "An attempt was made to set the policy version of CMake to \""
  403. << version << "\" which is greater than this version of CMake. "
  404. << "This is not allowed because the greater version may have new "
  405. << "policies not known to this CMake. "
  406. << "You may need a newer CMake version to build this project.";
  407. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  408. return false;
  409. }
  410. // now loop over all the policies and set them as appropriate
  411. std::vector<cmPolicies::PolicyID> ancientPolicies;
  412. for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  413. = this->Policies.begin(); i != this->Policies.end(); ++i)
  414. {
  415. if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
  416. {
  417. if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
  418. {
  419. ancientPolicies.push_back(i->first);
  420. }
  421. else
  422. {
  423. cmPolicies::PolicyStatus status = cmPolicies::WARN;
  424. if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
  425. !mf->SetPolicy(i->second->ID, status))
  426. {
  427. return false;
  428. }
  429. }
  430. }
  431. else
  432. {
  433. if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
  434. {
  435. return false;
  436. }
  437. }
  438. }
  439. // Make sure the project does not use any ancient policies.
  440. if(!ancientPolicies.empty())
  441. {
  442. this->DiagnoseAncientPolicies(ancientPolicies,
  443. majorVer, minorVer, patchVer, mf);
  444. cmSystemTools::SetFatalErrorOccured();
  445. return false;
  446. }
  447. return true;
  448. }
  449. //----------------------------------------------------------------------------
  450. bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
  451. cmPolicies::PolicyStatus* defaultSetting)
  452. {
  453. std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
  454. std::string defaultValue = mf->GetSafeDefinition(defaultVar);
  455. if(defaultValue == "NEW")
  456. {
  457. *defaultSetting = cmPolicies::NEW;
  458. }
  459. else if(defaultValue == "OLD")
  460. {
  461. *defaultSetting = cmPolicies::OLD;
  462. }
  463. else if(defaultValue == "")
  464. {
  465. *defaultSetting = cmPolicies::WARN;
  466. }
  467. else
  468. {
  469. std::ostringstream e;
  470. e << defaultVar << " has value \"" << defaultValue
  471. << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
  472. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  473. return false;
  474. }
  475. return true;
  476. }
  477. bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
  478. {
  479. if (!id || strlen(id) < 1)
  480. {
  481. return false;
  482. }
  483. std::map<std::string,cmPolicies::PolicyID>::iterator pos =
  484. this->PolicyStringMap.find(id);
  485. if (pos == this->PolicyStringMap.end())
  486. {
  487. return false;
  488. }
  489. pid = pos->second;
  490. return true;
  491. }
  492. std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
  493. {
  494. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  495. this->Policies.find(pid);
  496. if (pos == this->Policies.end())
  497. {
  498. return "";
  499. }
  500. return pos->second->IDString;
  501. }
  502. ///! return a warning string for a given policy
  503. std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
  504. {
  505. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  506. this->Policies.find(id);
  507. if (pos == this->Policies.end())
  508. {
  509. cmSystemTools::Error(
  510. "Request for warning text for undefined policy!");
  511. return "Request for warning text for undefined policy!";
  512. }
  513. std::ostringstream msg;
  514. msg <<
  515. "Policy " << pos->second->IDString << " is not set: "
  516. "" << pos->second->ShortDescription << " "
  517. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  518. "policy details. "
  519. "Use the cmake_policy command to set the policy "
  520. "and suppress this warning.";
  521. return msg.str();
  522. }
  523. ///! return an error string for when a required policy is unspecified
  524. std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
  525. {
  526. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  527. this->Policies.find(id);
  528. if (pos == this->Policies.end())
  529. {
  530. cmSystemTools::Error(
  531. "Request for error text for undefined policy!");
  532. return "Request for error text for undefined policy!";
  533. }
  534. std::ostringstream error;
  535. error <<
  536. "Policy " << pos->second->IDString << " is not set to NEW: "
  537. "" << pos->second->ShortDescription << " "
  538. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  539. "policy details. "
  540. "CMake now requires this policy to be set to NEW by the project. "
  541. "The policy may be set explicitly using the code\n"
  542. " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
  543. "or by upgrading all policies with the code\n"
  544. " cmake_policy(VERSION " << pos->second->GetVersionString() <<
  545. ") # or later\n"
  546. "Run \"cmake --help-command cmake_policy\" for more information.";
  547. return error.str();
  548. }
  549. ///! Get the default status for a policy
  550. cmPolicies::PolicyStatus
  551. cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
  552. {
  553. // if the policy is not know then what?
  554. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  555. this->Policies.find(id);
  556. if (pos == this->Policies.end())
  557. {
  558. // TODO is this right?
  559. return cmPolicies::WARN;
  560. }
  561. return pos->second->Status;
  562. }
  563. //----------------------------------------------------------------------------
  564. std::string
  565. cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
  566. {
  567. std::string pid = this->GetPolicyIDString(id);
  568. std::ostringstream e;
  569. e << "Policy " << pid << " may not be set to OLD behavior because this "
  570. << "version of CMake no longer supports it. "
  571. << "The policy was introduced in "
  572. << "CMake version " << this->Policies[id]->GetVersionString()
  573. << ", and use of NEW behavior is now required."
  574. << "\n"
  575. << "Please either update your CMakeLists.txt files to conform to "
  576. << "the new behavior or use an older version of CMake that still "
  577. << "supports the old behavior. "
  578. << "Run cmake --help-policy " << pid << " for more information.";
  579. return e.str();
  580. }
  581. //----------------------------------------------------------------------------
  582. void
  583. cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
  584. unsigned int majorVer,
  585. unsigned int minorVer,
  586. unsigned int patchVer,
  587. cmMakefile* mf)
  588. {
  589. std::ostringstream e;
  590. e << "The project requests behavior compatible with CMake version \""
  591. << majorVer << "." << minorVer << "." << patchVer
  592. << "\", which requires the OLD behavior for some policies:\n";
  593. for(std::vector<PolicyID>::const_iterator
  594. i = ancient.begin(); i != ancient.end(); ++i)
  595. {
  596. cmPolicy const* policy = this->Policies[*i];
  597. e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
  598. }
  599. e << "However, this version of CMake no longer supports the OLD "
  600. << "behavior for these policies. "
  601. << "Please either update your CMakeLists.txt files to conform to "
  602. << "the new behavior or use an older version of CMake that still "
  603. << "supports the old behavior.";
  604. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  605. }