cmPolicies.cxx 20 KB

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