cmPolicies.cxx 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. const char *longDescription,
  21. unsigned int majorVersionIntroduced,
  22. unsigned int minorVersionIntroduced,
  23. unsigned int patchVersionIntroduced,
  24. unsigned int tweakVersionIntroduced,
  25. cmPolicies::PolicyStatus status)
  26. {
  27. if (!idString || !shortDescription || ! longDescription)
  28. {
  29. cmSystemTools::Error("Attempt to define a policy without "
  30. "all parameters being specified!");
  31. return;
  32. }
  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->TweakVersionIntroduced = tweakVersionIntroduced;
  41. this->Status = status;
  42. }
  43. std::string GetVersionString()
  44. {
  45. cmOStringStream v;
  46. v << this->MajorVersionIntroduced << "." << this->MinorVersionIntroduced;
  47. v << "." << this->PatchVersionIntroduced;
  48. if(this->TweakVersionIntroduced > 0)
  49. {
  50. v << "." << this->TweakVersionIntroduced;
  51. }
  52. return v.str();
  53. }
  54. bool IsPolicyNewerThan(unsigned int majorV,
  55. unsigned int minorV,
  56. unsigned int patchV,
  57. unsigned int tweakV)
  58. {
  59. if (majorV < this->MajorVersionIntroduced)
  60. {
  61. return true;
  62. }
  63. if (majorV > this->MajorVersionIntroduced)
  64. {
  65. return false;
  66. }
  67. if (minorV < this->MinorVersionIntroduced)
  68. {
  69. return true;
  70. }
  71. if (minorV > this->MinorVersionIntroduced)
  72. {
  73. return false;
  74. }
  75. if (patchV < this->PatchVersionIntroduced)
  76. {
  77. return true;
  78. }
  79. if (patchV > this->PatchVersionIntroduced)
  80. {
  81. return false;
  82. }
  83. return (tweakV < this->TweakVersionIntroduced);
  84. }
  85. cmPolicies::PolicyID ID;
  86. std::string IDString;
  87. std::string ShortDescription;
  88. std::string LongDescription;
  89. unsigned int MajorVersionIntroduced;
  90. unsigned int MinorVersionIntroduced;
  91. unsigned int PatchVersionIntroduced;
  92. unsigned int TweakVersionIntroduced;
  93. cmPolicies::PolicyStatus Status;
  94. };
  95. cmPolicies::cmPolicies()
  96. {
  97. // define all the policies
  98. this->DefinePolicy(
  99. CMP0000, "CMP0000",
  100. "A minimum required CMake version must be specified.",
  101. "CMake requires that projects specify the version of CMake to which "
  102. "they have been written. "
  103. "This policy has been put in place so users trying to build the project "
  104. "may be told when they need to update their CMake. "
  105. "Specifying a version also helps the project build with CMake versions "
  106. "newer than that specified. "
  107. "Use the cmake_minimum_required command at the top of your main "
  108. " CMakeLists.txt file:\n"
  109. " cmake_minimum_required(VERSION <major>.<minor>)\n"
  110. "where \"<major>.<minor>\" is the version of CMake you want to support "
  111. "(such as \"2.6\"). "
  112. "The command will ensure that at least the given version of CMake is "
  113. "running and help newer versions be compatible with the project. "
  114. "See documentation of cmake_minimum_required for details.\n"
  115. "Note that the command invocation must appear in the CMakeLists.txt "
  116. "file itself; a call in an included file is not sufficient. "
  117. "However, the cmake_policy command may be called to set policy "
  118. "CMP0000 to OLD or NEW behavior explicitly. "
  119. "The OLD behavior is to silently ignore the missing invocation. "
  120. "The NEW behavior is to issue an error instead of a warning. "
  121. "An included file may set CMP0000 explicitly to affect how this "
  122. "policy is enforced for the main CMakeLists.txt file.",
  123. 2,6,0,0, cmPolicies::WARN
  124. );
  125. this->DefinePolicy(
  126. CMP0001, "CMP0001",
  127. "CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.",
  128. "The OLD behavior is to check CMAKE_BACKWARDS_COMPATIBILITY and present "
  129. "it to the user. "
  130. "The NEW behavior is to ignore CMAKE_BACKWARDS_COMPATIBILITY "
  131. "completely.\n"
  132. "In CMake 2.4 and below the variable CMAKE_BACKWARDS_COMPATIBILITY was "
  133. "used to request compatibility with earlier versions of CMake. "
  134. "In CMake 2.6 and above all compatibility issues are handled by policies "
  135. "and the cmake_policy command. "
  136. "However, CMake must still check CMAKE_BACKWARDS_COMPATIBILITY for "
  137. "projects written for CMake 2.4 and below.",
  138. 2,6,0,0, cmPolicies::WARN
  139. );
  140. this->DefinePolicy(
  141. CMP0002, "CMP0002",
  142. "Logical target names must be globally unique.",
  143. "Targets names created with "
  144. "add_executable, add_library, or add_custom_target "
  145. "are logical build target names. "
  146. "Logical target names must be globally unique because:\n"
  147. " - Unique names may be referenced unambiguously both in CMake\n"
  148. " code and on make tool command lines.\n"
  149. " - Logical names are used by Xcode and VS IDE generators\n"
  150. " to produce meaningful project names for the targets.\n"
  151. "The logical name of executable and library targets does not "
  152. "have to correspond to the physical file names built. "
  153. "Consider using the OUTPUT_NAME target property to create two "
  154. "targets with the same physical name while keeping logical "
  155. "names distinct. "
  156. "Custom targets must simply have globally unique names (unless one "
  157. "uses the global property ALLOW_DUPLICATE_CUSTOM_TARGETS with a "
  158. "Makefiles generator).",
  159. 2,6,0,0, cmPolicies::WARN
  160. );
  161. this->DefinePolicy(
  162. CMP0003, "CMP0003",
  163. "Libraries linked via full path no longer produce linker search paths.",
  164. "This policy affects how libraries whose full paths are NOT known "
  165. "are found at link time, but was created due to a change in how CMake "
  166. "deals with libraries whose full paths are known. "
  167. "Consider the code\n"
  168. " target_link_libraries(myexe /path/to/libA.so)\n"
  169. "CMake 2.4 and below implemented linking to libraries whose full paths "
  170. "are known by splitting them on the link line into separate components "
  171. "consisting of the linker search path and the library name. "
  172. "The example code might have produced something like\n"
  173. " ... -L/path/to -lA ...\n"
  174. "in order to link to library A. "
  175. "An analysis was performed to order multiple link directories such that "
  176. "the linker would find library A in the desired location, but there "
  177. "are cases in which this does not work. "
  178. "CMake versions 2.6 and above use the more reliable approach of passing "
  179. "the full path to libraries directly to the linker in most cases. "
  180. "The example code now produces something like\n"
  181. " ... /path/to/libA.so ....\n"
  182. "Unfortunately this change can break code like\n"
  183. " target_link_libraries(myexe /path/to/libA.so B)\n"
  184. "where \"B\" is meant to find \"/path/to/libB.so\". "
  185. "This code is wrong because the user is asking the linker to find "
  186. "library B but has not provided a linker search path (which may be "
  187. "added with the link_directories command). "
  188. "However, with the old linking implementation the code would work "
  189. "accidentally because the linker search path added for library A "
  190. "allowed library B to be found."
  191. "\n"
  192. "In order to support projects depending on linker search paths "
  193. "added by linking to libraries with known full paths, the OLD "
  194. "behavior for this policy will add the linker search paths even "
  195. "though they are not needed for their own libraries. "
  196. "When this policy is set to OLD, CMake will produce a link line such as\n"
  197. " ... -L/path/to /path/to/libA.so -lB ...\n"
  198. "which will allow library B to be found as it was previously. "
  199. "When this policy is set to NEW, CMake will produce a link line such as\n"
  200. " ... /path/to/libA.so -lB ...\n"
  201. "which more accurately matches what the project specified."
  202. "\n"
  203. "The setting for this policy used when generating the link line is that "
  204. "in effect when the target is created by an add_executable or "
  205. "add_library command. For the example described above, the code\n"
  206. " cmake_policy(SET CMP0003 OLD) # or cmake_policy(VERSION 2.4)\n"
  207. " add_executable(myexe myexe.c)\n"
  208. " target_link_libraries(myexe /path/to/libA.so B)\n"
  209. "will work and suppress the warning for this policy. "
  210. "It may also be updated to work with the corrected linking approach:\n"
  211. " cmake_policy(SET CMP0003 NEW) # or cmake_policy(VERSION 2.6)\n"
  212. " link_directories(/path/to) # needed to find library B\n"
  213. " add_executable(myexe myexe.c)\n"
  214. " target_link_libraries(myexe /path/to/libA.so B)\n"
  215. "Even better, library B may be specified with a full path:\n"
  216. " add_executable(myexe myexe.c)\n"
  217. " target_link_libraries(myexe /path/to/libA.so /path/to/libB.so)\n"
  218. "When all items on the link line have known paths CMake does not check "
  219. "this policy so it has no effect.\n"
  220. "Note that the warning for this policy will be issued for at most "
  221. "one target. This avoids flooding users with messages for every "
  222. "target when setting the policy once will probably fix all targets.",
  223. 2,6,0,0, cmPolicies::WARN);
  224. this->DefinePolicy(
  225. CMP0004, "CMP0004",
  226. "Libraries linked may not have leading or trailing whitespace.",
  227. "CMake versions 2.4 and below silently removed leading and trailing "
  228. "whitespace from libraries linked with code like\n"
  229. " target_link_libraries(myexe \" A \")\n"
  230. "This could lead to subtle errors in user projects.\n"
  231. "The OLD behavior for this policy is to silently remove leading and "
  232. "trailing whitespace. "
  233. "The NEW behavior for this policy is to diagnose the existence of "
  234. "such whitespace as an error. "
  235. "The setting for this policy used when checking the library names is "
  236. "that in effect when the target is created by an add_executable or "
  237. "add_library command.",
  238. 2,6,0,0, cmPolicies::WARN);
  239. this->DefinePolicy(
  240. CMP0005, "CMP0005",
  241. "Preprocessor definition values are now escaped automatically.",
  242. "This policy determines whether or not CMake should generate escaped "
  243. "preprocessor definition values added via add_definitions. "
  244. "CMake versions 2.4 and below assumed that only trivial values would "
  245. "be given for macros in add_definitions calls. "
  246. "It did not attempt to escape non-trivial values such as string "
  247. "literals in generated build rules. "
  248. "CMake versions 2.6 and above support escaping of most values, but "
  249. "cannot assume the user has not added escapes already in an attempt to "
  250. "work around limitations in earlier versions.\n"
  251. "The OLD behavior for this policy is to place definition values given "
  252. "to add_definitions directly in the generated build rules without "
  253. "attempting to escape anything. "
  254. "The NEW behavior for this policy is to generate correct escapes "
  255. "for all native build tools automatically. "
  256. "See documentation of the COMPILE_DEFINITIONS target property for "
  257. "limitations of the escaping implementation.",
  258. 2,6,0,0, cmPolicies::WARN);
  259. this->DefinePolicy(
  260. CMP0006, "CMP0006",
  261. "Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.",
  262. "This policy determines whether the install(TARGETS) command must be "
  263. "given a BUNDLE DESTINATION when asked to install a target with the "
  264. "MACOSX_BUNDLE property set. "
  265. "CMake 2.4 and below did not distinguish application bundles from "
  266. "normal executables when installing targets. "
  267. "CMake 2.6 provides a BUNDLE option to the install(TARGETS) command "
  268. "that specifies rules specific to application bundles on the Mac. "
  269. "Projects should use this option when installing a target with the "
  270. "MACOSX_BUNDLE property set.\n"
  271. "The OLD behavior for this policy is to fall back to the RUNTIME "
  272. "DESTINATION if a BUNDLE DESTINATION is not given. "
  273. "The NEW behavior for this policy is to produce an error if a bundle "
  274. "target is installed without a BUNDLE DESTINATION.",
  275. 2,6,0,0, cmPolicies::WARN);
  276. this->DefinePolicy(
  277. CMP0007, "CMP0007",
  278. "list command no longer ignores empty elements.",
  279. "This policy determines whether the list command will "
  280. "ignore empty elements in the list. "
  281. "CMake 2.4 and below list commands ignored all empty elements"
  282. " in the list. For example, a;b;;c would have length 3 and not 4. "
  283. "The OLD behavior for this policy is to ignore empty list elements. "
  284. "The NEW behavior for this policy is to correctly count empty "
  285. "elements in a list. ",
  286. 2,6,0,0, cmPolicies::WARN);
  287. this->DefinePolicy(
  288. CMP0008, "CMP0008",
  289. "Libraries linked by full-path must have a valid library file name.",
  290. "In CMake 2.4 and below it is possible to write code like\n"
  291. " target_link_libraries(myexe /full/path/to/somelib)\n"
  292. "where \"somelib\" is supposed to be a valid library file name "
  293. "such as \"libsomelib.a\" or \"somelib.lib\". "
  294. "For Makefile generators this produces an error at build time "
  295. "because the dependency on the full path cannot be found. "
  296. "For VS IDE and Xcode generators this used to work by accident because "
  297. "CMake would always split off the library directory and ask the "
  298. "linker to search for the library by name (-lsomelib or somelib.lib). "
  299. "Despite the failure with Makefiles, some projects have code like this "
  300. "and build only with VS and/or Xcode. "
  301. "This version of CMake prefers to pass the full path directly to the "
  302. "native build tool, which will fail in this case because it does "
  303. "not name a valid library file."
  304. "\n"
  305. "This policy determines what to do with full paths that do not appear "
  306. "to name a valid library file. "
  307. "The OLD behavior for this policy is to split the library name from the "
  308. "path and ask the linker to search for it. "
  309. "The NEW behavior for this policy is to trust the given path and "
  310. "pass it directly to the native build tool unchanged.",
  311. 2,6,1,0, cmPolicies::WARN);
  312. this->DefinePolicy(
  313. CMP0009, "CMP0009",
  314. "FILE GLOB_RECURSE calls should not follow symlinks by default.",
  315. "In CMake 2.6.1 and below, FILE GLOB_RECURSE calls would follow "
  316. "through symlinks, sometimes coming up with unexpectedly large "
  317. "result sets because of symlinks to top level directories that "
  318. "contain hundreds of thousands of files."
  319. "\n"
  320. "This policy determines whether or not to follow symlinks "
  321. "encountered during a FILE GLOB_RECURSE call. "
  322. "The OLD behavior for this policy is to follow the symlinks. "
  323. "The NEW behavior for this policy is not to follow the symlinks "
  324. "by default, but only if FOLLOW_SYMLINKS is given as an additional "
  325. "argument to the FILE command.",
  326. 2,6,2,0, 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,0, cmPolicies::WARN);
  338. this->DefinePolicy(
  339. CMP0011, "CMP0011",
  340. "Included scripts do automatic cmake_policy PUSH and POP.",
  341. "In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by "
  342. "the include() and find_package() commands would affect the includer. "
  343. "Explicit invocations of cmake_policy(PUSH) and cmake_policy(POP) were "
  344. "required to isolate policy changes and protect the includer. "
  345. "While some scripts intend to affect the policies of their includer, "
  346. "most do not. "
  347. "In CMake 2.6.3 and above, include() and find_package() by default PUSH "
  348. "and POP an entry on the policy stack around an included script, "
  349. "but provide a NO_POLICY_SCOPE option to disable it. "
  350. "This policy determines whether or not to imply NO_POLICY_SCOPE for "
  351. "compatibility. "
  352. "The OLD behavior for this policy is to imply NO_POLICY_SCOPE for "
  353. "include() and find_package() commands. "
  354. "The NEW behavior for this policy is to allow the commands to do their "
  355. "default cmake_policy PUSH and POP.",
  356. 2,6,3,0, cmPolicies::WARN);
  357. this->DefinePolicy(
  358. CMP0012, "CMP0012",
  359. "if() recognizes numbers and boolean constants.",
  360. "In CMake versions 2.6.4 and lower the if() command implicitly "
  361. "dereferenced arguments corresponding to variables, even those named "
  362. "like numbers or boolean constants, except for 0 and 1. "
  363. "Numbers and 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. "
  366. "For example, the code \"if(TRUE)\" might have evaluated as false. "
  367. "Numbers such as 2 were recognized only in "
  368. "boolean expressions like \"if(NOT 2)\" (leading to false) "
  369. "but not as a single-argument like \"if(2)\" (also leading to false). "
  370. "Later versions of CMake prefer to treat numbers and boolean constants "
  371. "literally, so they should not be used as variable names."
  372. "\n"
  373. "The OLD behavior for this policy is to implicitly dereference variables "
  374. "named like numbers and boolean constants. "
  375. "The NEW behavior for this policy is to recognize numbers and "
  376. "boolean constants without dereferencing variables with such names.",
  377. 2,8,0,0, cmPolicies::WARN);
  378. this->DefinePolicy(
  379. CMP0013, "CMP0013",
  380. "Duplicate binary directories are not allowed.",
  381. "CMake 2.6.3 and below silently permitted add_subdirectory() calls "
  382. "to create the same binary directory multiple times. "
  383. "During build system generation files would be written and then "
  384. "overwritten in the build tree and could lead to strange behavior. "
  385. "CMake 2.6.4 and above explicitly detect duplicate binary directories. "
  386. "CMake 2.6.4 always considers this case an error. "
  387. "In CMake 2.8.0 and above this policy determines whether or not "
  388. "the case is an error. "
  389. "The OLD behavior for this policy is to allow duplicate binary "
  390. "directories. "
  391. "The NEW behavior for this policy is to disallow duplicate binary "
  392. "directories with an error.",
  393. 2,8,0,0, cmPolicies::WARN);
  394. this->DefinePolicy(
  395. CMP0014, "CMP0014",
  396. "Input directories must have CMakeLists.txt.",
  397. "CMake versions before 2.8 silently ignored missing CMakeLists.txt "
  398. "files in directories referenced by add_subdirectory() or subdirs(), "
  399. "treating them as if present but empty. "
  400. "In CMake 2.8.0 and above this policy determines whether or not "
  401. "the case is an error. "
  402. "The OLD behavior for this policy is to silently ignore the problem. "
  403. "The NEW behavior for this policy is to report an error.",
  404. 2,8,0,0, cmPolicies::WARN);
  405. this->DefinePolicy(
  406. CMP0015, "CMP0015",
  407. "link_directories() treats paths relative to the source dir.",
  408. "In CMake 2.8.0 and lower the link_directories() command passed relative "
  409. "paths unchanged to the linker. "
  410. "In CMake 2.8.1 and above the link_directories() command prefers to "
  411. "interpret relative paths with respect to CMAKE_CURRENT_SOURCE_DIR, "
  412. "which is consistent with include_directories() and other commands. "
  413. "The OLD behavior for this policy is to use relative paths verbatim in "
  414. "the linker command. "
  415. "The NEW behavior for this policy is to convert relative paths to "
  416. "absolute paths by appending the relative path to "
  417. "CMAKE_CURRENT_SOURCE_DIR.",
  418. 2,8,1,0, cmPolicies::WARN);
  419. this->DefinePolicy(
  420. CMP0016, "CMP0016",
  421. "target_link_libraries() reports error if its only argument "
  422. "is not a target.",
  423. "In CMake 2.8.2 and lower the target_link_libraries() command silently "
  424. "ignored if it was called with only one argument, and this argument "
  425. "wasn't a valid target. "
  426. "In CMake 2.8.3 and above it reports an error in this case.",
  427. 2,8,3,0, cmPolicies::WARN);
  428. this->DefinePolicy(
  429. CMP0017, "CMP0017",
  430. "Prefer files from the CMake module directory when including from there.",
  431. "Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e. "
  432. "located in the CMake module directory) calls include() or "
  433. "find_package(), the files located in the CMake module directory are "
  434. "preferred over the files in CMAKE_MODULE_PATH. "
  435. "This makes sure that the modules belonging to "
  436. "CMake always get those files included which they expect, and against "
  437. "which they were developed and tested. "
  438. "In all other cases, the files found in "
  439. "CMAKE_MODULE_PATH still take precedence over the ones in "
  440. "the CMake module directory. "
  441. "The OLD behaviour is to always prefer files from CMAKE_MODULE_PATH over "
  442. "files from the CMake modules directory.",
  443. 2,8,4,0, cmPolicies::WARN);
  444. this->DefinePolicy(
  445. CMP0018, "CMP0018",
  446. "Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.",
  447. "CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries "
  448. "using the value of the undocumented CMAKE_SHARED_LIBRARY_<Lang>_FLAGS "
  449. "platform variable. The variable contained platform-specific flags "
  450. "needed to compile objects for shared libraries. Typically it included "
  451. "a flag such as -fPIC for position independent code but also included "
  452. "other flags needed on certain platforms. CMake 2.8.9 and higher "
  453. "prefer instead to use the POSITION_INDEPENDENT_CODE target property to "
  454. "determine what targets should be position independent, and new "
  455. "undocumented platform variables to select flags while ignoring "
  456. "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS completely."
  457. "\n"
  458. "The default for either approach produces identical compilation flags, "
  459. "but if a project modifies CMAKE_SHARED_LIBRARY_<Lang>_FLAGS from its "
  460. "original value this policy determines which approach to use."
  461. "\n"
  462. "The OLD behavior for this policy is to ignore the "
  463. "POSITION_INDEPENDENT_CODE property for all targets and use the modified "
  464. "value of CMAKE_SHARED_LIBRARY_<Lang>_FLAGS for SHARED and MODULE "
  465. "libraries."
  466. "\n"
  467. "The NEW behavior for this policy is to ignore "
  468. "CMAKE_SHARED_LIBRARY_<Lang>_FLAGS whether it is modified or not and "
  469. "honor the POSITION_INDEPENDENT_CODE target property.",
  470. 2,8,9,0, cmPolicies::WARN);
  471. this->DefinePolicy(
  472. CMP0019, "CMP0019",
  473. "Do not re-expand variables in include and link information.",
  474. "CMake 2.8.10 and lower re-evaluated values given to the "
  475. "include_directories, link_directories, and link_libraries "
  476. "commands to expand any leftover variable references at the "
  477. "end of the configuration step. "
  478. "This was for strict compatibility with VERY early CMake versions "
  479. "because all variable references are now normally evaluated during "
  480. "CMake language processing. "
  481. "CMake 2.8.11 and higher prefer to skip the extra evaluation."
  482. "\n"
  483. "The OLD behavior for this policy is to re-evaluate the values "
  484. "for strict compatibility. "
  485. "The NEW behavior for this policy is to leave the values untouched.",
  486. 2,8,11,0, cmPolicies::WARN);
  487. this->DefinePolicy(
  488. CMP0020, "CMP0020",
  489. "Automatically link Qt executables to qtmain target on Windows.",
  490. "CMake 2.8.10 and lower required users of Qt to always specify a link "
  491. "dependency to the qtmain.lib static library manually on Windows. CMake "
  492. "2.8.11 gained the ability to evaluate generator expressions while "
  493. "determining the link dependencies from IMPORTED targets. This allows "
  494. "CMake itself to automatically link executables which link to Qt to the "
  495. "qtmain.lib library when using IMPORTED Qt targets. For applications "
  496. "already linking to qtmain.lib, this should have little impact. For "
  497. "applications which supply their own alternative WinMain implementation "
  498. "and for applications which use the QAxServer library, this automatic "
  499. "linking will need to be disabled as per the documentation."
  500. "\n"
  501. "The OLD behavior for this policy is not to link executables to "
  502. "qtmain.lib automatically when they link to the QtCore IMPORTED"
  503. "target. "
  504. "The NEW behavior for this policy is to link executables to "
  505. "qtmain.lib automatically when they link to QtCore IMPORTED target.",
  506. 2,8,11,0, cmPolicies::WARN);
  507. this->DefinePolicy(
  508. CMP0021, "CMP0021",
  509. "Fatal error on relative paths in INCLUDE_DIRECTORIES target property.",
  510. "CMake 2.8.10.2 and lower allowed the INCLUDE_DIRECTORIES target "
  511. "property to contain relative paths. The base path for such relative "
  512. "entries is not well defined. CMake 2.8.12 issues a FATAL_ERROR if the "
  513. "INCLUDE_DIRECTORIES property contains a relative path."
  514. "\n"
  515. "The OLD behavior for this policy is not to warn about relative paths in "
  516. "the INCLUDE_DIRECTORIES target property. "
  517. "The NEW behavior for this policy is to issue a FATAL_ERROR if "
  518. "INCLUDE_DIRECTORIES contains a relative path.",
  519. 2,8,11,20130516, cmPolicies::WARN);
  520. this->DefinePolicy(
  521. CMP0022, "CMP0022",
  522. "INTERFACE_LINK_LIBRARIES defines the link interface.",
  523. "CMake 2.8.11 constructed the 'link interface' of a target from "
  524. "properties matching (IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?. "
  525. "The modern way to specify config-sensitive content is to use generator "
  526. "expressions and the IMPORTED_ prefix makes uniform processing of the "
  527. "link interface with generator expressions impossible. The "
  528. "INTERFACE_LINK_LIBRARIES target property was introduced as a "
  529. "replacement in CMake 2.8.12. This new property is named consistently "
  530. "with the INTERFACE_COMPILE_DEFINITIONS, INTERFACE_INCLUDE_DIRECTORIES "
  531. "and INTERFACE_COMPILE_OPTIONS properties. For in-build targets, CMake "
  532. "will use the INTERFACE_LINK_LIBRARIES property as the source of the "
  533. "link interface only if policy CMP0022 is NEW. "
  534. "When exporting a target which has this policy set to NEW, only the "
  535. "INTERFACE_LINK_LIBRARIES property will be processed and generated for "
  536. "the IMPORTED target by default. A new option to the install(EXPORT) "
  537. "and export commands allows export of the old-style properties for "
  538. "compatibility with downstream users of CMake versions older than 2.8.12."
  539. "\n"
  540. "The OLD behavior for this policy is to ignore the "
  541. "INTERFACE_LINK_LIBRARIES property for in-build targets. "
  542. "The NEW behavior for this policy is to use the INTERFACE_LINK_LIBRARIES "
  543. "property for in-build targets, and ignore the old properties matching "
  544. "(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?.",
  545. 2,8,11,20130516, cmPolicies::WARN);
  546. }
  547. cmPolicies::~cmPolicies()
  548. {
  549. // free the policies
  550. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  551. = this->Policies.begin();
  552. for (;i != this->Policies.end(); ++i)
  553. {
  554. delete i->second;
  555. }
  556. }
  557. void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
  558. const char *idString,
  559. const char *shortDescription,
  560. const char *longDescription,
  561. unsigned int majorVersionIntroduced,
  562. unsigned int minorVersionIntroduced,
  563. unsigned int patchVersionIntroduced,
  564. unsigned int tweakVersionIntroduced,
  565. cmPolicies::PolicyStatus status)
  566. {
  567. // a policy must be unique and can only be defined once
  568. if (this->Policies.find(iD) != this->Policies.end())
  569. {
  570. cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
  571. "ID ", this->GetPolicyIDString(iD).c_str());
  572. return;
  573. }
  574. this->Policies[iD] = new cmPolicy(iD, idString,
  575. shortDescription,
  576. longDescription,
  577. majorVersionIntroduced,
  578. minorVersionIntroduced,
  579. patchVersionIntroduced,
  580. tweakVersionIntroduced,
  581. status);
  582. this->PolicyStringMap[idString] = iD;
  583. }
  584. //----------------------------------------------------------------------------
  585. bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
  586. const char *version)
  587. {
  588. std::string ver = "2.4.0";
  589. if (version && strlen(version) > 0)
  590. {
  591. ver = version;
  592. }
  593. unsigned int majorVer = 2;
  594. unsigned int minorVer = 0;
  595. unsigned int patchVer = 0;
  596. unsigned int tweakVer = 0;
  597. // parse the string
  598. if(sscanf(ver.c_str(), "%u.%u.%u.%u",
  599. &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
  600. {
  601. cmOStringStream e;
  602. e << "Invalid policy version value \"" << ver << "\". "
  603. << "A numeric major.minor[.patch[.tweak]] must be given.";
  604. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  605. return false;
  606. }
  607. // it is an error if the policy version is less than 2.4
  608. if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
  609. {
  610. mf->IssueMessage(cmake::FATAL_ERROR,
  611. "An attempt was made to set the policy version of CMake to something "
  612. "earlier than \"2.4\". "
  613. "In CMake 2.4 and below backwards compatibility was handled with the "
  614. "CMAKE_BACKWARDS_COMPATIBILITY variable. "
  615. "In order to get compatibility features supporting versions earlier "
  616. "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
  617. "CMAKE_BACKWARDS_COMPATIBILITY variable. "
  618. "One way to do this is to set the policy version to 2.4 exactly."
  619. );
  620. return false;
  621. }
  622. // It is an error if the policy version is greater than the running
  623. // CMake.
  624. if (majorVer > cmVersion::GetMajorVersion() ||
  625. (majorVer == cmVersion::GetMajorVersion() &&
  626. minorVer > cmVersion::GetMinorVersion()) ||
  627. (majorVer == cmVersion::GetMajorVersion() &&
  628. minorVer == cmVersion::GetMinorVersion() &&
  629. patchVer > cmVersion::GetPatchVersion()) ||
  630. (majorVer == cmVersion::GetMajorVersion() &&
  631. minorVer == cmVersion::GetMinorVersion() &&
  632. patchVer == cmVersion::GetPatchVersion() &&
  633. tweakVer > cmVersion::GetTweakVersion()))
  634. {
  635. cmOStringStream e;
  636. e << "An attempt was made to set the policy version of CMake to \""
  637. << version << "\" which is greater than this version of CMake. "
  638. << "This is not allowed because the greater version may have new "
  639. << "policies not known to this CMake. "
  640. << "You may need a newer CMake version to build this project.";
  641. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  642. return false;
  643. }
  644. // now loop over all the policies and set them as appropriate
  645. std::vector<cmPolicies::PolicyID> ancientPolicies;
  646. for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  647. = this->Policies.begin(); i != this->Policies.end(); ++i)
  648. {
  649. if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
  650. {
  651. if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
  652. {
  653. ancientPolicies.push_back(i->first);
  654. }
  655. else
  656. {
  657. cmPolicies::PolicyStatus status = cmPolicies::WARN;
  658. if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
  659. !mf->SetPolicy(i->second->ID, status))
  660. {
  661. return false;
  662. }
  663. }
  664. }
  665. else
  666. {
  667. if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
  668. {
  669. return false;
  670. }
  671. }
  672. }
  673. // Make sure the project does not use any ancient policies.
  674. if(!ancientPolicies.empty())
  675. {
  676. this->DiagnoseAncientPolicies(ancientPolicies,
  677. majorVer, minorVer, patchVer, mf);
  678. cmSystemTools::SetFatalErrorOccured();
  679. return false;
  680. }
  681. return true;
  682. }
  683. //----------------------------------------------------------------------------
  684. bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
  685. cmPolicies::PolicyStatus* defaultSetting)
  686. {
  687. std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
  688. std::string defaultValue = mf->GetSafeDefinition(defaultVar.c_str());
  689. if(defaultValue == "NEW")
  690. {
  691. *defaultSetting = cmPolicies::NEW;
  692. }
  693. else if(defaultValue == "OLD")
  694. {
  695. *defaultSetting = cmPolicies::OLD;
  696. }
  697. else if(defaultValue == "")
  698. {
  699. *defaultSetting = cmPolicies::WARN;
  700. }
  701. else
  702. {
  703. cmOStringStream e;
  704. e << defaultVar << " has value \"" << defaultValue
  705. << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
  706. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  707. return false;
  708. }
  709. return true;
  710. }
  711. bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
  712. {
  713. if (!id || strlen(id) < 1)
  714. {
  715. return false;
  716. }
  717. std::map<std::string,cmPolicies::PolicyID>::iterator pos =
  718. this->PolicyStringMap.find(id);
  719. if (pos == this->PolicyStringMap.end())
  720. {
  721. return false;
  722. }
  723. pid = pos->second;
  724. return true;
  725. }
  726. std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
  727. {
  728. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  729. this->Policies.find(pid);
  730. if (pos == this->Policies.end())
  731. {
  732. return "";
  733. }
  734. return pos->second->IDString;
  735. }
  736. ///! return a warning string for a given policy
  737. std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
  738. {
  739. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  740. this->Policies.find(id);
  741. if (pos == this->Policies.end())
  742. {
  743. cmSystemTools::Error(
  744. "Request for warning text for undefined policy!");
  745. return "Request for warning text for undefined policy!";
  746. }
  747. cmOStringStream msg;
  748. msg <<
  749. "Policy " << pos->second->IDString << " is not set: "
  750. "" << pos->second->ShortDescription << " "
  751. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  752. "policy details. "
  753. "Use the cmake_policy command to set the policy "
  754. "and suppress this warning.";
  755. return msg.str();
  756. }
  757. ///! return an error string for when a required policy is unspecified
  758. std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
  759. {
  760. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  761. this->Policies.find(id);
  762. if (pos == this->Policies.end())
  763. {
  764. cmSystemTools::Error(
  765. "Request for error text for undefined policy!");
  766. return "Request for error text for undefined policy!";
  767. }
  768. cmOStringStream error;
  769. error <<
  770. "Policy " << pos->second->IDString << " is not set to NEW: "
  771. "" << pos->second->ShortDescription << " "
  772. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  773. "policy details. "
  774. "CMake now requires this policy to be set to NEW by the project. "
  775. "The policy may be set explicitly using the code\n"
  776. " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
  777. "or by upgrading all policies with the code\n"
  778. " cmake_policy(VERSION " << pos->second->GetVersionString() <<
  779. ") # or later\n"
  780. "Run \"cmake --help-command cmake_policy\" for more information.";
  781. return error.str();
  782. }
  783. ///! Get the default status for a policy
  784. cmPolicies::PolicyStatus
  785. cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
  786. {
  787. // if the policy is not know then what?
  788. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  789. this->Policies.find(id);
  790. if (pos == this->Policies.end())
  791. {
  792. // TODO is this right?
  793. return cmPolicies::WARN;
  794. }
  795. return pos->second->Status;
  796. }
  797. void cmPolicies::GetDocumentation(std::vector<cmDocumentationEntry>& v)
  798. {
  799. // now loop over all the policies and set them as appropriate
  800. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  801. = this->Policies.begin();
  802. for (;i != this->Policies.end(); ++i)
  803. {
  804. cmOStringStream full;
  805. full << i->second->LongDescription;
  806. full << "\nThis policy was introduced in CMake version ";
  807. full << i->second->GetVersionString() << ".";
  808. if(i->first != cmPolicies::CMP0000)
  809. {
  810. full << " "
  811. << "CMake version " << cmVersion::GetCMakeVersion() << " ";
  812. // add in some more text here based on status
  813. switch (i->second->Status)
  814. {
  815. case cmPolicies::WARN:
  816. full << "warns when the policy is not set and uses OLD behavior. "
  817. << "Use the cmake_policy command to set it to OLD or NEW "
  818. << "explicitly.";
  819. break;
  820. case cmPolicies::OLD:
  821. full << "defaults to the OLD behavior for this policy.";
  822. break;
  823. case cmPolicies::NEW:
  824. full << "defaults to the NEW behavior for this policy.";
  825. break;
  826. case cmPolicies::REQUIRED_IF_USED:
  827. full << "requires the policy to be set to NEW if you use it. "
  828. << "Use the cmake_policy command to set it to NEW.";
  829. break;
  830. case cmPolicies::REQUIRED_ALWAYS:
  831. full << "requires the policy to be set to NEW. "
  832. << "Use the cmake_policy command to set it to NEW.";
  833. break;
  834. }
  835. }
  836. cmDocumentationEntry e(i->second->IDString.c_str(),
  837. i->second->ShortDescription.c_str(),
  838. full.str().c_str());
  839. v.push_back(e);
  840. }
  841. }
  842. //----------------------------------------------------------------------------
  843. std::string
  844. cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
  845. {
  846. std::string pid = this->GetPolicyIDString(id);
  847. cmOStringStream e;
  848. e << "Policy " << pid << " may not be set to OLD behavior because this "
  849. << "version of CMake no longer supports it. "
  850. << "The policy was introduced in "
  851. << "CMake version " << this->Policies[id]->GetVersionString()
  852. << ", and use of NEW behavior is now required."
  853. << "\n"
  854. << "Please either update your CMakeLists.txt files to conform to "
  855. << "the new behavior or use an older version of CMake that still "
  856. << "supports the old behavior. "
  857. << "Run cmake --help-policy " << pid << " for more information.";
  858. return e.str();
  859. }
  860. //----------------------------------------------------------------------------
  861. void
  862. cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
  863. unsigned int majorVer,
  864. unsigned int minorVer,
  865. unsigned int patchVer,
  866. cmMakefile* mf)
  867. {
  868. cmOStringStream e;
  869. e << "The project requests behavior compatible with CMake version \""
  870. << majorVer << "." << minorVer << "." << patchVer
  871. << "\", which requires the OLD behavior for some policies:\n";
  872. for(std::vector<PolicyID>::const_iterator
  873. i = ancient.begin(); i != ancient.end(); ++i)
  874. {
  875. cmPolicy const* policy = this->Policies[*i];
  876. e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
  877. }
  878. e << "However, this version of CMake no longer supports the OLD "
  879. << "behavior for these policies. "
  880. << "Please either update your CMakeLists.txt files to conform to "
  881. << "the new behavior or use an older version of CMake that still "
  882. << "supports the old behavior.";
  883. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  884. }