cmFindPackageCommand.cxx 62 KB

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