cmPolicies.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. #include "cmPolicies.h"
  2. #include "cmake.h"
  3. #include "cmMakefile.h"
  4. #include "cmSourceFile.h"
  5. #include "cmVersion.h"
  6. #include "cmVersionMacros.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. }
  316. cmPolicies::~cmPolicies()
  317. {
  318. cmDeleteAll(this->Policies);
  319. }
  320. void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
  321. const char *idString,
  322. const char *shortDescription,
  323. unsigned int majorVersionIntroduced,
  324. unsigned int minorVersionIntroduced,
  325. unsigned int patchVersionIntroduced,
  326. cmPolicies::PolicyStatus status)
  327. {
  328. // a policy must be unique and can only be defined once
  329. if (this->Policies.find(iD) != this->Policies.end())
  330. {
  331. cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
  332. "ID ", this->GetPolicyIDString(iD).c_str());
  333. return;
  334. }
  335. this->Policies[iD] = new cmPolicy(iD, idString,
  336. shortDescription,
  337. majorVersionIntroduced,
  338. minorVersionIntroduced,
  339. patchVersionIntroduced,
  340. status);
  341. this->PolicyStringMap[idString] = iD;
  342. }
  343. //----------------------------------------------------------------------------
  344. bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
  345. const char *version)
  346. {
  347. std::string ver = "2.4.0";
  348. if (version && strlen(version) > 0)
  349. {
  350. ver = version;
  351. }
  352. unsigned int majorVer = 2;
  353. unsigned int minorVer = 0;
  354. unsigned int patchVer = 0;
  355. unsigned int tweakVer = 0;
  356. // parse the string
  357. if(sscanf(ver.c_str(), "%u.%u.%u.%u",
  358. &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
  359. {
  360. std::ostringstream e;
  361. e << "Invalid policy version value \"" << ver << "\". "
  362. << "A numeric major.minor[.patch[.tweak]] must be given.";
  363. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  364. return false;
  365. }
  366. // it is an error if the policy version is less than 2.4
  367. if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
  368. {
  369. mf->IssueMessage(cmake::FATAL_ERROR,
  370. "Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. "
  371. "For compatibility with older versions please use any CMake 2.8.x "
  372. "release or lower.");
  373. return false;
  374. }
  375. // It is an error if the policy version is greater than the running
  376. // CMake.
  377. if (majorVer > cmVersion::GetMajorVersion() ||
  378. (majorVer == cmVersion::GetMajorVersion() &&
  379. minorVer > cmVersion::GetMinorVersion()) ||
  380. (majorVer == cmVersion::GetMajorVersion() &&
  381. minorVer == cmVersion::GetMinorVersion() &&
  382. patchVer > cmVersion::GetPatchVersion()) ||
  383. (majorVer == cmVersion::GetMajorVersion() &&
  384. minorVer == cmVersion::GetMinorVersion() &&
  385. patchVer == cmVersion::GetPatchVersion() &&
  386. tweakVer > cmVersion::GetTweakVersion()))
  387. {
  388. std::ostringstream e;
  389. e << "An attempt was made to set the policy version of CMake to \""
  390. << version << "\" which is greater than this version of CMake. "
  391. << "This is not allowed because the greater version may have new "
  392. << "policies not known to this CMake. "
  393. << "You may need a newer CMake version to build this project.";
  394. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  395. return false;
  396. }
  397. // now loop over all the policies and set them as appropriate
  398. std::vector<cmPolicies::PolicyID> ancientPolicies;
  399. for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  400. = this->Policies.begin(); i != this->Policies.end(); ++i)
  401. {
  402. if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer))
  403. {
  404. if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
  405. {
  406. ancientPolicies.push_back(i->first);
  407. }
  408. else
  409. {
  410. cmPolicies::PolicyStatus status = cmPolicies::WARN;
  411. if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
  412. !mf->SetPolicy(i->second->ID, status))
  413. {
  414. return false;
  415. }
  416. }
  417. }
  418. else
  419. {
  420. if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
  421. {
  422. return false;
  423. }
  424. }
  425. }
  426. // Make sure the project does not use any ancient policies.
  427. if(!ancientPolicies.empty())
  428. {
  429. this->DiagnoseAncientPolicies(ancientPolicies,
  430. majorVer, minorVer, patchVer, mf);
  431. cmSystemTools::SetFatalErrorOccured();
  432. return false;
  433. }
  434. return true;
  435. }
  436. //----------------------------------------------------------------------------
  437. bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
  438. cmPolicies::PolicyStatus* defaultSetting)
  439. {
  440. std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
  441. std::string defaultValue = mf->GetSafeDefinition(defaultVar);
  442. if(defaultValue == "NEW")
  443. {
  444. *defaultSetting = cmPolicies::NEW;
  445. }
  446. else if(defaultValue == "OLD")
  447. {
  448. *defaultSetting = cmPolicies::OLD;
  449. }
  450. else if(defaultValue == "")
  451. {
  452. *defaultSetting = cmPolicies::WARN;
  453. }
  454. else
  455. {
  456. std::ostringstream e;
  457. e << defaultVar << " has value \"" << defaultValue
  458. << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
  459. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  460. return false;
  461. }
  462. return true;
  463. }
  464. bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
  465. {
  466. if (!id || strlen(id) < 1)
  467. {
  468. return false;
  469. }
  470. std::map<std::string,cmPolicies::PolicyID>::iterator pos =
  471. this->PolicyStringMap.find(id);
  472. if (pos == this->PolicyStringMap.end())
  473. {
  474. return false;
  475. }
  476. pid = pos->second;
  477. return true;
  478. }
  479. std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
  480. {
  481. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  482. this->Policies.find(pid);
  483. if (pos == this->Policies.end())
  484. {
  485. return "";
  486. }
  487. return pos->second->IDString;
  488. }
  489. ///! return a warning string for a given policy
  490. std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
  491. {
  492. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  493. this->Policies.find(id);
  494. if (pos == this->Policies.end())
  495. {
  496. cmSystemTools::Error(
  497. "Request for warning text for undefined policy!");
  498. return "Request for warning text for undefined policy!";
  499. }
  500. std::ostringstream msg;
  501. msg <<
  502. "Policy " << pos->second->IDString << " is not set: "
  503. "" << pos->second->ShortDescription << " "
  504. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  505. "policy details. "
  506. "Use the cmake_policy command to set the policy "
  507. "and suppress this warning.";
  508. return msg.str();
  509. }
  510. ///! return an error string for when a required policy is unspecified
  511. std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
  512. {
  513. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  514. this->Policies.find(id);
  515. if (pos == this->Policies.end())
  516. {
  517. cmSystemTools::Error(
  518. "Request for error text for undefined policy!");
  519. return "Request for error text for undefined policy!";
  520. }
  521. std::ostringstream error;
  522. error <<
  523. "Policy " << pos->second->IDString << " is not set to NEW: "
  524. "" << pos->second->ShortDescription << " "
  525. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  526. "policy details. "
  527. "CMake now requires this policy to be set to NEW by the project. "
  528. "The policy may be set explicitly using the code\n"
  529. " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
  530. "or by upgrading all policies with the code\n"
  531. " cmake_policy(VERSION " << pos->second->GetVersionString() <<
  532. ") # or later\n"
  533. "Run \"cmake --help-command cmake_policy\" for more information.";
  534. return error.str();
  535. }
  536. ///! Get the default status for a policy
  537. cmPolicies::PolicyStatus
  538. cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
  539. {
  540. // if the policy is not know then what?
  541. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  542. this->Policies.find(id);
  543. if (pos == this->Policies.end())
  544. {
  545. // TODO is this right?
  546. return cmPolicies::WARN;
  547. }
  548. return pos->second->Status;
  549. }
  550. //----------------------------------------------------------------------------
  551. std::string
  552. cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
  553. {
  554. std::string pid = this->GetPolicyIDString(id);
  555. std::ostringstream e;
  556. e << "Policy " << pid << " may not be set to OLD behavior because this "
  557. << "version of CMake no longer supports it. "
  558. << "The policy was introduced in "
  559. << "CMake version " << this->Policies[id]->GetVersionString()
  560. << ", and use of NEW behavior is now required."
  561. << "\n"
  562. << "Please either update your CMakeLists.txt files to conform to "
  563. << "the new behavior or use an older version of CMake that still "
  564. << "supports the old behavior. "
  565. << "Run cmake --help-policy " << pid << " for more information.";
  566. return e.str();
  567. }
  568. //----------------------------------------------------------------------------
  569. void
  570. cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
  571. unsigned int majorVer,
  572. unsigned int minorVer,
  573. unsigned int patchVer,
  574. cmMakefile* mf)
  575. {
  576. std::ostringstream e;
  577. e << "The project requests behavior compatible with CMake version \""
  578. << majorVer << "." << minorVer << "." << patchVer
  579. << "\", which requires the OLD behavior for some policies:\n";
  580. for(std::vector<PolicyID>::const_iterator
  581. i = ancient.begin(); i != ancient.end(); ++i)
  582. {
  583. cmPolicy const* policy = this->Policies[*i];
  584. e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
  585. }
  586. e << "However, this version of CMake no longer supports the OLD "
  587. << "behavior for these policies. "
  588. << "Please either update your CMakeLists.txt files to conform to "
  589. << "the new behavior or use an older version of CMake that still "
  590. << "supports the old behavior.";
  591. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  592. }