cmPolicies.cxx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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,12,0, 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 "
  539. "2.8.12. "
  540. "The target_link_libraries command will no longer populate the "
  541. "properties matching LINK_INTERFACE_LIBRARIES(_<CONFIG>)? if this policy "
  542. "is NEW."
  543. "\n"
  544. "The OLD behavior for this policy is to ignore the "
  545. "INTERFACE_LINK_LIBRARIES property for in-build targets. "
  546. "The NEW behavior for this policy is to use the INTERFACE_LINK_LIBRARIES "
  547. "property for in-build targets, and ignore the old properties matching "
  548. "(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?.",
  549. 2,8,12,0, cmPolicies::WARN);
  550. this->DefinePolicy(
  551. CMP0023, "CMP0023",
  552. "Plain and keyword target_link_libraries signatures cannot be mixed.",
  553. "CMake 2.8.12 introduced the target_link_libraries signature using "
  554. "the PUBLIC, PRIVATE, and INTERFACE keywords to generalize the "
  555. "LINK_PUBLIC and LINK_PRIVATE keywords introduced in CMake 2.8.7. "
  556. "Use of signatures with any of these keywords sets the link interface "
  557. "of a target explicitly, even if empty. "
  558. "This produces confusing behavior when used in combination with the "
  559. "historical behavior of the plain target_link_libraries signature. "
  560. "For example, consider the code:\n"
  561. " target_link_libraries(mylib A)\n"
  562. " target_link_libraries(mylib PRIVATE B)\n"
  563. "After the first line the link interface has not been set explicitly "
  564. "so CMake would use the link implementation, A, as the link interface. "
  565. "However, the second line sets the link interface to empty. "
  566. "In order to avoid this subtle behavior CMake now prefers to disallow "
  567. "mixing the plain and keyword signatures of target_link_libraries for "
  568. "a single target."
  569. "\n"
  570. "The OLD behavior for this policy is to allow keyword and plain "
  571. "target_link_libraries signatures to be mixed. "
  572. "The NEW behavior for this policy is to not to allow mixing of the "
  573. "keyword and plain signatures.",
  574. 2,8,12,0, cmPolicies::WARN);
  575. this->DefinePolicy(
  576. CMP0024, "CMP0024",
  577. "Disallow include export result.",
  578. "CMake 2.8.12 and lower allowed use of the include() command with the "
  579. "result of the export() command. This relies on the assumption that "
  580. "the export() command has an immediate effect at configure-time during a "
  581. "cmake run. Certain properties of targets are not fully determined "
  582. "until later at generate-time, such as the link language and complete "
  583. "list of link libraries. Future refactoring will change the effect of "
  584. "the export() command to be executed at generate-time. Use ALIAS "
  585. "targets instead in cases where the goal is to refer to targets by "
  586. "another name"
  587. "\n"
  588. "The OLD behavior for this policy is to allow including the result "
  589. "of an export() command. "
  590. "The NEW behavior for this policy is to not to allow including the "
  591. "result of an export() command.",
  592. 2,8,13,0, cmPolicies::WARN);
  593. }
  594. cmPolicies::~cmPolicies()
  595. {
  596. // free the policies
  597. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  598. = this->Policies.begin();
  599. for (;i != this->Policies.end(); ++i)
  600. {
  601. delete i->second;
  602. }
  603. }
  604. void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD,
  605. const char *idString,
  606. const char *shortDescription,
  607. const char *longDescription,
  608. unsigned int majorVersionIntroduced,
  609. unsigned int minorVersionIntroduced,
  610. unsigned int patchVersionIntroduced,
  611. unsigned int tweakVersionIntroduced,
  612. cmPolicies::PolicyStatus status)
  613. {
  614. // a policy must be unique and can only be defined once
  615. if (this->Policies.find(iD) != this->Policies.end())
  616. {
  617. cmSystemTools::Error("Attempt to redefine a CMake policy for policy "
  618. "ID ", this->GetPolicyIDString(iD).c_str());
  619. return;
  620. }
  621. this->Policies[iD] = new cmPolicy(iD, idString,
  622. shortDescription,
  623. longDescription,
  624. majorVersionIntroduced,
  625. minorVersionIntroduced,
  626. patchVersionIntroduced,
  627. tweakVersionIntroduced,
  628. status);
  629. this->PolicyStringMap[idString] = iD;
  630. }
  631. //----------------------------------------------------------------------------
  632. bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
  633. const char *version)
  634. {
  635. std::string ver = "2.4.0";
  636. if (version && strlen(version) > 0)
  637. {
  638. ver = version;
  639. }
  640. unsigned int majorVer = 2;
  641. unsigned int minorVer = 0;
  642. unsigned int patchVer = 0;
  643. unsigned int tweakVer = 0;
  644. // parse the string
  645. if(sscanf(ver.c_str(), "%u.%u.%u.%u",
  646. &majorVer, &minorVer, &patchVer, &tweakVer) < 2)
  647. {
  648. cmOStringStream e;
  649. e << "Invalid policy version value \"" << ver << "\". "
  650. << "A numeric major.minor[.patch[.tweak]] must be given.";
  651. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  652. return false;
  653. }
  654. // it is an error if the policy version is less than 2.4
  655. if (majorVer < 2 || (majorVer == 2 && minorVer < 4))
  656. {
  657. mf->IssueMessage(cmake::FATAL_ERROR,
  658. "An attempt was made to set the policy version of CMake to something "
  659. "earlier than \"2.4\". "
  660. "In CMake 2.4 and below backwards compatibility was handled with the "
  661. "CMAKE_BACKWARDS_COMPATIBILITY variable. "
  662. "In order to get compatibility features supporting versions earlier "
  663. "than 2.4 set policy CMP0001 to OLD to tell CMake to check the "
  664. "CMAKE_BACKWARDS_COMPATIBILITY variable. "
  665. "One way to do this is to set the policy version to 2.4 exactly."
  666. );
  667. return false;
  668. }
  669. // It is an error if the policy version is greater than the running
  670. // CMake.
  671. if (majorVer > cmVersion::GetMajorVersion() ||
  672. (majorVer == cmVersion::GetMajorVersion() &&
  673. minorVer > cmVersion::GetMinorVersion()) ||
  674. (majorVer == cmVersion::GetMajorVersion() &&
  675. minorVer == cmVersion::GetMinorVersion() &&
  676. patchVer > cmVersion::GetPatchVersion()) ||
  677. (majorVer == cmVersion::GetMajorVersion() &&
  678. minorVer == cmVersion::GetMinorVersion() &&
  679. patchVer == cmVersion::GetPatchVersion() &&
  680. tweakVer > cmVersion::GetTweakVersion()))
  681. {
  682. cmOStringStream e;
  683. e << "An attempt was made to set the policy version of CMake to \""
  684. << version << "\" which is greater than this version of CMake. "
  685. << "This is not allowed because the greater version may have new "
  686. << "policies not known to this CMake. "
  687. << "You may need a newer CMake version to build this project.";
  688. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  689. return false;
  690. }
  691. // now loop over all the policies and set them as appropriate
  692. std::vector<cmPolicies::PolicyID> ancientPolicies;
  693. for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  694. = this->Policies.begin(); i != this->Policies.end(); ++i)
  695. {
  696. if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
  697. {
  698. if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
  699. {
  700. ancientPolicies.push_back(i->first);
  701. }
  702. else
  703. {
  704. cmPolicies::PolicyStatus status = cmPolicies::WARN;
  705. if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
  706. !mf->SetPolicy(i->second->ID, status))
  707. {
  708. return false;
  709. }
  710. }
  711. }
  712. else
  713. {
  714. if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
  715. {
  716. return false;
  717. }
  718. }
  719. }
  720. // Make sure the project does not use any ancient policies.
  721. if(!ancientPolicies.empty())
  722. {
  723. this->DiagnoseAncientPolicies(ancientPolicies,
  724. majorVer, minorVer, patchVer, mf);
  725. cmSystemTools::SetFatalErrorOccured();
  726. return false;
  727. }
  728. return true;
  729. }
  730. //----------------------------------------------------------------------------
  731. bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
  732. cmPolicies::PolicyStatus* defaultSetting)
  733. {
  734. std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
  735. std::string defaultValue = mf->GetSafeDefinition(defaultVar.c_str());
  736. if(defaultValue == "NEW")
  737. {
  738. *defaultSetting = cmPolicies::NEW;
  739. }
  740. else if(defaultValue == "OLD")
  741. {
  742. *defaultSetting = cmPolicies::OLD;
  743. }
  744. else if(defaultValue == "")
  745. {
  746. *defaultSetting = cmPolicies::WARN;
  747. }
  748. else
  749. {
  750. cmOStringStream e;
  751. e << defaultVar << " has value \"" << defaultValue
  752. << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
  753. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  754. return false;
  755. }
  756. return true;
  757. }
  758. bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
  759. {
  760. if (!id || strlen(id) < 1)
  761. {
  762. return false;
  763. }
  764. std::map<std::string,cmPolicies::PolicyID>::iterator pos =
  765. this->PolicyStringMap.find(id);
  766. if (pos == this->PolicyStringMap.end())
  767. {
  768. return false;
  769. }
  770. pid = pos->second;
  771. return true;
  772. }
  773. std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid)
  774. {
  775. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  776. this->Policies.find(pid);
  777. if (pos == this->Policies.end())
  778. {
  779. return "";
  780. }
  781. return pos->second->IDString;
  782. }
  783. ///! return a warning string for a given policy
  784. std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
  785. {
  786. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  787. this->Policies.find(id);
  788. if (pos == this->Policies.end())
  789. {
  790. cmSystemTools::Error(
  791. "Request for warning text for undefined policy!");
  792. return "Request for warning text for undefined policy!";
  793. }
  794. cmOStringStream msg;
  795. msg <<
  796. "Policy " << pos->second->IDString << " is not set: "
  797. "" << pos->second->ShortDescription << " "
  798. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  799. "policy details. "
  800. "Use the cmake_policy command to set the policy "
  801. "and suppress this warning.";
  802. return msg.str();
  803. }
  804. ///! return an error string for when a required policy is unspecified
  805. std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
  806. {
  807. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  808. this->Policies.find(id);
  809. if (pos == this->Policies.end())
  810. {
  811. cmSystemTools::Error(
  812. "Request for error text for undefined policy!");
  813. return "Request for error text for undefined policy!";
  814. }
  815. cmOStringStream error;
  816. error <<
  817. "Policy " << pos->second->IDString << " is not set to NEW: "
  818. "" << pos->second->ShortDescription << " "
  819. "Run \"cmake --help-policy " << pos->second->IDString << "\" for "
  820. "policy details. "
  821. "CMake now requires this policy to be set to NEW by the project. "
  822. "The policy may be set explicitly using the code\n"
  823. " cmake_policy(SET " << pos->second->IDString << " NEW)\n"
  824. "or by upgrading all policies with the code\n"
  825. " cmake_policy(VERSION " << pos->second->GetVersionString() <<
  826. ") # or later\n"
  827. "Run \"cmake --help-command cmake_policy\" for more information.";
  828. return error.str();
  829. }
  830. ///! Get the default status for a policy
  831. cmPolicies::PolicyStatus
  832. cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id)
  833. {
  834. // if the policy is not know then what?
  835. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator pos =
  836. this->Policies.find(id);
  837. if (pos == this->Policies.end())
  838. {
  839. // TODO is this right?
  840. return cmPolicies::WARN;
  841. }
  842. return pos->second->Status;
  843. }
  844. void cmPolicies::GetDocumentation(std::vector<cmDocumentationEntry>& v)
  845. {
  846. // now loop over all the policies and set them as appropriate
  847. std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
  848. = this->Policies.begin();
  849. for (;i != this->Policies.end(); ++i)
  850. {
  851. cmOStringStream full;
  852. full << i->second->LongDescription;
  853. full << "\nThis policy was introduced in CMake version ";
  854. full << i->second->GetVersionString() << ".";
  855. if(i->first != cmPolicies::CMP0000)
  856. {
  857. full << " "
  858. << "CMake version " << cmVersion::GetCMakeVersion() << " ";
  859. // add in some more text here based on status
  860. switch (i->second->Status)
  861. {
  862. case cmPolicies::WARN:
  863. full << "warns when the policy is not set and uses OLD behavior. "
  864. << "Use the cmake_policy command to set it to OLD or NEW "
  865. << "explicitly.";
  866. break;
  867. case cmPolicies::OLD:
  868. full << "defaults to the OLD behavior for this policy.";
  869. break;
  870. case cmPolicies::NEW:
  871. full << "defaults to the NEW behavior for this policy.";
  872. break;
  873. case cmPolicies::REQUIRED_IF_USED:
  874. full << "requires the policy to be set to NEW if you use it. "
  875. << "Use the cmake_policy command to set it to NEW.";
  876. break;
  877. case cmPolicies::REQUIRED_ALWAYS:
  878. full << "requires the policy to be set to NEW. "
  879. << "Use the cmake_policy command to set it to NEW.";
  880. break;
  881. }
  882. }
  883. cmDocumentationEntry e(i->second->IDString.c_str(),
  884. i->second->ShortDescription.c_str(),
  885. full.str().c_str());
  886. v.push_back(e);
  887. }
  888. }
  889. //----------------------------------------------------------------------------
  890. std::string
  891. cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id)
  892. {
  893. std::string pid = this->GetPolicyIDString(id);
  894. cmOStringStream e;
  895. e << "Policy " << pid << " may not be set to OLD behavior because this "
  896. << "version of CMake no longer supports it. "
  897. << "The policy was introduced in "
  898. << "CMake version " << this->Policies[id]->GetVersionString()
  899. << ", and use of NEW behavior is now required."
  900. << "\n"
  901. << "Please either update your CMakeLists.txt files to conform to "
  902. << "the new behavior or use an older version of CMake that still "
  903. << "supports the old behavior. "
  904. << "Run cmake --help-policy " << pid << " for more information.";
  905. return e.str();
  906. }
  907. //----------------------------------------------------------------------------
  908. void
  909. cmPolicies::DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
  910. unsigned int majorVer,
  911. unsigned int minorVer,
  912. unsigned int patchVer,
  913. cmMakefile* mf)
  914. {
  915. cmOStringStream e;
  916. e << "The project requests behavior compatible with CMake version \""
  917. << majorVer << "." << minorVer << "." << patchVer
  918. << "\", which requires the OLD behavior for some policies:\n";
  919. for(std::vector<PolicyID>::const_iterator
  920. i = ancient.begin(); i != ancient.end(); ++i)
  921. {
  922. cmPolicy const* policy = this->Policies[*i];
  923. e << " " << policy->IDString << ": " << policy->ShortDescription << "\n";
  924. }
  925. e << "However, this version of CMake no longer supports the OLD "
  926. << "behavior for these policies. "
  927. << "Please either update your CMakeLists.txt files to conform to "
  928. << "the new behavior or use an older version of CMake that still "
  929. << "supports the old behavior.";
  930. mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  931. }