cmFindPackageCommand.cxx 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmFindPackageCommand.h"
  14. #include <cmsys/RegularExpression.hxx>
  15. #ifdef CMAKE_BUILD_WITH_CMAKE
  16. #include "cmVariableWatch.h"
  17. #endif
  18. void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
  19. int access_type, void*, const char* newValue,
  20. const cmMakefile*)
  21. {
  22. (void)newValue;
  23. #ifdef CMAKE_BUILD_WITH_CMAKE
  24. if(access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  25. {
  26. std::string message = "An attempt was made to access a variable: ";
  27. message += variable;
  28. message +=
  29. " that has not been defined. This variable is created by the "
  30. "FIND_PACKAGE command. CMake version 1.6 always converted the "
  31. "variable name to upper-case, but this behavior is no longer the "
  32. "case. To fix this you might need to set the cache value of "
  33. "CMAKE_BACKWARDS_COMPATIBILITY to 1.6 or less. If you are writing a "
  34. "CMake listfile, you should change the variable reference to use "
  35. "the case of the argument to FIND_PACKAGE.";
  36. cmSystemTools::Error(message.c_str());
  37. }
  38. #else
  39. (void)variable;
  40. (void)access_type;
  41. #endif
  42. }
  43. //----------------------------------------------------------------------------
  44. cmFindPackageCommand::cmFindPackageCommand()
  45. {
  46. cmSystemTools::ReplaceString(this->GenericDocumentationRootPath,
  47. "CMAKE_FIND_ROOT_PATH_MODE_XXX",
  48. "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE");
  49. cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
  50. "FIND_ARGS_XXX", "<package>");
  51. cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
  52. "FIND_XXX", "find_package");
  53. this->CMakePathName = "PACKAGE";
  54. this->Quiet = false;
  55. this->Required = false;
  56. this->NoBuilds = false;
  57. this->NoModule = false;
  58. this->DebugMode = false;
  59. this->VersionMajor = 0;
  60. this->VersionMinor = 0;
  61. this->VersionPatch = 0;
  62. this->VersionCount = 0;
  63. this->VersionExact = false;
  64. this->VersionFoundMajor = 0;
  65. this->VersionFoundMinor = 0;
  66. this->VersionFoundPatch = 0;
  67. this->VersionFoundCount = 0;
  68. this->CommandDocumentation =
  69. " find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]\n"
  70. " [[REQUIRED|COMPONENTS] [components...]])\n"
  71. "Finds and loads settings from an external project. "
  72. "<package>_FOUND will be set to indicate whether the package was found. "
  73. "When the package is found package-specific information is provided "
  74. "through variables documented by the package itself. "
  75. "The QUIET option disables messages if the package cannot be found. "
  76. "The REQUIRED option stops processing with an error message if the "
  77. "package cannot be found. "
  78. "A package-specific list of components may be listed after the "
  79. "REQUIRED option or after the COMPONENTS option if no REQUIRED "
  80. "option is given. "
  81. "The \"[major[.minor[.patch]]]\" version argument specifies a desired "
  82. "version with which the package found should be compatible. "
  83. "The EXACT option requests that the version be matched exactly. "
  84. "Version support is currently provided only on a package-by-package "
  85. "basis (details below).\n"
  86. "User code should generally look for packages using the above simple "
  87. "signature. The remainder of this command documentation specifies the "
  88. "full command signature and details of the search process. Project "
  89. "maintainers wishing to provide a package to be found by this command "
  90. "are encouraged to read on.\n"
  91. "The command has two modes by which it searches for packages: "
  92. "\"Module\" mode and \"Config\" mode. "
  93. "Module mode is available when the command is invoked with the above "
  94. "reduced signature. "
  95. "CMake searches for a file called \"Find<package>.cmake\" in "
  96. "the CMAKE_MODULE_PATH followed by the CMake installation. "
  97. "If the file is found, it is read and processed by CMake. "
  98. "It is responsible for finding the package, checking the version, "
  99. "and producing any needed messages. "
  100. "Many find-modules provide limited or no support for versioning; "
  101. "check the module documentation. "
  102. "If no module is found the command proceeds to Config mode.\n"
  103. "The complete Config mode command signature is:\n"
  104. " find_package(<package> [major[.minor[.patch]]] [EXACT] [QUIET]\n"
  105. " [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
  106. " [NAMES name1 [name2 ...]]\n"
  107. " [CONFIGS config1 [config2 ...]]\n"
  108. " [PATHS path1 [path2 ... ]]\n"
  109. " [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
  110. " [NO_DEFAULT_PATH]\n"
  111. " [NO_CMAKE_ENVIRONMENT_PATH]\n"
  112. " [NO_CMAKE_PATH]\n"
  113. " [NO_SYSTEM_ENVIRONMENT_PATH]\n"
  114. " [NO_CMAKE_BUILDS_PATH]\n"
  115. " [NO_CMAKE_SYSTEM_PATH]\n"
  116. " [CMAKE_FIND_ROOT_PATH_BOTH |\n"
  117. " ONLY_CMAKE_FIND_ROOT_PATH |\n"
  118. " NO_CMAKE_FIND_ROOT_PATH])\n"
  119. "The NO_MODULE option may be used to skip Module mode explicitly. "
  120. "It is also implied by use of options not specified in the reduced "
  121. "signature. "
  122. "\n"
  123. "Config mode attempts to locate a configuration file provided by the "
  124. "package to be found. A cache entry called <package>_DIR is created to "
  125. "hold the directory containing the file. "
  126. "By default the command searches for a package with the name <package>. "
  127. "If the NAMES option is given the names following it are used instead "
  128. "of <package>. "
  129. "The command searches for a file called \"<name>Config.cmake\" or "
  130. "\"<lower-case-name>-config.cmake\" for each name specified. "
  131. "A replacement set of possible configuration file names may be given "
  132. "using the CONFIGS option. "
  133. "The search procedure is specified below. Once found, the configuration "
  134. "file is read and processed by CMake. Since the file is provided by the "
  135. "package it already knows the location of package contents. "
  136. "The full path to the configuration file is stored in the cmake "
  137. "variable <package>_CONFIG."
  138. "\n"
  139. "If the package configuration file cannot be found CMake "
  140. "will generate an error describing the problem unless the QUIET "
  141. "argument is specified. If REQUIRED is specified and the package "
  142. "is not found a fatal error is generated and the configure step stops "
  143. "executing. If <package>_DIR has been set to a directory not containing "
  144. "a configuration file a fatal error is always generated because user "
  145. "intervention is required."
  146. "\n"
  147. "When the \"[major[.minor[.patch]]]\" version argument is specified "
  148. "Config mode will only find a version of the package that claims "
  149. "compatibility with the requested version. "
  150. "If the EXACT option is given only a version of the package claiming "
  151. "an exact match of the requested version may be found. "
  152. "CMake does not establish any convention for the meaning of version "
  153. "numbers. "
  154. "Package version numbers are checked by \"version\" files provided by "
  155. "the packages themselves. "
  156. "For a candidate package confguration file \"<config-file>.cmake\" the "
  157. "corresponding version file is located next to it and named either "
  158. "\"<config-file>-version.cmake\" or \"<config-file>Version.cmake\". "
  159. "If no such version file is available then the configuration file "
  160. "is assumed to not be compatible with any requested version. "
  161. "When a version file is found it is loaded to check the requested "
  162. "version number. "
  163. "The version file is loaded in a nested scope in which the following "
  164. "variables have been defined:\n"
  165. " PACKAGE_FIND_NAME = the <package> name\n"
  166. " PACKAGE_FIND_VERSION = full requested version string\n"
  167. " PACKAGE_FIND_VERSION_MAJOR = requested major version, if any\n"
  168. " PACKAGE_FIND_VERSION_MINOR = requested minor version, if any\n"
  169. " PACKAGE_FIND_VERSION_PATCH = requested patch version, if any\n"
  170. "The version file checks whether it satisfies the requested version "
  171. "and sets these variables:\n"
  172. " PACKAGE_VERSION = package version (major[.minor[.patch]])\n"
  173. " PACKAGE_VERSION_EXACT = true if version is exact match\n"
  174. " PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n"
  175. "These variables are checked by the find_package command to determine "
  176. "whether the configuration file provides an acceptable version. "
  177. "They are not available after the find_package call returns. "
  178. "If the version is acceptable the following variables are set:\n"
  179. " <package>_VERSION = package version (major[.minor[.patch]])\n"
  180. " <package>_VERSION_MAJOR = major from major[.minor[.patch]], if any\n"
  181. " <package>_VERSION_MINOR = minor from major[.minor[.patch]], if any\n"
  182. " <package>_VERSION_PATCH = patch from major[.minor[.patch]], if any\n"
  183. "and the corresponding package configuration file is loaded. "
  184. "When multiple package configuration files are available whose version "
  185. "files claim compatibility with the version requested it is unspecified "
  186. "which one is chosen. "
  187. "No attempt is made to choose a highest or closest version number."
  188. "\n"
  189. "Config mode provides an elaborate interface and search procedure. "
  190. "Much of the interface is provided for completeness and for use "
  191. "internally by find-modules loaded by Module mode. "
  192. "Most user code should simply call\n"
  193. " find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])\n"
  194. "in order to find a package. Package maintainers providing CMake "
  195. "package configuration files are encouraged to name and install "
  196. "them such that the procedure outlined below will find them "
  197. "without requiring use of additional options."
  198. "\n"
  199. "CMake constructs a set of possible installation prefixes for the "
  200. "package. Under each prefix several directories are searched for a "
  201. "configuration file. The tables below show the directories searched. "
  202. "Each entry is meant for installation trees following Windows (W), "
  203. "UNIX (U), or Apple (A) conventions.\n"
  204. " <prefix>/ (W)\n"
  205. " <prefix>/(cmake|CMake)/ (W)\n"
  206. " <prefix>/(share|lib)/<name>*/ (U)\n"
  207. " <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)\n"
  208. "On systems supporting OS X Frameworks and Application Bundles "
  209. "the following directories are searched for frameworks or bundles "
  210. "containing a configuration file:\n"
  211. " <prefix>/<name>.framework/Resources/ (A)\n"
  212. " <prefix>/<name>.framework/Resources/CMake/ (A)\n"
  213. " <prefix>/<name>.framework/Versions/*/Resources/ (A)\n"
  214. " <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)\n"
  215. " <prefix>/<name>.app/Contents/Resources/ (A)\n"
  216. " <prefix>/<name>.app/Contents/Resources/CMake/ (A)\n"
  217. "In all cases the <name> is treated as case-insensitive and corresponds "
  218. "to any of the names specified (<package> or names given by NAMES). "
  219. "If PATH_SUFFIXES is specified the suffixes are appended to each "
  220. "(W) or (U) directory entry one-by-one.\n"
  221. "This set of directories is intended to work in cooperation with "
  222. "projects that provide configuration files in their installation trees. "
  223. "Directories above marked with (W) are intended for installations on "
  224. "Windows where the prefix may point at the top of an application's "
  225. "installation directory. Those marked with (U) are intended for "
  226. "installations on UNIX platforms where the prefix is shared by "
  227. "multiple packages. This is merely a convention, so all (W) and (U) "
  228. "directories are still searched on all platforms. "
  229. "Directories marked with (A) are intended for installations on "
  230. "Apple platforms. The cmake variables CMAKE_FIND_FRAMEWORK and "
  231. "CMAKE_FIND_APPBUNDLE determine the order of preference "
  232. "as specified below.\n"
  233. "The set of installation prefixes is constructed using the following "
  234. "steps. If NO_DEFAULT_PATH is specified steps 1-5 are skipped.\n"
  235. "1. Search cmake specific environment variables. This "
  236. "can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
  237. " CMAKE_PREFIX_PATH\n"
  238. " CMAKE_FRAMEWORK_PATH\n"
  239. " CMAKE_APPBUNDLE_PATH\n"
  240. "2. Search cmake variables with the same names as the cmake specific "
  241. "environment variables. These are intended to be used on the command "
  242. "line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH "
  243. "is passed.\n"
  244. " CMAKE_PREFIX_PATH\n"
  245. " CMAKE_FRAMEWORK_PATH\n"
  246. " CMAKE_APPBUNDLE_PATH\n"
  247. "3. Search the standard system environment variables. "
  248. "This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. "
  249. "Path entries ending in \"/bin\" or \"/sbin\" are automatically "
  250. "converted to their parent directories.\n"
  251. " PATH\n"
  252. "4. Search project build trees recently configured in a CMake GUI. "
  253. "This can be skipped if NO_CMAKE_BUILDS_PATH is passed. "
  254. "It is intended for the case when a user is building multiple "
  255. "dependent projects one after another.\n"
  256. "5. Search cmake variables defined in the Platform files "
  257. "for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
  258. "is passed.\n"
  259. " CMAKE_SYSTEM_PREFIX_PATH\n"
  260. " CMAKE_SYSTEM_FRAMEWORK_PATH\n"
  261. " CMAKE_SYSTEM_APPBUNDLE_PATH\n"
  262. "6. Search paths specified by the PATHS option.\n"
  263. ;
  264. this->CommandDocumentation += this->GenericDocumentationMacPolicy;
  265. this->CommandDocumentation += this->GenericDocumentationRootPath;
  266. this->CommandDocumentation += this->GenericDocumentationPathsOrder;
  267. }
  268. //----------------------------------------------------------------------------
  269. const char* cmFindPackageCommand::GetFullDocumentation()
  270. {
  271. return this->CommandDocumentation.c_str();
  272. }
  273. //----------------------------------------------------------------------------
  274. bool cmFindPackageCommand
  275. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  276. {
  277. if(args.size() < 1)
  278. {
  279. this->SetError("called with incorrect number of arguments");
  280. return false;
  281. }
  282. // Check for debug mode.
  283. this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
  284. // Find the current root path mode.
  285. this->SelectDefaultRootPathMode();
  286. // Find the current bundle/framework search policy.
  287. this->SelectDefaultMacMode();
  288. // Record options.
  289. this->Name = args[0];
  290. std::string components;
  291. const char* components_sep = "";
  292. // Check ancient compatibility.
  293. this->Compatibility_1_6 =
  294. this->Makefile->GetLocalGenerator()
  295. ->NeedBackwardsCompatibility(1, 6);
  296. // Always search directly in a generated path.
  297. this->SearchPathSuffixes.push_back("");
  298. // Parse the arguments.
  299. enum Doing { DoingNone, DoingComponents, DoingNames, DoingPaths,
  300. DoingPathSuffixes, DoingConfigs };
  301. Doing doing = DoingNone;
  302. cmsys::RegularExpression version("^[0-9.]+$");
  303. bool haveVersion = false;
  304. for(unsigned int i=1; i < args.size(); ++i)
  305. {
  306. if(args[i] == "QUIET")
  307. {
  308. this->Quiet = true;
  309. doing = DoingNone;
  310. }
  311. else if(args[i] == "EXACT")
  312. {
  313. this->VersionExact = true;
  314. this->Compatibility_1_6 = false;
  315. doing = DoingNone;
  316. }
  317. else if(args[i] == "NO_MODULE")
  318. {
  319. this->NoModule = true;
  320. doing = DoingNone;
  321. }
  322. else if(args[i] == "REQUIRED")
  323. {
  324. this->Required = true;
  325. doing = DoingComponents;
  326. }
  327. else if(args[i] == "COMPONENTS")
  328. {
  329. this->Compatibility_1_6 = false;
  330. doing = DoingComponents;
  331. }
  332. else if(args[i] == "NAMES")
  333. {
  334. this->NoModule = true;
  335. this->Compatibility_1_6 = false;
  336. doing = DoingNames;
  337. }
  338. else if(args[i] == "PATHS")
  339. {
  340. this->NoModule = true;
  341. this->Compatibility_1_6 = false;
  342. doing = DoingPaths;
  343. }
  344. else if(args[i] == "PATH_SUFFIXES")
  345. {
  346. this->NoModule = true;
  347. this->Compatibility_1_6 = false;
  348. doing = DoingPathSuffixes;
  349. }
  350. else if(args[i] == "CONFIGS")
  351. {
  352. this->NoModule = true;
  353. this->Compatibility_1_6 = false;
  354. doing = DoingConfigs;
  355. }
  356. else if(args[i] == "NO_CMAKE_BUILDS_PATH")
  357. {
  358. this->NoBuilds = true;
  359. this->NoModule = true;
  360. this->Compatibility_1_6 = false;
  361. doing = DoingNone;
  362. }
  363. else if(this->CheckCommonArgument(args[i]))
  364. {
  365. this->NoModule = true;
  366. this->Compatibility_1_6 = false;
  367. doing = DoingNone;
  368. }
  369. else if(doing == DoingComponents)
  370. {
  371. // Set a variable telling the find script this component
  372. // is required.
  373. std::string req_var = Name + "_FIND_REQUIRED_" + args[i];
  374. this->Makefile->AddDefinition(req_var.c_str(), "1");
  375. // Append to the list of required components.
  376. components += components_sep;
  377. components += args[i];
  378. components_sep = ";";
  379. }
  380. else if(doing == DoingNames)
  381. {
  382. this->Names.push_back(args[i]);
  383. }
  384. else if(doing == DoingPaths)
  385. {
  386. this->AddUserPath(args[i]);
  387. }
  388. else if(doing == DoingPathSuffixes)
  389. {
  390. this->AddPathSuffix(args[i]);
  391. }
  392. else if(doing == DoingConfigs)
  393. {
  394. if(args[i].find_first_of(":/\\") != args[i].npos ||
  395. cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake")
  396. {
  397. cmOStringStream e;
  398. e << "given CONFIGS option followed by invalid file name \""
  399. << args[i] << "\". The names given must be file names without "
  400. << "a path and with a \".cmake\" extension.";
  401. return false;
  402. }
  403. this->Configs.push_back(args[i]);
  404. }
  405. else if(!haveVersion && version.find(args[i].c_str()))
  406. {
  407. haveVersion = true;
  408. this->Version = args[i];
  409. }
  410. else
  411. {
  412. cmOStringStream e;
  413. e << "called with invalid argument \"" << args[i].c_str() << "\"";
  414. this->SetError(e.str().c_str());
  415. return false;
  416. }
  417. }
  418. if(!this->Version.empty())
  419. {
  420. // Try to parse the version number and store the results that were
  421. // successfully parsed.
  422. unsigned int parsed_major;
  423. unsigned int parsed_minor;
  424. unsigned int parsed_patch;
  425. this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u",
  426. &parsed_major, &parsed_minor, &parsed_patch);
  427. switch(this->VersionCount)
  428. {
  429. case 3: this->VersionPatch = parsed_patch; // no break!
  430. case 2: this->VersionMinor = parsed_minor; // no break!
  431. case 1: this->VersionMajor = parsed_major; // no break!
  432. default: break;
  433. }
  434. }
  435. // Store the list of components.
  436. std::string components_var = Name + "_FIND_COMPONENTS";
  437. this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
  438. // See if there is a Find<package>.cmake module.
  439. if(!this->NoModule)
  440. {
  441. bool foundModule = false;
  442. if(!this->FindModule(foundModule))
  443. {
  444. this->AppendSuccessInformation();
  445. return false;
  446. }
  447. if(foundModule)
  448. {
  449. this->AppendSuccessInformation();
  450. return true;
  451. }
  452. }
  453. // No find module. Assume the project has a CMake config file. Use
  454. // a <package>_DIR cache variable to locate it.
  455. this->Variable = this->Name;
  456. this->Variable += "_DIR";
  457. // Add the default name.
  458. if(this->Names.empty())
  459. {
  460. this->Names.push_back(this->Name);
  461. }
  462. // Add the default configs.
  463. if(this->Configs.empty())
  464. {
  465. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  466. ni != this->Names.end(); ++ni)
  467. {
  468. std::string config = *ni;
  469. config += "Config.cmake";
  470. this->Configs.push_back(config);
  471. config = cmSystemTools::LowerCase(*ni);
  472. config += "-config.cmake";
  473. this->Configs.push_back(config);
  474. }
  475. }
  476. // Find and load the package.
  477. bool result = this->HandlePackageMode();
  478. this->AppendSuccessInformation();
  479. return result;
  480. }
  481. //----------------------------------------------------------------------------
  482. bool cmFindPackageCommand::FindModule(bool& found)
  483. {
  484. std::string module = "Find";
  485. module += this->Name;
  486. module += ".cmake";
  487. std::string mfile = this->Makefile->GetModulesFile(module.c_str());
  488. if ( mfile.size() )
  489. {
  490. if(this->Quiet)
  491. {
  492. // Tell the module that is about to be read that it should find
  493. // quietly.
  494. std::string quietly = this->Name;
  495. quietly += "_FIND_QUIETLY";
  496. this->Makefile->AddDefinition(quietly.c_str(), "1");
  497. }
  498. if(this->Required)
  499. {
  500. // Tell the module that is about to be read that it should report
  501. // a fatal error if the package is not found.
  502. std::string req = this->Name;
  503. req += "_FIND_REQUIRED";
  504. this->Makefile->AddDefinition(req.c_str(), "1");
  505. }
  506. if(!this->Version.empty())
  507. {
  508. // Tell the module that is about to be read what version of the
  509. // package has been requested.
  510. std::string ver = this->Name;
  511. ver += "_FIND_VERSION";
  512. this->Makefile->AddDefinition(ver.c_str(), this->Version.c_str());
  513. char buf[64];
  514. switch(this->VersionCount)
  515. {
  516. case 3:
  517. {
  518. sprintf(buf, "%u", this->VersionPatch);
  519. this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
  520. } // no break
  521. case 2:
  522. {
  523. sprintf(buf, "%u", this->VersionMinor);
  524. this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
  525. } // no break
  526. case 1:
  527. {
  528. sprintf(buf, "%u", this->VersionMajor);
  529. this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
  530. } // no break
  531. default: break;
  532. }
  533. // Tell the module whether an exact version has been requested.
  534. std::string exact = this->Name;
  535. exact += "_FIND_VERSION_EXACT";
  536. this->Makefile->AddDefinition(exact.c_str(),
  537. this->VersionExact? "1":"0");
  538. }
  539. // Load the module we found.
  540. found = true;
  541. return this->ReadListFile(mfile.c_str());
  542. }
  543. return true;
  544. }
  545. //----------------------------------------------------------------------------
  546. bool cmFindPackageCommand::HandlePackageMode()
  547. {
  548. // Support old capitalization behavior.
  549. std::string upperDir = cmSystemTools::UpperCase(this->Name);
  550. std::string upperFound = cmSystemTools::UpperCase(this->Name);
  551. upperDir += "_DIR";
  552. upperFound += "_FOUND";
  553. if(upperDir == this->Variable)
  554. {
  555. this->Compatibility_1_6 = false;
  556. }
  557. // Try to find the config file.
  558. const char* def = this->Makefile->GetDefinition(this->Variable.c_str());
  559. if(this->Compatibility_1_6 && cmSystemTools::IsOff(def))
  560. {
  561. // Use the setting of the old name of the variable to provide the
  562. // value of the new.
  563. const char* oldDef = this->Makefile->GetDefinition(upperDir.c_str());
  564. if(!cmSystemTools::IsOff(oldDef))
  565. {
  566. this->Makefile->AddDefinition(this->Variable.c_str(), oldDef);
  567. def = this->Makefile->GetDefinition(this->Variable.c_str());
  568. }
  569. }
  570. // Search for the config file if it is not already found.
  571. if(cmSystemTools::IsOff(def))
  572. {
  573. this->FindConfig();
  574. def = this->Makefile->GetDefinition(this->Variable.c_str());
  575. }
  576. // If the config file was found, load it.
  577. std::string file;
  578. bool result = true;
  579. bool found = false;
  580. if(!cmSystemTools::IsOff(def))
  581. {
  582. // Get the directory from the variable value.
  583. std::string dir = def;
  584. cmSystemTools::ConvertToUnixSlashes(dir);
  585. // Treat relative paths with respect to the current source dir.
  586. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  587. {
  588. dir = "/" + dir;
  589. dir = this->Makefile->GetCurrentDirectory() + dir;
  590. }
  591. // Find the configuration file.
  592. if(this->FindConfigFileToLoad(dir, file))
  593. {
  594. // Set the version variables before loading the config file.
  595. // It may override them.
  596. this->StoreVersionFound();
  597. // Parse the configuration file.
  598. if(this->ReadListFile(file.c_str()))
  599. {
  600. // The package has been found.
  601. found = true;
  602. }
  603. else
  604. {
  605. // The configuration file is invalid.
  606. result = false;
  607. }
  608. }
  609. else
  610. {
  611. // The variable setting is wrong.
  612. cmOStringStream e;
  613. e << "cannot find package " << this->Name << " because "
  614. << this->Variable << " is set to \"" << def << "\" "
  615. << "which is not a directory containing a package configuration "
  616. << "file (or it is not for the requested version). "
  617. << "Please set the cache entry " << this->Variable << " "
  618. << "to the correct directory, or delete it to ask CMake "
  619. << "to search.";
  620. this->SetError(e.str().c_str());
  621. result = false;
  622. }
  623. }
  624. else if(!this->Quiet || this->Required)
  625. {
  626. // The variable is not set.
  627. cmOStringStream e;
  628. e << "could not find ";
  629. if(!this->NoModule)
  630. {
  631. e << "module Find" << this->Name << ".cmake or ";
  632. }
  633. e << "a configuration file for package " << this->Name << ".\n";
  634. if(!this->NoModule)
  635. {
  636. e << "Adjust CMAKE_MODULE_PATH to find Find"
  637. << this->Name << ".cmake or set ";
  638. }
  639. else
  640. {
  641. e << "Set ";
  642. }
  643. e << this->Variable << " to the directory containing a CMake "
  644. << "configuration file for " << this->Name << ". ";
  645. if(this->Configs.size() == 1)
  646. {
  647. e << "The file will be called " << this->Configs[0];
  648. }
  649. else
  650. {
  651. e << "The file will have one of the following names:\n";
  652. for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
  653. ci != this->Configs.end(); ++ci)
  654. {
  655. e << " " << *ci << "\n";
  656. }
  657. }
  658. if(this->Required)
  659. {
  660. this->SetError(e.str().c_str());
  661. result = false;
  662. }
  663. else
  664. {
  665. cmSystemTools::Error("find_package ", e.str().c_str());
  666. }
  667. }
  668. // Set a variable marking whether the package was found.
  669. std::string foundVar = this->Name;
  670. foundVar += "_FOUND";
  671. this->Makefile->AddDefinition(foundVar.c_str(), found? "1":"0");
  672. // Set a variable naming the configuration file that was found.
  673. std::string fileVar = this->Name;
  674. fileVar += "_CONFIG";
  675. if(found)
  676. {
  677. this->Makefile->AddDefinition(fileVar.c_str(), file.c_str());
  678. }
  679. else
  680. {
  681. this->Makefile->RemoveDefinition(fileVar.c_str());
  682. }
  683. // Handle some ancient compatibility stuff.
  684. if(this->Compatibility_1_6)
  685. {
  686. // Listfiles will be looking for the capitalized version of the
  687. // name. Provide it.
  688. this->Makefile->AddDefinition
  689. (upperDir.c_str(),
  690. this->Makefile->GetDefinition(this->Variable.c_str()));
  691. this->Makefile->AddDefinition
  692. (upperFound.c_str(),
  693. this->Makefile->GetDefinition(foundVar.c_str()));
  694. }
  695. #ifdef CMAKE_BUILD_WITH_CMAKE
  696. if(!(upperDir == this->Variable))
  697. {
  698. if(this->Compatibility_1_6)
  699. {
  700. // Listfiles may use the capitalized version of the name.
  701. // Remove any previously added watch.
  702. this->Makefile->GetVariableWatch()->RemoveWatch(
  703. upperDir.c_str(),
  704. cmFindPackageNeedBackwardsCompatibility
  705. );
  706. }
  707. else
  708. {
  709. // Listfiles should not be using the capitalized version of the
  710. // name. Add a watch to warn the user.
  711. this->Makefile->GetVariableWatch()->AddWatch(
  712. upperDir.c_str(),
  713. cmFindPackageNeedBackwardsCompatibility
  714. );
  715. }
  716. }
  717. #endif
  718. return result;
  719. }
  720. //----------------------------------------------------------------------------
  721. void cmFindPackageCommand::FindConfig()
  722. {
  723. // Compute the set of search prefixes.
  724. this->ComputePrefixes();
  725. // Look for the project's configuration file.
  726. bool found = false;
  727. // Search for frameworks.
  728. if(!found && this->SearchFrameworkFirst || this->SearchFrameworkOnly)
  729. {
  730. found = this->FindFrameworkConfig();
  731. }
  732. // Search for apps.
  733. if(!found && this->SearchAppBundleFirst || this->SearchAppBundleOnly)
  734. {
  735. found = this->FindAppBundleConfig();
  736. }
  737. // Search prefixes.
  738. if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  739. {
  740. found = this->FindPrefixedConfig();
  741. }
  742. // Search for frameworks.
  743. if(!found && this->SearchFrameworkLast)
  744. {
  745. found = this->FindFrameworkConfig();
  746. }
  747. // Search for apps.
  748. if(!found && this->SearchAppBundleLast)
  749. {
  750. found = this->FindAppBundleConfig();
  751. }
  752. // Store the entry in the cache so it can be set by the user.
  753. std::string init;
  754. if(found)
  755. {
  756. init = cmSystemTools::GetFilenamePath(this->FileFound);
  757. }
  758. else
  759. {
  760. init = this->Variable + "-NOTFOUND";
  761. }
  762. std::string help =
  763. "The directory containing a CMake configuration file for ";
  764. help += this->Name;
  765. help += ".";
  766. this->Makefile->AddCacheDefinition(this->Variable.c_str(),
  767. init.c_str(), help.c_str(),
  768. cmCacheManager::PATH);
  769. }
  770. //----------------------------------------------------------------------------
  771. bool cmFindPackageCommand::FindPrefixedConfig()
  772. {
  773. std::vector<std::string>& prefixes = this->SearchPaths;
  774. for(std::vector<std::string>::const_iterator pi = prefixes.begin();
  775. pi != prefixes.end(); ++pi)
  776. {
  777. if(this->SearchPrefix(*pi))
  778. {
  779. return true;
  780. }
  781. }
  782. return false;
  783. }
  784. //----------------------------------------------------------------------------
  785. bool cmFindPackageCommand::FindFrameworkConfig()
  786. {
  787. std::vector<std::string>& prefixes = this->SearchPaths;
  788. for(std::vector<std::string>::const_iterator i = prefixes.begin();
  789. i != prefixes.end(); ++i)
  790. {
  791. if(this->SearchFrameworkPrefix(*i))
  792. {
  793. return true;
  794. }
  795. }
  796. return false;
  797. }
  798. //----------------------------------------------------------------------------
  799. bool cmFindPackageCommand::FindAppBundleConfig()
  800. {
  801. std::vector<std::string>& prefixes = this->SearchPaths;
  802. for(std::vector<std::string>::const_iterator i = prefixes.begin();
  803. i != prefixes.end(); ++i)
  804. {
  805. if(this->SearchAppBundlePrefix(*i))
  806. {
  807. return true;
  808. }
  809. }
  810. return false;
  811. }
  812. //----------------------------------------------------------------------------
  813. bool cmFindPackageCommand::ReadListFile(const char* f)
  814. {
  815. if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),f))
  816. {
  817. return true;
  818. }
  819. std::string e = "Error reading CMake code from \"";
  820. e += f;
  821. e += "\".";
  822. this->SetError(e.c_str());
  823. return false;
  824. }
  825. //----------------------------------------------------------------------------
  826. void cmFindPackageCommand::AppendToProperty(const char* propertyName)
  827. {
  828. std::string propertyValue;
  829. const char *prop =
  830. this->Makefile->GetCMakeInstance()->GetProperty(propertyName);
  831. if (prop && *prop)
  832. {
  833. propertyValue = prop;
  834. std::vector<std::string> contents;
  835. cmSystemTools::ExpandListArgument(propertyValue, contents, false);
  836. bool alreadyInserted = false;
  837. for(std::vector<std::string>::const_iterator it = contents.begin();
  838. it != contents.end(); ++ it )
  839. {
  840. if (*it == this->Name)
  841. {
  842. alreadyInserted = true;
  843. break;
  844. }
  845. }
  846. if (!alreadyInserted)
  847. {
  848. propertyValue += ";";
  849. propertyValue += this->Name;
  850. }
  851. }
  852. else
  853. {
  854. propertyValue = this->Name;
  855. }
  856. this->Makefile->GetCMakeInstance()->SetProperty(propertyName,
  857. propertyValue.c_str());
  858. }
  859. //----------------------------------------------------------------------------
  860. void cmFindPackageCommand::AppendSuccessInformation()
  861. {
  862. std::string found = this->Name;
  863. found += "_FOUND";
  864. std::string upperFound = cmSystemTools::UpperCase(found);
  865. const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str());
  866. const char* result = this->Makefile->GetDefinition(found.c_str());
  867. if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult)))
  868. {
  869. this->AppendToProperty("PACKAGES_FOUND");
  870. if (!this->Quiet)
  871. {
  872. this->AppendToProperty("ENABLED_FEATURES");
  873. }
  874. }
  875. else
  876. {
  877. this->AppendToProperty("PACKAGES_NOT_FOUND");
  878. if (!this->Quiet)
  879. {
  880. this->AppendToProperty("DISABLED_FEATURES");
  881. }
  882. }
  883. }
  884. //----------------------------------------------------------------------------
  885. void cmFindPackageCommand::ComputePrefixes()
  886. {
  887. this->AddPrefixesCMakeEnvironment();
  888. this->AddPrefixesCMakeVariable();
  889. this->AddPrefixesSystemEnvironment();
  890. this->AddPrefixesBuilds();
  891. this->AddPrefixesCMakeSystemVariable();
  892. this->AddPrefixesUser();
  893. this->ComputeFinalPrefixes();
  894. }
  895. //----------------------------------------------------------------------------
  896. void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
  897. {
  898. if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
  899. {
  900. // Check the environment variable with the same name as the cache
  901. // entry.
  902. std::string env;
  903. if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
  904. {
  905. cmSystemTools::ConvertToUnixSlashes(env);
  906. this->AddPathInternal(env, EnvPath);
  907. }
  908. this->AddEnvPath("CMAKE_PREFIX_PATH");
  909. this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
  910. this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
  911. }
  912. }
  913. //----------------------------------------------------------------------------
  914. void cmFindPackageCommand::AddPrefixesCMakeVariable()
  915. {
  916. if(!this->NoCMakePath && !this->NoDefaultPath)
  917. {
  918. this->AddCMakePath("CMAKE_PREFIX_PATH");
  919. this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
  920. this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
  921. }
  922. }
  923. //----------------------------------------------------------------------------
  924. void cmFindPackageCommand::AddPrefixesSystemEnvironment()
  925. {
  926. if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
  927. {
  928. // Use the system search path to generate prefixes.
  929. // Relative paths are interpreted with respect to the current
  930. // working directory.
  931. std::vector<std::string> tmp;
  932. cmSystemTools::GetPath(tmp);
  933. for(std::vector<std::string>::iterator i = tmp.begin();
  934. i != tmp.end(); ++i)
  935. {
  936. std::string const& d = *i;
  937. // If the path is a PREFIX/bin case then add its parent instead.
  938. if(d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0 ||
  939. d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0)
  940. {
  941. this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
  942. }
  943. else
  944. {
  945. this->AddPathInternal(d, EnvPath);
  946. }
  947. }
  948. }
  949. }
  950. //----------------------------------------------------------------------------
  951. void cmFindPackageCommand::AddPrefixesBuilds()
  952. {
  953. if(!this->NoBuilds && !this->NoDefaultPath)
  954. {
  955. // It is likely that CMake will have recently built the project.
  956. for(int i=1; i <= 10; ++i)
  957. {
  958. cmOStringStream r;
  959. r <<
  960. "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
  961. "Settings\\StartPath;WhereBuild" << i << "]";
  962. std::string f = r.str();
  963. cmSystemTools::ExpandRegistryValues(f);
  964. cmSystemTools::ConvertToUnixSlashes(f);
  965. if(cmSystemTools::FileIsFullPath(f.c_str()) &&
  966. cmSystemTools::FileIsDirectory(f.c_str()))
  967. {
  968. this->AddPathInternal(f, FullPath);
  969. }
  970. }
  971. }
  972. }
  973. //----------------------------------------------------------------------------
  974. void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
  975. {
  976. if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
  977. {
  978. this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
  979. this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
  980. this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
  981. }
  982. }
  983. //----------------------------------------------------------------------------
  984. void cmFindPackageCommand::AddPrefixesUser()
  985. {
  986. if(!this->UserPaths.empty())
  987. {
  988. // Add paths specified by the caller.
  989. this->AddPathsInternal(this->UserPaths, CMakePath);
  990. }
  991. }
  992. //----------------------------------------------------------------------------
  993. void cmFindPackageCommand::ComputeFinalPrefixes()
  994. {
  995. std::vector<std::string>& prefixes = this->SearchPaths;
  996. // Construct the final set of prefixes.
  997. this->RerootPaths(prefixes);
  998. // Add a trailing slash to all prefixes to aid the search process.
  999. this->AddTrailingSlashes(prefixes);
  1000. }
  1001. //----------------------------------------------------------------------------
  1002. bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
  1003. {
  1004. assert(!dir.empty() && dir[dir.size()-1] == '/');
  1005. // Check each path suffix on this directory.
  1006. for(std::vector<std::string>::const_iterator
  1007. si = this->SearchPathSuffixes.begin();
  1008. si != this->SearchPathSuffixes.end(); ++si)
  1009. {
  1010. std::string d = dir;
  1011. if(!si->empty())
  1012. {
  1013. d += *si;
  1014. d += "/";
  1015. }
  1016. if(this->CheckDirectory(d))
  1017. {
  1018. return true;
  1019. }
  1020. }
  1021. return false;
  1022. }
  1023. //----------------------------------------------------------------------------
  1024. bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
  1025. {
  1026. assert(!dir.empty() && dir[dir.size()-1] == '/');
  1027. // Look for the file in this directory.
  1028. std::string d = dir.substr(0, dir.size()-1);
  1029. if(this->FindConfigFile(d, this->FileFound))
  1030. {
  1031. // Remove duplicate slashes.
  1032. cmSystemTools::ConvertToUnixSlashes(this->FileFound);
  1033. return true;
  1034. }
  1035. return false;
  1036. }
  1037. //----------------------------------------------------------------------------
  1038. bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
  1039. std::string& file)
  1040. {
  1041. for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
  1042. ci != this->Configs.end(); ++ci)
  1043. {
  1044. file = dir;
  1045. file += "/";
  1046. file += *ci;
  1047. if(this->DebugMode)
  1048. {
  1049. fprintf(stderr, "Checking file [%s]\n", file.c_str());
  1050. }
  1051. if(cmSystemTools::FileExists(file.c_str(), true) &&
  1052. this->CheckVersion(file))
  1053. {
  1054. return true;
  1055. }
  1056. }
  1057. return false;
  1058. }
  1059. //----------------------------------------------------------------------------
  1060. bool cmFindPackageCommand::FindConfigFileToLoad(std::string const& dir,
  1061. std::string& file)
  1062. {
  1063. if(this->FileFound.empty())
  1064. {
  1065. // The file location was cached. Look for the correct file.
  1066. return this->FindConfigFile(dir, file);
  1067. }
  1068. else
  1069. {
  1070. // The file location was just found during this call.
  1071. // Use the file found without searching again.
  1072. file = this->FileFound;
  1073. return true;
  1074. }
  1075. }
  1076. //----------------------------------------------------------------------------
  1077. bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
  1078. {
  1079. // Get the filename without the .cmake extension.
  1080. std::string::size_type pos = config_file.rfind('.');
  1081. std::string version_file_base = config_file.substr(0, pos);
  1082. // Look for foo-config-version.cmake
  1083. std::string version_file = version_file_base;
  1084. version_file += "-version.cmake";
  1085. if(cmSystemTools::FileExists(version_file.c_str(), true))
  1086. {
  1087. return this->CheckVersionFile(version_file);
  1088. }
  1089. // Look for fooConfigVersion.cmake
  1090. version_file = version_file_base;
  1091. version_file += "Version.cmake";
  1092. if(cmSystemTools::FileExists(version_file.c_str(), true))
  1093. {
  1094. return this->CheckVersionFile(version_file);
  1095. }
  1096. // If no version was requested a versionless package is acceptable.
  1097. if(this->Version.empty())
  1098. {
  1099. return true;
  1100. }
  1101. // No version file found. Assume the version is incompatible.
  1102. return false;
  1103. }
  1104. //----------------------------------------------------------------------------
  1105. bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file)
  1106. {
  1107. // The version file will be loaded in an isolated scope.
  1108. this->Makefile->PushScope();
  1109. // Clear the output variables.
  1110. this->Makefile->RemoveDefinition("PACKAGE_VERSION");
  1111. this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
  1112. this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
  1113. // Set the input variables.
  1114. this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str());
  1115. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION",
  1116. this->Version.c_str());
  1117. if(this->VersionCount >= 3)
  1118. {
  1119. char buf[64];
  1120. sprintf(buf, "%u", this->VersionPatch);
  1121. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_PATCH", buf);
  1122. }
  1123. else
  1124. {
  1125. this->Makefile->RemoveDefinition("PACKAGE_FIND_VERSION_PATCH");
  1126. }
  1127. if(this->VersionCount >= 2)
  1128. {
  1129. char buf[64];
  1130. sprintf(buf, "%u", this->VersionMinor);
  1131. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MINOR", buf);
  1132. }
  1133. else
  1134. {
  1135. this->Makefile->RemoveDefinition("PACKAGE_FIND_VERSION_MINOR");
  1136. }
  1137. if(this->VersionCount >= 1)
  1138. {
  1139. char buf[64];
  1140. sprintf(buf, "%u", this->VersionMajor);
  1141. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf);
  1142. }
  1143. else
  1144. {
  1145. this->Makefile->RemoveDefinition("PACKAGE_FIND_VERSION_MAJOR");
  1146. }
  1147. // Load the version check file.
  1148. bool found = false;
  1149. if(this->ReadListFile(version_file.c_str()))
  1150. {
  1151. // Check the output variables.
  1152. found = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
  1153. if(!found && !this->VersionExact)
  1154. {
  1155. found = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
  1156. }
  1157. if(found || this->Version.empty())
  1158. {
  1159. // Get the version found.
  1160. this->VersionFound =
  1161. this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
  1162. // Try to parse the version number and store the results that were
  1163. // successfully parsed.
  1164. unsigned int parsed_major;
  1165. unsigned int parsed_minor;
  1166. unsigned int parsed_patch;
  1167. this->VersionFoundCount =
  1168. sscanf(this->VersionFound.c_str(), "%u.%u.%u",
  1169. &parsed_major, &parsed_minor, &parsed_patch);
  1170. switch(this->VersionFoundCount)
  1171. {
  1172. case 3: this->VersionFoundPatch = parsed_patch; // no break!
  1173. case 2: this->VersionFoundMinor = parsed_minor; // no break!
  1174. case 1: this->VersionFoundMajor = parsed_major; // no break!
  1175. default: break;
  1176. }
  1177. }
  1178. }
  1179. // Restore the original scope.
  1180. this->Makefile->PopScope();
  1181. // Succeed if the version was found or no version was requested.
  1182. return found || this->Version.empty();
  1183. }
  1184. //----------------------------------------------------------------------------
  1185. void cmFindPackageCommand::StoreVersionFound()
  1186. {
  1187. // Store the whole version string.
  1188. std::string ver = this->Name;
  1189. ver += "_VERSION";
  1190. if(this->VersionFound.empty())
  1191. {
  1192. this->Makefile->RemoveDefinition(ver.c_str());
  1193. }
  1194. else
  1195. {
  1196. this->Makefile->AddDefinition(ver.c_str(), this->VersionFound.c_str());
  1197. }
  1198. // Store the portions that could be parsed.
  1199. char buf[64];
  1200. switch(this->VersionFoundCount)
  1201. {
  1202. case 3:
  1203. {
  1204. sprintf(buf, "%u", this->VersionFoundPatch);
  1205. this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
  1206. } // no break
  1207. case 2:
  1208. {
  1209. sprintf(buf, "%u", this->VersionFoundMinor);
  1210. this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
  1211. } // no break
  1212. case 1:
  1213. {
  1214. sprintf(buf, "%u", this->VersionFoundMajor);
  1215. this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
  1216. } // no break
  1217. default: break;
  1218. }
  1219. }
  1220. //----------------------------------------------------------------------------
  1221. #include <cmsys/Directory.hxx>
  1222. #include <cmsys/Glob.hxx>
  1223. #include <cmsys/String.h>
  1224. #include <cmsys/auto_ptr.hxx>
  1225. class cmFileList;
  1226. class cmFileListGeneratorBase
  1227. {
  1228. public:
  1229. virtual ~cmFileListGeneratorBase() {}
  1230. protected:
  1231. bool Consider(std::string const& fullPath, cmFileList& listing);
  1232. private:
  1233. bool Search(cmFileList&);
  1234. virtual bool Search(std::string const& parent, cmFileList&) = 0;
  1235. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const = 0;
  1236. friend class cmFileList;
  1237. cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next);
  1238. cmsys::auto_ptr<cmFileListGeneratorBase> Next;
  1239. };
  1240. class cmFileList
  1241. {
  1242. public:
  1243. cmFileList(): First(), Last(0) {}
  1244. virtual ~cmFileList() {}
  1245. cmFileList& operator/(cmFileListGeneratorBase const& rhs)
  1246. {
  1247. if(this->Last)
  1248. {
  1249. this->Last = this->Last->SetNext(rhs);
  1250. }
  1251. else
  1252. {
  1253. this->First = rhs.Clone();
  1254. this->Last = this->First.get();
  1255. }
  1256. return *this;
  1257. }
  1258. bool Search()
  1259. {
  1260. if(this->First.get())
  1261. {
  1262. return this->First->Search(*this);
  1263. }
  1264. return false;
  1265. }
  1266. private:
  1267. virtual bool Visit(std::string const& fullPath) = 0;
  1268. friend class cmFileListGeneratorBase;
  1269. cmsys::auto_ptr<cmFileListGeneratorBase> First;
  1270. cmFileListGeneratorBase* Last;
  1271. };
  1272. class cmFindPackageFileList: public cmFileList
  1273. {
  1274. public:
  1275. cmFindPackageFileList(cmFindPackageCommand* fpc,
  1276. bool use_suffixes = true):
  1277. cmFileList(), FPC(fpc), UseSuffixes(use_suffixes) {}
  1278. private:
  1279. bool Visit(std::string const& fullPath)
  1280. {
  1281. if(this->UseSuffixes)
  1282. {
  1283. return this->FPC->SearchDirectory(fullPath);
  1284. }
  1285. else
  1286. {
  1287. return this->FPC->CheckDirectory(fullPath);
  1288. }
  1289. }
  1290. cmFindPackageCommand* FPC;
  1291. bool UseSuffixes;
  1292. };
  1293. bool cmFileListGeneratorBase::Search(cmFileList& listing)
  1294. {
  1295. return this->Search("", listing);
  1296. }
  1297. cmFileListGeneratorBase*
  1298. cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
  1299. {
  1300. this->Next = next.Clone();
  1301. return this->Next.get();
  1302. }
  1303. bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
  1304. cmFileList& listing)
  1305. {
  1306. if(this->Next.get())
  1307. {
  1308. return this->Next->Search(fullPath + "/", listing);
  1309. }
  1310. else
  1311. {
  1312. return listing.Visit(fullPath + "/");
  1313. }
  1314. }
  1315. class cmFileListGeneratorFixed: public cmFileListGeneratorBase
  1316. {
  1317. public:
  1318. cmFileListGeneratorFixed(std::string const& str):
  1319. cmFileListGeneratorBase(), String(str) {}
  1320. cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r):
  1321. cmFileListGeneratorBase(), String(r.String) {}
  1322. private:
  1323. std::string String;
  1324. virtual bool Search(std::string const& parent, cmFileList& lister)
  1325. {
  1326. std::string fullPath = parent + this->String;
  1327. return this->Consider(fullPath, lister);
  1328. }
  1329. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1330. {
  1331. cmsys::auto_ptr<cmFileListGeneratorBase>
  1332. g(new cmFileListGeneratorFixed(*this));
  1333. return g;
  1334. }
  1335. };
  1336. class cmFileListGeneratorEnumerate: public cmFileListGeneratorBase
  1337. {
  1338. public:
  1339. cmFileListGeneratorEnumerate(const char* p1, const char* p2):
  1340. cmFileListGeneratorBase()
  1341. {
  1342. this->Vector.push_back(p1);
  1343. this->Vector.push_back(p2);
  1344. }
  1345. cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
  1346. cmFileListGeneratorBase(), Vector(r.Vector) {}
  1347. private:
  1348. std::vector<std::string> Vector;
  1349. virtual bool Search(std::string const& parent, cmFileList& lister)
  1350. {
  1351. for(std::vector<std::string>::const_iterator i = this->Vector.begin();
  1352. i != this->Vector.end(); ++i)
  1353. {
  1354. if(this->Consider(parent + *i, lister))
  1355. {
  1356. return true;
  1357. }
  1358. }
  1359. return false;
  1360. }
  1361. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1362. {
  1363. cmsys::auto_ptr<cmFileListGeneratorBase>
  1364. g(new cmFileListGeneratorEnumerate(*this));
  1365. return g;
  1366. }
  1367. };
  1368. class cmFileListGeneratorProject: public cmFileListGeneratorBase
  1369. {
  1370. public:
  1371. cmFileListGeneratorProject(std::vector<std::string> const& names):
  1372. cmFileListGeneratorBase(), Names(names) {}
  1373. cmFileListGeneratorProject(cmFileListGeneratorProject const& r):
  1374. cmFileListGeneratorBase(), Names(r.Names) {}
  1375. private:
  1376. std::vector<std::string> const& Names;
  1377. virtual bool Search(std::string const& parent, cmFileList& lister)
  1378. {
  1379. // Construct a list of matches.
  1380. std::vector<std::string> matches;
  1381. cmsys::Directory d;
  1382. d.Load(parent.c_str());
  1383. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  1384. {
  1385. const char* fname = d.GetFile(i);
  1386. if(strcmp(fname, ".") == 0 ||
  1387. strcmp(fname, "..") == 0)
  1388. {
  1389. continue;
  1390. }
  1391. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  1392. ni != this->Names.end(); ++ni)
  1393. {
  1394. if(cmsysString_strncasecmp(fname, ni->c_str(),
  1395. ni->length()) == 0)
  1396. {
  1397. matches.push_back(fname);
  1398. }
  1399. }
  1400. }
  1401. for(std::vector<std::string>::const_iterator i = matches.begin();
  1402. i != matches.end(); ++i)
  1403. {
  1404. if(this->Consider(parent + *i, lister))
  1405. {
  1406. return true;
  1407. }
  1408. }
  1409. return false;
  1410. }
  1411. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1412. {
  1413. cmsys::auto_ptr<cmFileListGeneratorBase>
  1414. g(new cmFileListGeneratorProject(*this));
  1415. return g;
  1416. }
  1417. };
  1418. class cmFileListGeneratorMacProject: public cmFileListGeneratorBase
  1419. {
  1420. public:
  1421. cmFileListGeneratorMacProject(std::vector<std::string> const& names,
  1422. const char* ext):
  1423. cmFileListGeneratorBase(), Names(names), Extension(ext) {}
  1424. cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r):
  1425. cmFileListGeneratorBase(), Names(r.Names), Extension(r.Extension) {}
  1426. private:
  1427. std::vector<std::string> const& Names;
  1428. std::string Extension;
  1429. virtual bool Search(std::string const& parent, cmFileList& lister)
  1430. {
  1431. // Construct a list of matches.
  1432. std::vector<std::string> matches;
  1433. cmsys::Directory d;
  1434. d.Load(parent.c_str());
  1435. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  1436. {
  1437. const char* fname = d.GetFile(i);
  1438. if(strcmp(fname, ".") == 0 ||
  1439. strcmp(fname, "..") == 0)
  1440. {
  1441. continue;
  1442. }
  1443. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  1444. ni != this->Names.end(); ++ni)
  1445. {
  1446. std::string name = *ni;
  1447. name += this->Extension;
  1448. if(cmsysString_strcasecmp(fname, name.c_str()) == 0)
  1449. {
  1450. matches.push_back(fname);
  1451. }
  1452. }
  1453. }
  1454. for(std::vector<std::string>::const_iterator i = matches.begin();
  1455. i != matches.end(); ++i)
  1456. {
  1457. if(this->Consider(parent + *i, lister))
  1458. {
  1459. return true;
  1460. }
  1461. }
  1462. return false;
  1463. }
  1464. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1465. {
  1466. cmsys::auto_ptr<cmFileListGeneratorBase>
  1467. g(new cmFileListGeneratorMacProject(*this));
  1468. return g;
  1469. }
  1470. };
  1471. class cmFileListGeneratorCaseInsensitive: public cmFileListGeneratorBase
  1472. {
  1473. public:
  1474. cmFileListGeneratorCaseInsensitive(std::string const& str):
  1475. cmFileListGeneratorBase(), String(str) {}
  1476. cmFileListGeneratorCaseInsensitive(
  1477. cmFileListGeneratorCaseInsensitive const& r):
  1478. cmFileListGeneratorBase(), String(r.String) {}
  1479. private:
  1480. std::string String;
  1481. virtual bool Search(std::string const& parent, cmFileList& lister)
  1482. {
  1483. // Look for matching files.
  1484. std::vector<std::string> matches;
  1485. cmsys::Directory d;
  1486. d.Load(parent.c_str());
  1487. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  1488. {
  1489. const char* fname = d.GetFile(i);
  1490. if(strcmp(fname, ".") == 0 ||
  1491. strcmp(fname, "..") == 0)
  1492. {
  1493. continue;
  1494. }
  1495. if(cmsysString_strcasecmp(fname, this->String.c_str()) == 0)
  1496. {
  1497. if(this->Consider(parent + fname, lister))
  1498. {
  1499. return true;
  1500. }
  1501. }
  1502. }
  1503. return false;
  1504. }
  1505. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1506. {
  1507. cmsys::auto_ptr<cmFileListGeneratorBase>
  1508. g(new cmFileListGeneratorCaseInsensitive(*this));
  1509. return g;
  1510. }
  1511. };
  1512. class cmFileListGeneratorGlob: public cmFileListGeneratorBase
  1513. {
  1514. public:
  1515. cmFileListGeneratorGlob(std::string const& str):
  1516. cmFileListGeneratorBase(), Pattern(str) {}
  1517. cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r):
  1518. cmFileListGeneratorBase(), Pattern(r.Pattern) {}
  1519. private:
  1520. std::string Pattern;
  1521. virtual bool Search(std::string const& parent, cmFileList& lister)
  1522. {
  1523. // Glob the set of matching files.
  1524. std::string expr = parent;
  1525. expr += this->Pattern;
  1526. cmsys::Glob g;
  1527. if(!g.FindFiles(expr))
  1528. {
  1529. return false;
  1530. }
  1531. std::vector<std::string> const& files = g.GetFiles();
  1532. // Look for directories among the matches.
  1533. for(std::vector<std::string>::const_iterator fi = files.begin();
  1534. fi != files.end(); ++fi)
  1535. {
  1536. if(cmSystemTools::FileIsDirectory(fi->c_str()))
  1537. {
  1538. if(this->Consider(*fi, lister))
  1539. {
  1540. return true;
  1541. }
  1542. }
  1543. }
  1544. return false;
  1545. }
  1546. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1547. {
  1548. cmsys::auto_ptr<cmFileListGeneratorBase>
  1549. g(new cmFileListGeneratorGlob(*this));
  1550. return g;
  1551. }
  1552. };
  1553. //----------------------------------------------------------------------------
  1554. bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
  1555. {
  1556. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  1557. if(this->DebugMode)
  1558. {
  1559. fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
  1560. }
  1561. // Skip this if the prefix does not exist.
  1562. if(!cmSystemTools::FileIsDirectory(prefix_in.c_str()))
  1563. {
  1564. return false;
  1565. }
  1566. // PREFIX/ (useful on windows or in build trees)
  1567. if(this->SearchDirectory(prefix_in))
  1568. {
  1569. return true;
  1570. }
  1571. // Strip the trailing slash because the path generator is about to
  1572. // add one.
  1573. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  1574. // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
  1575. {
  1576. cmFindPackageFileList lister(this);
  1577. lister
  1578. / cmFileListGeneratorFixed(prefix)
  1579. / cmFileListGeneratorCaseInsensitive("cmake");
  1580. if(lister.Search())
  1581. {
  1582. return true;
  1583. }
  1584. }
  1585. // PREFIX/(share|lib)/(Foo|foo|FOO).*/
  1586. {
  1587. cmFindPackageFileList lister(this);
  1588. lister
  1589. / cmFileListGeneratorFixed(prefix)
  1590. / cmFileListGeneratorEnumerate("lib", "share")
  1591. / cmFileListGeneratorProject(this->Names);
  1592. if(lister.Search())
  1593. {
  1594. return true;
  1595. }
  1596. }
  1597. // PREFIX/(share|lib)/(Foo|foo|FOO).*/(cmake|CMake)/
  1598. {
  1599. cmFindPackageFileList lister(this);
  1600. lister
  1601. / cmFileListGeneratorFixed(prefix)
  1602. / cmFileListGeneratorEnumerate("lib", "share")
  1603. / cmFileListGeneratorProject(this->Names)
  1604. / cmFileListGeneratorCaseInsensitive("cmake");
  1605. if(lister.Search())
  1606. {
  1607. return true;
  1608. }
  1609. }
  1610. return false;
  1611. }
  1612. //----------------------------------------------------------------------------
  1613. bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
  1614. {
  1615. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  1616. if(this->DebugMode)
  1617. {
  1618. fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
  1619. }
  1620. // Strip the trailing slash because the path generator is about to
  1621. // add one.
  1622. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  1623. // <prefix>/Foo.framework/Resources/
  1624. {
  1625. cmFindPackageFileList lister(this);
  1626. lister
  1627. / cmFileListGeneratorFixed(prefix)
  1628. / cmFileListGeneratorMacProject(this->Names, ".framework")
  1629. / cmFileListGeneratorFixed("Resources");
  1630. if(lister.Search())
  1631. {
  1632. return true;
  1633. }
  1634. }
  1635. // <prefix>/Foo.framework/Resources/CMake/
  1636. {
  1637. cmFindPackageFileList lister(this);
  1638. lister
  1639. / cmFileListGeneratorFixed(prefix)
  1640. / cmFileListGeneratorMacProject(this->Names, ".framework")
  1641. / cmFileListGeneratorFixed("Resources")
  1642. / cmFileListGeneratorCaseInsensitive("cmake");
  1643. if(lister.Search())
  1644. {
  1645. return true;
  1646. }
  1647. }
  1648. // <prefix>/Foo.framework/Versions/*/Resources/
  1649. {
  1650. cmFindPackageFileList lister(this);
  1651. lister
  1652. / cmFileListGeneratorFixed(prefix)
  1653. / cmFileListGeneratorMacProject(this->Names, ".framework")
  1654. / cmFileListGeneratorFixed("Versions")
  1655. / cmFileListGeneratorGlob("*/Resources");
  1656. if(lister.Search())
  1657. {
  1658. return true;
  1659. }
  1660. }
  1661. // <prefix>/Foo.framework/Versions/*/Resources/CMake/
  1662. {
  1663. cmFindPackageFileList lister(this);
  1664. lister
  1665. / cmFileListGeneratorFixed(prefix)
  1666. / cmFileListGeneratorMacProject(this->Names, ".framework")
  1667. / cmFileListGeneratorFixed("Versions")
  1668. / cmFileListGeneratorGlob("*/Resources")
  1669. / cmFileListGeneratorCaseInsensitive("cmake");
  1670. if(lister.Search())
  1671. {
  1672. return true;
  1673. }
  1674. }
  1675. return false;
  1676. }
  1677. //----------------------------------------------------------------------------
  1678. bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
  1679. {
  1680. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  1681. if(this->DebugMode)
  1682. {
  1683. fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
  1684. }
  1685. // Strip the trailing slash because the path generator is about to
  1686. // add one.
  1687. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  1688. // <prefix>/Foo.app/Contents/Resources
  1689. {
  1690. cmFindPackageFileList lister(this);
  1691. lister
  1692. / cmFileListGeneratorFixed(prefix)
  1693. / cmFileListGeneratorMacProject(this->Names, ".app")
  1694. / cmFileListGeneratorFixed("Contents/Resources");
  1695. if(lister.Search())
  1696. {
  1697. return true;
  1698. }
  1699. }
  1700. // <prefix>/Foo.app/Contents/Resources/CMake
  1701. {
  1702. cmFindPackageFileList lister(this);
  1703. lister
  1704. / cmFileListGeneratorFixed(prefix)
  1705. / cmFileListGeneratorMacProject(this->Names, ".app")
  1706. / cmFileListGeneratorFixed("Contents/Resources")
  1707. / cmFileListGeneratorCaseInsensitive("cmake");
  1708. if(lister.Search())
  1709. {
  1710. return true;
  1711. }
  1712. }
  1713. return false;
  1714. }
  1715. // TODO: Version numbers? Perhaps have a listing component class that
  1716. // sorts by lexicographic and numerical ordering. Also try to match
  1717. // some command argument for the version. Alternatively provide an
  1718. // API that just returns a list of valid directories? Perhaps push a
  1719. // scope and try loading the target file just to get its version
  1720. // number? Could add a foo-version.cmake or FooVersion.cmake file
  1721. // in the projects that contains just version information.
  1722. // TODO: Debug cmsys::Glob double slash problem.
  1723. // TODO: Add registry entries after cmake system search path?
  1724. // Currently the user must specify them with the PATHS option.
  1725. //
  1726. // [HKEY_CURRENT_USER\Software\*\Foo*;InstallDir]
  1727. // [HKEY_CURRENT_USER\Software\*\*\Foo*;InstallDir]
  1728. // [HKEY_LOCAL_MACHINE\Software\*\Foo*;InstallDir]
  1729. // [HKEY_LOCAL_MACHINE\Software\*\*\Foo*;InstallDir]