cmFindPackageCommand.cxx 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmFindPackageCommand.h"
  11. #include <cmsys/Directory.hxx>
  12. #include <cmsys/RegularExpression.hxx>
  13. #ifdef CMAKE_BUILD_WITH_CMAKE
  14. #include "cmVariableWatch.h"
  15. #endif
  16. #if defined(__HAIKU__)
  17. #include <StorageKit.h>
  18. #endif
  19. void cmFindPackageNeedBackwardsCompatibility(const std::string& variable,
  20. int access_type, void*, const char* newValue,
  21. const cmMakefile*)
  22. {
  23. (void)newValue;
  24. #ifdef CMAKE_BUILD_WITH_CMAKE
  25. if(access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  26. {
  27. std::string message = "An attempt was made to access a variable: ";
  28. message += variable;
  29. message +=
  30. " that has not been defined. This variable is created by the "
  31. "FIND_PACKAGE command. CMake version 1.6 always converted the "
  32. "variable name to upper-case, but this behavior is no longer the "
  33. "case. To fix this you might need to set the cache value of "
  34. "CMAKE_BACKWARDS_COMPATIBILITY to 1.6 or less. If you are writing a "
  35. "CMake listfile, you should change the variable reference to use "
  36. "the case of the argument to FIND_PACKAGE.";
  37. cmSystemTools::Error(message.c_str());
  38. }
  39. #else
  40. (void)variable;
  41. (void)access_type;
  42. #endif
  43. }
  44. //----------------------------------------------------------------------------
  45. cmFindPackageCommand::cmFindPackageCommand()
  46. {
  47. this->CMakePathName = "PACKAGE";
  48. this->Quiet = false;
  49. this->Required = false;
  50. this->NoUserRegistry = false;
  51. this->NoSystemRegistry = false;
  52. this->NoBuilds = false;
  53. this->UseConfigFiles = true;
  54. this->UseFindModules = true;
  55. this->DebugMode = false;
  56. this->UseLib64Paths = false;
  57. this->PolicyScope = true;
  58. this->VersionMajor = 0;
  59. this->VersionMinor = 0;
  60. this->VersionPatch = 0;
  61. this->VersionTweak = 0;
  62. this->VersionCount = 0;
  63. this->VersionExact = false;
  64. this->VersionFoundMajor = 0;
  65. this->VersionFoundMinor = 0;
  66. this->VersionFoundPatch = 0;
  67. this->VersionFoundTweak = 0;
  68. this->VersionFoundCount = 0;
  69. this->RequiredCMakeVersion = 0;
  70. }
  71. //----------------------------------------------------------------------------
  72. void cmFindPackageCommand::GenerateDocumentation()
  73. {
  74. this->cmFindCommon::GenerateDocumentation();
  75. cmSystemTools::ReplaceString(this->GenericDocumentationRootPath,
  76. "CMAKE_FIND_ROOT_PATH_MODE_XXX",
  77. "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE");
  78. cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
  79. "FIND_ARGS_XXX", "<package>");
  80. cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder,
  81. "FIND_XXX", "find_package");
  82. this->CommandDocumentation =
  83. " find_package(<package> [version] [EXACT] [QUIET] [MODULE]\n"
  84. " [[REQUIRED|COMPONENTS] [components...]]\n"
  85. " [NO_POLICY_SCOPE])\n"
  86. "Finds and loads settings from an external project. "
  87. "<package>_FOUND will be set to indicate whether the package was found. "
  88. "When the package is found package-specific information is provided "
  89. "through variables documented by the package itself. "
  90. "The QUIET option disables messages if the package cannot be found. "
  91. "The MODULE option disables the second signature documented below. "
  92. "The REQUIRED option stops processing with an error message if the "
  93. "package cannot be found. "
  94. "A package-specific list of components may be listed after the "
  95. "REQUIRED option or after the COMPONENTS option if no REQUIRED "
  96. "option is given. "
  97. "The [version] argument requests a version with which the package found "
  98. "should be compatible (format is major[.minor[.patch[.tweak]]]). "
  99. "The EXACT option requests that the version be matched exactly. "
  100. "If no [version] and/or component list is given to a recursive "
  101. "invocation inside a find-module, the corresponding arguments "
  102. "are forwarded automatically from the outer call (including the "
  103. "EXACT flag for [version]). "
  104. "Version support is currently provided only on a package-by-package "
  105. "basis (details below).\n"
  106. "User code should generally look for packages using the above simple "
  107. "signature. The remainder of this command documentation specifies the "
  108. "full command signature and details of the search process. Project "
  109. "maintainers wishing to provide a package to be found by this command "
  110. "are encouraged to read on.\n"
  111. "The command has two modes by which it searches for packages: "
  112. "\"Module\" mode and \"Config\" mode. "
  113. "Module mode is available when the command is invoked with the above "
  114. "reduced signature. "
  115. "CMake searches for a file called \"Find<package>.cmake\" in "
  116. "the CMAKE_MODULE_PATH followed by the CMake installation. "
  117. "If the file is found, it is read and processed by CMake. "
  118. "It is responsible for finding the package, checking the version, "
  119. "and producing any needed messages. "
  120. "Many find-modules provide limited or no support for versioning; "
  121. "check the module documentation. "
  122. "If no module is found and the MODULE option is not given the command "
  123. "proceeds to Config mode.\n"
  124. "The complete Config mode command signature is:\n"
  125. " find_package(<package> [version] [EXACT] [QUIET]\n"
  126. " [[REQUIRED|COMPONENTS] [components...]]\n"
  127. " [CONFIG|NO_MODULE]\n"
  128. " [NO_POLICY_SCOPE]\n"
  129. " [NAMES name1 [name2 ...]]\n"
  130. " [CONFIGS config1 [config2 ...]]\n"
  131. " [HINTS path1 [path2 ... ]]\n"
  132. " [PATHS path1 [path2 ... ]]\n"
  133. " [PATH_SUFFIXES suffix1 [suffix2 ...]]\n"
  134. " [NO_DEFAULT_PATH]\n"
  135. " [NO_CMAKE_ENVIRONMENT_PATH]\n"
  136. " [NO_CMAKE_PATH]\n"
  137. " [NO_SYSTEM_ENVIRONMENT_PATH]\n"
  138. " [NO_CMAKE_PACKAGE_REGISTRY]\n"
  139. " [NO_CMAKE_BUILDS_PATH]\n"
  140. " [NO_CMAKE_SYSTEM_PATH]\n"
  141. " [NO_CMAKE_SYSTEM_PACKAGE_REGISTRY]\n"
  142. " [CMAKE_FIND_ROOT_PATH_BOTH |\n"
  143. " ONLY_CMAKE_FIND_ROOT_PATH |\n"
  144. " NO_CMAKE_FIND_ROOT_PATH])\n"
  145. "The CONFIG option may be used to skip Module mode explicitly and "
  146. "switch to Config mode. It is synonymous to using NO_MODULE. "
  147. "Config mode is also implied by use of options not specified in the "
  148. "reduced signature. "
  149. "\n"
  150. "Config mode attempts to locate a configuration file provided by the "
  151. "package to be found. A cache entry called <package>_DIR is created to "
  152. "hold the directory containing the file. "
  153. "By default the command searches for a package with the name <package>. "
  154. "If the NAMES option is given the names following it are used instead "
  155. "of <package>. "
  156. "The command searches for a file called \"<name>Config.cmake\" or "
  157. "\"<lower-case-name>-config.cmake\" for each name specified. "
  158. "A replacement set of possible configuration file names may be given "
  159. "using the CONFIGS option. "
  160. "The search procedure is specified below. Once found, the configuration "
  161. "file is read and processed by CMake. Since the file is provided by the "
  162. "package it already knows the location of package contents. "
  163. "The full path to the configuration file is stored in the cmake "
  164. "variable <package>_CONFIG."
  165. "\n"
  166. "All configuration files which have been considered by CMake while "
  167. "searching for an installation of the package with an appropriate "
  168. "version are stored in the cmake variable <package>_CONSIDERED_CONFIGS, "
  169. "the associated versions in <package>_CONSIDERED_VERSIONS. "
  170. "\n"
  171. "If the package configuration file cannot be found CMake "
  172. "will generate an error describing the problem unless the QUIET "
  173. "argument is specified. If REQUIRED is specified and the package "
  174. "is not found a fatal error is generated and the configure step stops "
  175. "executing. If <package>_DIR has been set to a directory not containing "
  176. "a configuration file CMake will ignore it and search from scratch."
  177. "\n"
  178. "When the [version] argument is given Config mode will only find a "
  179. "version of the package that claims compatibility with the requested "
  180. "version (format is major[.minor[.patch[.tweak]]]). "
  181. "If the EXACT option is given only a version of the package claiming "
  182. "an exact match of the requested version may be found. "
  183. "CMake does not establish any convention for the meaning of version "
  184. "numbers. "
  185. "Package version numbers are checked by \"version\" files provided by "
  186. "the packages themselves. "
  187. "For a candidate package configuration file \"<config-file>.cmake\" the "
  188. "corresponding version file is located next to it and named either "
  189. "\"<config-file>-version.cmake\" or \"<config-file>Version.cmake\". "
  190. "If no such version file is available then the configuration file "
  191. "is assumed to not be compatible with any requested version. "
  192. "A basic version file containing generic version matching code can be "
  193. "created using the macro write_basic_package_version_file(), see its "
  194. "documentation for more details. "
  195. "When a version file is found it is loaded to check the requested "
  196. "version number. "
  197. "The version file is loaded in a nested scope in which the following "
  198. "variables have been defined:\n"
  199. " PACKAGE_FIND_NAME = the <package> name\n"
  200. " PACKAGE_FIND_VERSION = full requested version string\n"
  201. " PACKAGE_FIND_VERSION_MAJOR = major version if requested, else 0\n"
  202. " PACKAGE_FIND_VERSION_MINOR = minor version if requested, else 0\n"
  203. " PACKAGE_FIND_VERSION_PATCH = patch version if requested, else 0\n"
  204. " PACKAGE_FIND_VERSION_TWEAK = tweak version if requested, else 0\n"
  205. " PACKAGE_FIND_VERSION_COUNT = number of version components, 0 to 4\n"
  206. "The version file checks whether it satisfies the requested version "
  207. "and sets these variables:\n"
  208. " PACKAGE_VERSION = full provided version string\n"
  209. " PACKAGE_VERSION_EXACT = true if version is exact match\n"
  210. " PACKAGE_VERSION_COMPATIBLE = true if version is compatible\n"
  211. " PACKAGE_VERSION_UNSUITABLE = true if unsuitable as any version\n"
  212. "These variables are checked by the find_package command to determine "
  213. "whether the configuration file provides an acceptable version. "
  214. "They are not available after the find_package call returns. "
  215. "If the version is acceptable the following variables are set:\n"
  216. " <package>_VERSION = full provided version string\n"
  217. " <package>_VERSION_MAJOR = major version if provided, else 0\n"
  218. " <package>_VERSION_MINOR = minor version if provided, else 0\n"
  219. " <package>_VERSION_PATCH = patch version if provided, else 0\n"
  220. " <package>_VERSION_TWEAK = tweak version if provided, else 0\n"
  221. " <package>_VERSION_COUNT = number of version components, 0 to 4\n"
  222. "and the corresponding package configuration file is loaded. "
  223. "When multiple package configuration files are available whose version "
  224. "files claim compatibility with the version requested it is unspecified "
  225. "which one is chosen. "
  226. "No attempt is made to choose a highest or closest version number."
  227. "\n"
  228. "Config mode provides an elaborate interface and search procedure. "
  229. "Much of the interface is provided for completeness and for use "
  230. "internally by find-modules loaded by Module mode. "
  231. "Most user code should simply call\n"
  232. " find_package(<package> [major[.minor]] [EXACT] [REQUIRED|QUIET])\n"
  233. "in order to find a package. Package maintainers providing CMake "
  234. "package configuration files are encouraged to name and install "
  235. "them such that the procedure outlined below will find them "
  236. "without requiring use of additional options."
  237. "\n"
  238. "CMake constructs a set of possible installation prefixes for the "
  239. "package. Under each prefix several directories are searched for a "
  240. "configuration file. The tables below show the directories searched. "
  241. "Each entry is meant for installation trees following Windows (W), "
  242. "UNIX (U), or Apple (A) conventions.\n"
  243. " <prefix>/ (W)\n"
  244. " <prefix>/(cmake|CMake)/ (W)\n"
  245. " <prefix>/<name>*/ (W)\n"
  246. " <prefix>/<name>*/(cmake|CMake)/ (W)\n"
  247. " <prefix>/(lib/<arch>|lib|share)/cmake/<name>*/ (U)\n"
  248. " <prefix>/(lib/<arch>|lib|share)/<name>*/ (U)\n"
  249. " <prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)\n"
  250. "On systems supporting OS X Frameworks and Application Bundles "
  251. "the following directories are searched for frameworks or bundles "
  252. "containing a configuration file:\n"
  253. " <prefix>/<name>.framework/Resources/ (A)\n"
  254. " <prefix>/<name>.framework/Resources/CMake/ (A)\n"
  255. " <prefix>/<name>.framework/Versions/*/Resources/ (A)\n"
  256. " <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)\n"
  257. " <prefix>/<name>.app/Contents/Resources/ (A)\n"
  258. " <prefix>/<name>.app/Contents/Resources/CMake/ (A)\n"
  259. "In all cases the <name> is treated as case-insensitive and corresponds "
  260. "to any of the names specified (<package> or names given by NAMES). "
  261. "Paths with lib/<arch> are enabled if CMAKE_LIBRARY_ARCHITECTURE is set. "
  262. "If PATH_SUFFIXES is specified the suffixes are appended to each "
  263. "(W) or (U) directory entry one-by-one.\n"
  264. "This set of directories is intended to work in cooperation with "
  265. "projects that provide configuration files in their installation trees. "
  266. "Directories above marked with (W) are intended for installations on "
  267. "Windows where the prefix may point at the top of an application's "
  268. "installation directory. Those marked with (U) are intended for "
  269. "installations on UNIX platforms where the prefix is shared by "
  270. "multiple packages. This is merely a convention, so all (W) and (U) "
  271. "directories are still searched on all platforms. "
  272. "Directories marked with (A) are intended for installations on "
  273. "Apple platforms. The cmake variables CMAKE_FIND_FRAMEWORK and "
  274. "CMAKE_FIND_APPBUNDLE determine the order of preference "
  275. "as specified below.\n"
  276. "The set of installation prefixes is constructed using the following "
  277. "steps. If NO_DEFAULT_PATH is specified all NO_* options are enabled.\n"
  278. "1. Search paths specified in cmake-specific cache variables. "
  279. "These are intended to be used on the command line with a -DVAR=value. "
  280. "This can be skipped if NO_CMAKE_PATH is passed.\n"
  281. " CMAKE_PREFIX_PATH\n"
  282. " CMAKE_FRAMEWORK_PATH\n"
  283. " CMAKE_APPBUNDLE_PATH\n"
  284. "2. Search paths specified in cmake-specific environment variables. "
  285. "These are intended to be set in the user's shell configuration. "
  286. "This can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.\n"
  287. " <package>_DIR\n"
  288. " CMAKE_PREFIX_PATH\n"
  289. " CMAKE_FRAMEWORK_PATH\n"
  290. " CMAKE_APPBUNDLE_PATH\n"
  291. "3. Search paths specified by the HINTS option. "
  292. "These should be paths computed by system introspection, such as a "
  293. "hint provided by the location of another item already found. "
  294. "Hard-coded guesses should be specified with the PATHS option.\n"
  295. "4. Search the standard system environment variables. "
  296. "This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. "
  297. "Path entries ending in \"/bin\" or \"/sbin\" are automatically "
  298. "converted to their parent directories.\n"
  299. " PATH\n"
  300. "5. Search project build trees recently configured in a CMake GUI. "
  301. "This can be skipped if NO_CMAKE_BUILDS_PATH is passed. "
  302. "It is intended for the case when a user is building multiple "
  303. "dependent projects one after another.\n"
  304. "6. Search paths stored in the CMake user package registry. "
  305. "This can be skipped if NO_CMAKE_PACKAGE_REGISTRY is passed. "
  306. "On Windows a <package> may appear under registry key\n"
  307. " HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Packages\\<package>\n"
  308. "as a REG_SZ value, with arbitrary name, that specifies the directory "
  309. "containing the package configuration file. "
  310. "On UNIX platforms a <package> may appear under the directory\n"
  311. " ~/.cmake/packages/<package>\n"
  312. "as a file, with arbitrary name, whose content specifies the directory "
  313. "containing the package configuration file. "
  314. "See the export(PACKAGE) command to create user package registry entries "
  315. "for project build trees."
  316. "\n"
  317. "7. Search cmake variables defined in the Platform files "
  318. "for the current system. This can be skipped if NO_CMAKE_SYSTEM_PATH "
  319. "is passed.\n"
  320. " CMAKE_SYSTEM_PREFIX_PATH\n"
  321. " CMAKE_SYSTEM_FRAMEWORK_PATH\n"
  322. " CMAKE_SYSTEM_APPBUNDLE_PATH\n"
  323. "8. Search paths stored in the CMake system package registry. "
  324. "This can be skipped if NO_CMAKE_SYSTEM_PACKAGE_REGISTRY is passed. "
  325. "On Windows a <package> may appear under registry key\n"
  326. " HKEY_LOCAL_MACHINE\\Software\\Kitware\\CMake\\Packages\\<package>\n"
  327. "as a REG_SZ value, with arbitrary name, that specifies the directory "
  328. "containing the package configuration file. "
  329. "There is no system package registry on non-Windows platforms."
  330. "\n"
  331. "9. Search paths specified by the PATHS option. "
  332. "These are typically hard-coded guesses.\n"
  333. ;
  334. this->CommandDocumentation += this->GenericDocumentationMacPolicy;
  335. this->CommandDocumentation += this->GenericDocumentationRootPath;
  336. this->CommandDocumentation += this->GenericDocumentationPathsOrder;
  337. this->CommandDocumentation +=
  338. "\n"
  339. "Every non-REQUIRED find_package() call can be disabled by setting the "
  340. "variable CMAKE_DISABLE_FIND_PACKAGE_<package> to TRUE. See the "
  341. "documentation for the CMAKE_DISABLE_FIND_PACKAGE_<package> variable for "
  342. "more information.\n"
  343. "See the cmake_policy() command documentation for discussion of the "
  344. "NO_POLICY_SCOPE option."
  345. ;
  346. }
  347. //----------------------------------------------------------------------------
  348. const char* cmFindPackageCommand::GetFullDocumentation() const
  349. {
  350. if(this->CommandDocumentation.empty())
  351. {
  352. const_cast<cmFindPackageCommand *>(this)->GenerateDocumentation();
  353. }
  354. return this->CommandDocumentation.c_str();
  355. }
  356. //----------------------------------------------------------------------------
  357. bool cmFindPackageCommand
  358. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  359. {
  360. if(args.size() < 1)
  361. {
  362. this->SetError("called with incorrect number of arguments");
  363. return false;
  364. }
  365. // Lookup required version of CMake.
  366. if(const char* rv =
  367. this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
  368. {
  369. unsigned int v[3] = {0,0,0};
  370. sscanf(rv, "%u.%u.%u", &v[0], &v[1], &v[2]);
  371. this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0],v[1],v[2]);
  372. }
  373. // Check for debug mode.
  374. this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
  375. // Lookup target architecture, if any.
  376. if(const char* arch =
  377. this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
  378. {
  379. this->LibraryArchitecture = arch;
  380. }
  381. // Lookup whether lib64 paths should be used.
  382. if(this->Makefile->PlatformIs64Bit() &&
  383. this->Makefile->GetCMakeInstance()
  384. ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
  385. {
  386. this->UseLib64Paths = true;
  387. }
  388. // Find the current root path mode.
  389. this->SelectDefaultRootPathMode();
  390. // Find the current bundle/framework search policy.
  391. this->SelectDefaultMacMode();
  392. // Record options.
  393. this->Name = args[0];
  394. std::string components;
  395. const char* components_sep = "";
  396. // Check ancient compatibility.
  397. this->Compatibility_1_6 =
  398. this->Makefile->GetLocalGenerator()
  399. ->NeedBackwardsCompatibility(1, 6);
  400. // Always search directly in a generated path.
  401. this->SearchPathSuffixes.push_back("");
  402. // Parse the arguments.
  403. enum Doing { DoingNone, DoingComponents, DoingNames, DoingPaths,
  404. DoingPathSuffixes, DoingConfigs, DoingHints };
  405. Doing doing = DoingNone;
  406. cmsys::RegularExpression version("^[0-9.]+$");
  407. bool haveVersion = false;
  408. std::set<unsigned int> configArgs;
  409. std::set<unsigned int> moduleArgs;
  410. for(unsigned int i=1; i < args.size(); ++i)
  411. {
  412. if(args[i] == "QUIET")
  413. {
  414. this->Quiet = true;
  415. doing = DoingNone;
  416. }
  417. else if(args[i] == "EXACT")
  418. {
  419. this->VersionExact = true;
  420. this->Compatibility_1_6 = false;
  421. doing = DoingNone;
  422. }
  423. else if(args[i] == "MODULE")
  424. {
  425. moduleArgs.insert(i);
  426. doing = DoingNone;
  427. }
  428. else if(args[i] == "CONFIG")
  429. {
  430. configArgs.insert(i);
  431. doing = DoingNone;
  432. }
  433. else if(args[i] == "NO_MODULE")
  434. {
  435. configArgs.insert(i);
  436. doing = DoingNone;
  437. }
  438. else if(args[i] == "REQUIRED")
  439. {
  440. this->Required = true;
  441. doing = DoingComponents;
  442. }
  443. else if(args[i] == "COMPONENTS")
  444. {
  445. this->Compatibility_1_6 = false;
  446. doing = DoingComponents;
  447. }
  448. else if(args[i] == "NAMES")
  449. {
  450. configArgs.insert(i);
  451. this->Compatibility_1_6 = false;
  452. doing = DoingNames;
  453. }
  454. else if(args[i] == "PATHS")
  455. {
  456. configArgs.insert(i);
  457. this->Compatibility_1_6 = false;
  458. doing = DoingPaths;
  459. }
  460. else if(args[i] == "HINTS")
  461. {
  462. configArgs.insert(i);
  463. this->Compatibility_1_6 = false;
  464. doing = DoingHints;
  465. }
  466. else if(args[i] == "PATH_SUFFIXES")
  467. {
  468. configArgs.insert(i);
  469. this->Compatibility_1_6 = false;
  470. doing = DoingPathSuffixes;
  471. }
  472. else if(args[i] == "CONFIGS")
  473. {
  474. configArgs.insert(i);
  475. this->Compatibility_1_6 = false;
  476. doing = DoingConfigs;
  477. }
  478. else if(args[i] == "NO_POLICY_SCOPE")
  479. {
  480. this->PolicyScope = false;
  481. this->Compatibility_1_6 = false;
  482. doing = DoingNone;
  483. }
  484. else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
  485. {
  486. this->NoUserRegistry = true;
  487. configArgs.insert(i);
  488. this->Compatibility_1_6 = false;
  489. doing = DoingNone;
  490. }
  491. else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
  492. {
  493. this->NoSystemRegistry = true;
  494. configArgs.insert(i);
  495. this->Compatibility_1_6 = false;
  496. doing = DoingNone;
  497. }
  498. else if(args[i] == "NO_CMAKE_BUILDS_PATH")
  499. {
  500. this->NoBuilds = true;
  501. configArgs.insert(i);
  502. this->Compatibility_1_6 = false;
  503. doing = DoingNone;
  504. }
  505. else if(this->CheckCommonArgument(args[i]))
  506. {
  507. configArgs.insert(i);
  508. this->Compatibility_1_6 = false;
  509. doing = DoingNone;
  510. }
  511. else if(doing == DoingComponents)
  512. {
  513. // Set a variable telling the find script this component
  514. // is required.
  515. std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
  516. this->AddFindDefinition(req_var.c_str(), "1");
  517. // Append to the list of required components.
  518. components += components_sep;
  519. components += args[i];
  520. components_sep = ";";
  521. }
  522. else if(doing == DoingNames)
  523. {
  524. this->Names.push_back(args[i]);
  525. }
  526. else if(doing == DoingPaths)
  527. {
  528. this->AddUserPath(args[i], this->UserPaths);
  529. }
  530. else if(doing == DoingHints)
  531. {
  532. this->AddUserPath(args[i], this->UserHints);
  533. }
  534. else if(doing == DoingPathSuffixes)
  535. {
  536. this->AddPathSuffix(args[i]);
  537. }
  538. else if(doing == DoingConfigs)
  539. {
  540. if(args[i].find_first_of(":/\\") != args[i].npos ||
  541. cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake")
  542. {
  543. cmOStringStream e;
  544. e << "given CONFIGS option followed by invalid file name \""
  545. << args[i] << "\". The names given must be file names without "
  546. << "a path and with a \".cmake\" extension.";
  547. this->SetError(e.str().c_str());
  548. return false;
  549. }
  550. this->Configs.push_back(args[i]);
  551. }
  552. else if(!haveVersion && version.find(args[i].c_str()))
  553. {
  554. haveVersion = true;
  555. this->Version = args[i];
  556. }
  557. else
  558. {
  559. cmOStringStream e;
  560. e << "called with invalid argument \"" << args[i].c_str() << "\"";
  561. this->SetError(e.str().c_str());
  562. return false;
  563. }
  564. }
  565. // Maybe choose one mode exclusively.
  566. this->UseFindModules = configArgs.empty();
  567. this->UseConfigFiles = moduleArgs.empty();
  568. if(!this->UseFindModules && !this->UseConfigFiles)
  569. {
  570. cmOStringStream e;
  571. e << "given options exclusive to Module mode:\n";
  572. for(std::set<unsigned int>::const_iterator si = moduleArgs.begin();
  573. si != moduleArgs.end(); ++si)
  574. {
  575. e << " " << args[*si] << "\n";
  576. }
  577. e << "and options exclusive to Config mode:\n";
  578. for(std::set<unsigned int>::const_iterator si = configArgs.begin();
  579. si != configArgs.end(); ++si)
  580. {
  581. e << " " << args[*si] << "\n";
  582. }
  583. e << "The options are incompatible.";
  584. this->SetError(e.str().c_str());
  585. return false;
  586. }
  587. // Ignore EXACT with no version.
  588. if(this->Version.empty() && this->VersionExact)
  589. {
  590. this->VersionExact = false;
  591. this->Makefile->IssueMessage(
  592. cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested.");
  593. }
  594. if(this->Version.empty() || components.empty())
  595. {
  596. // Check whether we are recursing inside "Find<name>.cmake" within
  597. // another find_package(<name>) call.
  598. std::string mod = this->Name;
  599. mod += "_FIND_MODULE";
  600. if(this->Makefile->IsOn(mod.c_str()))
  601. {
  602. if(this->Version.empty())
  603. {
  604. // Get version information from the outer call if necessary.
  605. // Requested version string.
  606. std::string ver = this->Name;
  607. ver += "_FIND_VERSION";
  608. this->Version = this->Makefile->GetSafeDefinition(ver.c_str());
  609. // Whether an exact version is required.
  610. std::string exact = this->Name;
  611. exact += "_FIND_VERSION_EXACT";
  612. this->VersionExact = this->Makefile->IsOn(exact.c_str());
  613. }
  614. if(components.empty())
  615. {
  616. std::string components_var = this->Name + "_FIND_COMPONENTS";
  617. components = this->Makefile->GetSafeDefinition(components_var.c_str());
  618. }
  619. }
  620. }
  621. if(!this->Version.empty())
  622. {
  623. // Try to parse the version number and store the results that were
  624. // successfully parsed.
  625. unsigned int parsed_major;
  626. unsigned int parsed_minor;
  627. unsigned int parsed_patch;
  628. unsigned int parsed_tweak;
  629. this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u.%u",
  630. &parsed_major, &parsed_minor,
  631. &parsed_patch, &parsed_tweak);
  632. switch(this->VersionCount)
  633. {
  634. case 4: this->VersionTweak = parsed_tweak; // no break!
  635. case 3: this->VersionPatch = parsed_patch; // no break!
  636. case 2: this->VersionMinor = parsed_minor; // no break!
  637. case 1: this->VersionMajor = parsed_major; // no break!
  638. default: break;
  639. }
  640. }
  641. std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_";
  642. disableFindPackageVar += this->Name;
  643. if(this->Makefile->IsOn(disableFindPackageVar.c_str()))
  644. {
  645. if (this->Required)
  646. {
  647. cmOStringStream e;
  648. e << "for module " << this->Name << " called with REQUIRED, but "
  649. << disableFindPackageVar
  650. << " is enabled. A REQUIRED package cannot be disabled.";
  651. this->SetError(e.str().c_str());
  652. return false;
  653. }
  654. return true;
  655. }
  656. this->SetModuleVariables(components);
  657. // See if there is a Find<package>.cmake module.
  658. if(this->UseFindModules)
  659. {
  660. bool foundModule = false;
  661. if(!this->FindModule(foundModule))
  662. {
  663. this->AppendSuccessInformation();
  664. return false;
  665. }
  666. if(foundModule)
  667. {
  668. this->AppendSuccessInformation();
  669. return true;
  670. }
  671. }
  672. if(this->UseFindModules && this->UseConfigFiles &&
  673. this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE"))
  674. {
  675. cmOStringStream aw;
  676. if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8))
  677. {
  678. aw << "find_package called without either MODULE or CONFIG option and "
  679. "no Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
  680. "Add MODULE to exclusively request Module mode and fail if "
  681. "Find" << this->Name << ".cmake is missing. "
  682. "Add CONFIG to exclusively request Config mode and search for a "
  683. "package configuration file provided by " << this->Name <<
  684. " (" << this->Name << "Config.cmake or " <<
  685. cmSystemTools::LowerCase(this->Name) << "-config.cmake). ";
  686. }
  687. else
  688. {
  689. aw << "find_package called without NO_MODULE option and no "
  690. "Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
  691. "Add NO_MODULE to exclusively request Config mode and search for a "
  692. "package configuration file provided by " << this->Name <<
  693. " (" << this->Name << "Config.cmake or " <<
  694. cmSystemTools::LowerCase(this->Name) << "-config.cmake). "
  695. "Otherwise make Find" << this->Name << ".cmake available in "
  696. "CMAKE_MODULE_PATH.";
  697. }
  698. aw << "\n"
  699. "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)";
  700. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
  701. }
  702. // No find module. Assume the project has a CMake config file. Use
  703. // a <package>_DIR cache variable to locate it.
  704. this->Variable = this->Name;
  705. this->Variable += "_DIR";
  706. // Add the default name.
  707. if(this->Names.empty())
  708. {
  709. this->Names.push_back(this->Name);
  710. }
  711. // Add the default configs.
  712. if(this->Configs.empty())
  713. {
  714. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  715. ni != this->Names.end(); ++ni)
  716. {
  717. std::string config = *ni;
  718. config += "Config.cmake";
  719. this->Configs.push_back(config);
  720. config = cmSystemTools::LowerCase(*ni);
  721. config += "-config.cmake";
  722. this->Configs.push_back(config);
  723. }
  724. }
  725. // get igonored paths from vars and reroot them.
  726. std::vector<std::string> ignored;
  727. this->GetIgnoredPaths(ignored);
  728. this->RerootPaths(ignored);
  729. // Construct a set of ignored paths
  730. this->IgnoredPaths.clear();
  731. this->IgnoredPaths.insert(ignored.begin(), ignored.end());
  732. // Find and load the package.
  733. bool result = this->HandlePackageMode();
  734. this->AppendSuccessInformation();
  735. return result;
  736. }
  737. //----------------------------------------------------------------------------
  738. void cmFindPackageCommand::SetModuleVariables(const std::string& components)
  739. {
  740. // Store the list of components.
  741. std::string components_var = this->Name + "_FIND_COMPONENTS";
  742. this->AddFindDefinition(components_var.c_str(), components.c_str());
  743. if(this->Quiet)
  744. {
  745. // Tell the module that is about to be read that it should find
  746. // quietly.
  747. std::string quietly = this->Name;
  748. quietly += "_FIND_QUIETLY";
  749. this->AddFindDefinition(quietly.c_str(), "1");
  750. }
  751. if(this->Required)
  752. {
  753. // Tell the module that is about to be read that it should report
  754. // a fatal error if the package is not found.
  755. std::string req = this->Name;
  756. req += "_FIND_REQUIRED";
  757. this->AddFindDefinition(req.c_str(), "1");
  758. }
  759. if(!this->Version.empty())
  760. {
  761. // Tell the module that is about to be read what version of the
  762. // package has been requested.
  763. std::string ver = this->Name;
  764. ver += "_FIND_VERSION";
  765. this->AddFindDefinition(ver.c_str(), this->Version.c_str());
  766. char buf[64];
  767. sprintf(buf, "%u", this->VersionMajor);
  768. this->AddFindDefinition((ver+"_MAJOR").c_str(), buf);
  769. sprintf(buf, "%u", this->VersionMinor);
  770. this->AddFindDefinition((ver+"_MINOR").c_str(), buf);
  771. sprintf(buf, "%u", this->VersionPatch);
  772. this->AddFindDefinition((ver+"_PATCH").c_str(), buf);
  773. sprintf(buf, "%u", this->VersionTweak);
  774. this->AddFindDefinition((ver+"_TWEAK").c_str(), buf);
  775. sprintf(buf, "%u", this->VersionCount);
  776. this->AddFindDefinition((ver+"_COUNT").c_str(), buf);
  777. // Tell the module whether an exact version has been requested.
  778. std::string exact = this->Name;
  779. exact += "_FIND_VERSION_EXACT";
  780. this->AddFindDefinition(exact.c_str(), this->VersionExact? "1":"0");
  781. }
  782. }
  783. //----------------------------------------------------------------------------
  784. void cmFindPackageCommand::AddFindDefinition(const char* var, const char* val)
  785. {
  786. if(const char* old = this->Makefile->GetDefinition(var))
  787. {
  788. this->OriginalDefs[var].exists = true;
  789. this->OriginalDefs[var].value = old;
  790. }
  791. else
  792. {
  793. this->OriginalDefs[var].exists = false;
  794. }
  795. this->Makefile->AddDefinition(var, val);
  796. }
  797. //----------------------------------------------------------------------------
  798. void cmFindPackageCommand::RestoreFindDefinitions()
  799. {
  800. for(std::map<cmStdString, OriginalDef>::iterator
  801. i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
  802. {
  803. OriginalDef const& od = i->second;
  804. if(od.exists)
  805. {
  806. this->Makefile->AddDefinition(i->first.c_str(), od.value.c_str());
  807. }
  808. else
  809. {
  810. this->Makefile->RemoveDefinition(i->first.c_str());
  811. }
  812. }
  813. }
  814. //----------------------------------------------------------------------------
  815. bool cmFindPackageCommand::FindModule(bool& found)
  816. {
  817. std::string module = "Find";
  818. module += this->Name;
  819. module += ".cmake";
  820. std::string mfile = this->Makefile->GetModulesFile(module.c_str());
  821. if ( mfile.size() )
  822. {
  823. // Load the module we found, and set "<name>_FIND_MODULE" to true
  824. // while inside it.
  825. found = true;
  826. std::string var = this->Name;
  827. var += "_FIND_MODULE";
  828. this->Makefile->AddDefinition(var.c_str(), "1");
  829. bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
  830. this->Makefile->RemoveDefinition(var.c_str());
  831. return result;
  832. }
  833. return true;
  834. }
  835. //----------------------------------------------------------------------------
  836. bool cmFindPackageCommand::HandlePackageMode()
  837. {
  838. this->ConsideredConfigs.clear();
  839. // Support old capitalization behavior.
  840. std::string upperDir = cmSystemTools::UpperCase(this->Name);
  841. std::string upperFound = cmSystemTools::UpperCase(this->Name);
  842. upperDir += "_DIR";
  843. upperFound += "_FOUND";
  844. if(upperDir == this->Variable)
  845. {
  846. this->Compatibility_1_6 = false;
  847. }
  848. // Try to find the config file.
  849. const char* def = this->Makefile->GetDefinition(this->Variable.c_str());
  850. if(this->Compatibility_1_6 && cmSystemTools::IsOff(def))
  851. {
  852. // Use the setting of the old name of the variable to provide the
  853. // value of the new.
  854. const char* oldDef = this->Makefile->GetDefinition(upperDir.c_str());
  855. if(!cmSystemTools::IsOff(oldDef))
  856. {
  857. this->Makefile->AddDefinition(this->Variable.c_str(), oldDef);
  858. def = this->Makefile->GetDefinition(this->Variable.c_str());
  859. }
  860. }
  861. // Try to load the config file if the directory is known
  862. bool fileFound = false;
  863. if (this->UseConfigFiles)
  864. {
  865. if(!cmSystemTools::IsOff(def))
  866. {
  867. // Get the directory from the variable value.
  868. std::string dir = def;
  869. cmSystemTools::ConvertToUnixSlashes(dir);
  870. // Treat relative paths with respect to the current source dir.
  871. if(!cmSystemTools::FileIsFullPath(dir.c_str()))
  872. {
  873. dir = "/" + dir;
  874. dir = this->Makefile->GetCurrentDirectory() + dir;
  875. }
  876. // The file location was cached. Look for the correct file.
  877. std::string file;
  878. if (this->FindConfigFile(dir, file))
  879. {
  880. this->FileFound = file;
  881. fileFound = true;
  882. }
  883. def = this->Makefile->GetDefinition(this->Variable.c_str());
  884. }
  885. // Search for the config file if it is not already found.
  886. if(cmSystemTools::IsOff(def) || !fileFound)
  887. {
  888. fileFound = this->FindConfig();
  889. def = this->Makefile->GetDefinition(this->Variable.c_str());
  890. }
  891. // Sanity check.
  892. if(fileFound && this->FileFound.empty())
  893. {
  894. this->Makefile->IssueMessage(
  895. cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
  896. fileFound = false;
  897. }
  898. }
  899. // If the directory for the config file was found, try to read the file.
  900. bool result = true;
  901. bool found = false;
  902. if(fileFound)
  903. {
  904. // Set the version variables before loading the config file.
  905. // It may override them.
  906. this->StoreVersionFound();
  907. // Parse the configuration file.
  908. if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
  909. {
  910. // The package has been found.
  911. found = true;
  912. }
  913. else
  914. {
  915. // The configuration file is invalid.
  916. result = false;
  917. }
  918. }
  919. else if(!this->Quiet || this->Required)
  920. {
  921. // The variable is not set.
  922. cmOStringStream e;
  923. cmOStringStream aw;
  924. // If there are files in ConsideredConfigs, it means that FooConfig.cmake
  925. // have been found, but they didn't have appropriate versions.
  926. if (this->ConsideredConfigs.size() > 0)
  927. {
  928. e << "Could not find a configuration file for package \""
  929. << this->Name << "\" that "
  930. << (this->VersionExact? "exactly matches" : "is compatible with")
  931. << " requested version \"" << this->Version << "\".\n"
  932. << "The following configuration files were considered but not "
  933. "accepted:\n";
  934. for(std::vector<ConfigFileInfo>::size_type i=0;
  935. i<this->ConsideredConfigs.size(); i++)
  936. {
  937. e << " " << this->ConsideredConfigs[i].filename
  938. << ", version: " << this->ConsideredConfigs[i].version << "\n";
  939. }
  940. }
  941. else
  942. {
  943. std::string requestedVersionString;
  944. if(!this->Version.empty())
  945. {
  946. requestedVersionString = " (requested version ";
  947. requestedVersionString += this->Version;
  948. requestedVersionString += ")";
  949. }
  950. if (this->UseConfigFiles)
  951. {
  952. if(this->UseFindModules)
  953. {
  954. e << "By not providing \"Find" << this->Name << ".cmake\" in "
  955. "CMAKE_MODULE_PATH this project has asked CMake to find a "
  956. "package configuration file provided by \""<<this->Name<< "\", "
  957. "but CMake did not find one.\n";
  958. }
  959. if(this->Configs.size() == 1)
  960. {
  961. e << "Could not find a package configuration file named \""
  962. << this->Configs[0] << "\" provided by package \""
  963. << this->Name << "\"" << requestedVersionString <<".\n";
  964. }
  965. else
  966. {
  967. e << "Could not find a package configuration file provided by \""
  968. << this->Name << "\"" << requestedVersionString
  969. << " with any of the following names:\n";
  970. for(std::vector<std::string>::const_iterator ci =
  971. this->Configs.begin();
  972. ci != this->Configs.end(); ++ci)
  973. {
  974. e << " " << *ci << "\n";
  975. }
  976. }
  977. e << "Add the installation prefix of \"" << this->Name << "\" to "
  978. "CMAKE_PREFIX_PATH or set \"" << this->Variable << "\" to a "
  979. "directory containing one of the above files. "
  980. "If \"" << this->Name << "\" provides a separate development "
  981. "package or SDK, be sure it has been installed.";
  982. }
  983. else // if(!this->UseFindModules && !this->UseConfigFiles)
  984. {
  985. e << "No \"Find" << this->Name << ".cmake\" found in "
  986. << "CMAKE_MODULE_PATH.";
  987. aw<< "Find"<< this->Name <<".cmake must either be part of this "
  988. "project itself, in this case adjust CMAKE_MODULE_PATH so that "
  989. "it points to the correct location inside its source tree.\n"
  990. "Or it must be installed by a package which has already been "
  991. "found via find_package(). In this case make sure that "
  992. "package has indeed been found and adjust CMAKE_MODULE_PATH to "
  993. "contain the location where that package has installed "
  994. "Find" << this->Name << ".cmake. This must be a location "
  995. "provided by that package. This error in general means that "
  996. "the buildsystem of this project is relying on a Find-module "
  997. "without ensuring that it is actually available.\n";
  998. }
  999. }
  1000. this->Makefile->IssueMessage(
  1001. this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
  1002. if (!aw.str().empty())
  1003. {
  1004. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
  1005. }
  1006. }
  1007. // Set a variable marking whether the package was found.
  1008. std::string foundVar = this->Name;
  1009. foundVar += "_FOUND";
  1010. this->Makefile->AddDefinition(foundVar.c_str(), found? "1":"0");
  1011. // Set a variable naming the configuration file that was found.
  1012. std::string fileVar = this->Name;
  1013. fileVar += "_CONFIG";
  1014. if(found)
  1015. {
  1016. this->Makefile->AddDefinition(fileVar.c_str(), this->FileFound.c_str());
  1017. }
  1018. else
  1019. {
  1020. this->Makefile->RemoveDefinition(fileVar.c_str());
  1021. }
  1022. // Handle some ancient compatibility stuff.
  1023. if(this->Compatibility_1_6)
  1024. {
  1025. // Listfiles will be looking for the capitalized version of the
  1026. // name. Provide it.
  1027. this->Makefile->AddDefinition
  1028. (upperDir.c_str(),
  1029. this->Makefile->GetDefinition(this->Variable.c_str()));
  1030. this->Makefile->AddDefinition
  1031. (upperFound.c_str(),
  1032. this->Makefile->GetDefinition(foundVar.c_str()));
  1033. }
  1034. #ifdef CMAKE_BUILD_WITH_CMAKE
  1035. if(!(upperDir == this->Variable))
  1036. {
  1037. if(this->Compatibility_1_6)
  1038. {
  1039. // Listfiles may use the capitalized version of the name.
  1040. // Remove any previously added watch.
  1041. this->Makefile->GetVariableWatch()->RemoveWatch(
  1042. upperDir.c_str(),
  1043. cmFindPackageNeedBackwardsCompatibility
  1044. );
  1045. }
  1046. else
  1047. {
  1048. // Listfiles should not be using the capitalized version of the
  1049. // name. Add a watch to warn the user.
  1050. this->Makefile->GetVariableWatch()->AddWatch(
  1051. upperDir.c_str(),
  1052. cmFindPackageNeedBackwardsCompatibility
  1053. );
  1054. }
  1055. }
  1056. #endif
  1057. std::string consideredConfigsVar = this->Name;
  1058. consideredConfigsVar += "_CONSIDERED_CONFIGS";
  1059. std::string consideredVersionsVar = this->Name;
  1060. consideredVersionsVar += "_CONSIDERED_VERSIONS";
  1061. std::string consideredConfigFiles;
  1062. std::string consideredVersions;
  1063. const char* sep = "";
  1064. for(std::vector<ConfigFileInfo>::size_type i=0;
  1065. i<this->ConsideredConfigs.size(); i++)
  1066. {
  1067. consideredConfigFiles += sep;
  1068. consideredVersions += sep;
  1069. consideredConfigFiles += this->ConsideredConfigs[i].filename;
  1070. consideredVersions += this->ConsideredConfigs[i].version;
  1071. sep = ";";
  1072. }
  1073. this->Makefile->AddDefinition(consideredConfigsVar.c_str(),
  1074. consideredConfigFiles.c_str());
  1075. this->Makefile->AddDefinition(consideredVersionsVar.c_str(),
  1076. consideredVersions.c_str());
  1077. return result;
  1078. }
  1079. //----------------------------------------------------------------------------
  1080. bool cmFindPackageCommand::FindConfig()
  1081. {
  1082. // Compute the set of search prefixes.
  1083. this->ComputePrefixes();
  1084. // Look for the project's configuration file.
  1085. bool found = false;
  1086. // Search for frameworks.
  1087. if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
  1088. {
  1089. found = this->FindFrameworkConfig();
  1090. }
  1091. // Search for apps.
  1092. if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
  1093. {
  1094. found = this->FindAppBundleConfig();
  1095. }
  1096. // Search prefixes.
  1097. if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
  1098. {
  1099. found = this->FindPrefixedConfig();
  1100. }
  1101. // Search for frameworks.
  1102. if(!found && this->SearchFrameworkLast)
  1103. {
  1104. found = this->FindFrameworkConfig();
  1105. }
  1106. // Search for apps.
  1107. if(!found && this->SearchAppBundleLast)
  1108. {
  1109. found = this->FindAppBundleConfig();
  1110. }
  1111. // Store the entry in the cache so it can be set by the user.
  1112. std::string init;
  1113. if(found)
  1114. {
  1115. init = cmSystemTools::GetFilenamePath(this->FileFound);
  1116. }
  1117. else
  1118. {
  1119. init = this->Variable + "-NOTFOUND";
  1120. }
  1121. std::string help =
  1122. "The directory containing a CMake configuration file for ";
  1123. help += this->Name;
  1124. help += ".";
  1125. // We force the value since we do not get here if it was already set.
  1126. this->Makefile->AddCacheDefinition(this->Variable.c_str(),
  1127. init.c_str(), help.c_str(),
  1128. cmCacheManager::PATH, true);
  1129. return found;
  1130. }
  1131. //----------------------------------------------------------------------------
  1132. bool cmFindPackageCommand::FindPrefixedConfig()
  1133. {
  1134. std::vector<std::string>& prefixes = this->SearchPaths;
  1135. for(std::vector<std::string>::const_iterator pi = prefixes.begin();
  1136. pi != prefixes.end(); ++pi)
  1137. {
  1138. if(this->SearchPrefix(*pi))
  1139. {
  1140. return true;
  1141. }
  1142. }
  1143. return false;
  1144. }
  1145. //----------------------------------------------------------------------------
  1146. bool cmFindPackageCommand::FindFrameworkConfig()
  1147. {
  1148. std::vector<std::string>& prefixes = this->SearchPaths;
  1149. for(std::vector<std::string>::const_iterator i = prefixes.begin();
  1150. i != prefixes.end(); ++i)
  1151. {
  1152. if(this->SearchFrameworkPrefix(*i))
  1153. {
  1154. return true;
  1155. }
  1156. }
  1157. return false;
  1158. }
  1159. //----------------------------------------------------------------------------
  1160. bool cmFindPackageCommand::FindAppBundleConfig()
  1161. {
  1162. std::vector<std::string>& prefixes = this->SearchPaths;
  1163. for(std::vector<std::string>::const_iterator i = prefixes.begin();
  1164. i != prefixes.end(); ++i)
  1165. {
  1166. if(this->SearchAppBundlePrefix(*i))
  1167. {
  1168. return true;
  1169. }
  1170. }
  1171. return false;
  1172. }
  1173. //----------------------------------------------------------------------------
  1174. bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
  1175. {
  1176. if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), f, 0,
  1177. !this->PolicyScope || psr == NoPolicyScope))
  1178. {
  1179. return true;
  1180. }
  1181. std::string e = "Error reading CMake code from \"";
  1182. e += f;
  1183. e += "\".";
  1184. this->SetError(e.c_str());
  1185. return false;
  1186. }
  1187. //----------------------------------------------------------------------------
  1188. void cmFindPackageCommand::AppendToProperty(const char* propertyName)
  1189. {
  1190. std::string propertyValue;
  1191. const char *prop =
  1192. this->Makefile->GetCMakeInstance()->GetProperty(propertyName);
  1193. if (prop && *prop)
  1194. {
  1195. propertyValue = prop;
  1196. std::vector<std::string> contents;
  1197. cmSystemTools::ExpandListArgument(propertyValue, contents, false);
  1198. bool alreadyInserted = false;
  1199. for(std::vector<std::string>::const_iterator it = contents.begin();
  1200. it != contents.end(); ++ it )
  1201. {
  1202. if (*it == this->Name)
  1203. {
  1204. alreadyInserted = true;
  1205. break;
  1206. }
  1207. }
  1208. if (!alreadyInserted)
  1209. {
  1210. propertyValue += ";";
  1211. propertyValue += this->Name;
  1212. }
  1213. }
  1214. else
  1215. {
  1216. propertyValue = this->Name;
  1217. }
  1218. this->Makefile->GetCMakeInstance()->SetProperty(propertyName,
  1219. propertyValue.c_str());
  1220. }
  1221. //----------------------------------------------------------------------------
  1222. void cmFindPackageCommand::AppendSuccessInformation()
  1223. {
  1224. std::string found = this->Name;
  1225. found += "_FOUND";
  1226. std::string upperFound = cmSystemTools::UpperCase(found);
  1227. const char* upperResult = this->Makefile->GetDefinition(upperFound.c_str());
  1228. const char* result = this->Makefile->GetDefinition(found.c_str());
  1229. if ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult)))
  1230. {
  1231. this->AppendToProperty("PACKAGES_FOUND");
  1232. }
  1233. else
  1234. {
  1235. this->AppendToProperty("PACKAGES_NOT_FOUND");
  1236. }
  1237. // Record whether the find was quiet or not, so this can be used
  1238. // e.g. in FeatureSummary.cmake
  1239. std::string quietInfoPropName = "_CMAKE_";
  1240. quietInfoPropName += this->Name;
  1241. quietInfoPropName += "_QUIET";
  1242. this->Makefile->GetCMakeInstance()->SetProperty(quietInfoPropName.c_str(),
  1243. this->Quiet ? "TRUE" : "FALSE");
  1244. // set a global property to record the required version of this package
  1245. std::string versionInfoPropName = "_CMAKE_";
  1246. versionInfoPropName += this->Name;
  1247. versionInfoPropName += "_REQUIRED_VERSION";
  1248. std::string versionInfo;
  1249. if(!this->Version.empty())
  1250. {
  1251. versionInfo = this->VersionExact ? "==" : ">=";
  1252. versionInfo += " ";
  1253. versionInfo += this->Version;
  1254. }
  1255. this->Makefile->GetCMakeInstance()->SetProperty(versionInfoPropName.c_str(),
  1256. versionInfo.c_str());
  1257. if (this->Required)
  1258. {
  1259. std::string requiredInfoPropName = "_CMAKE_";
  1260. requiredInfoPropName += this->Name;
  1261. requiredInfoPropName += "_TYPE";
  1262. this->Makefile->GetCMakeInstance()->SetProperty(
  1263. requiredInfoPropName.c_str(), "REQUIRED");
  1264. }
  1265. // Restore original state of "_FIND_" variables we set.
  1266. this->RestoreFindDefinitions();
  1267. }
  1268. //----------------------------------------------------------------------------
  1269. void cmFindPackageCommand::ComputePrefixes()
  1270. {
  1271. this->AddPrefixesCMakeVariable();
  1272. this->AddPrefixesCMakeEnvironment();
  1273. this->AddPrefixesUserHints();
  1274. this->AddPrefixesSystemEnvironment();
  1275. this->AddPrefixesUserRegistry();
  1276. this->AddPrefixesBuilds();
  1277. this->AddPrefixesCMakeSystemVariable();
  1278. this->AddPrefixesSystemRegistry();
  1279. this->AddPrefixesUserGuess();
  1280. this->ComputeFinalPaths();
  1281. }
  1282. //----------------------------------------------------------------------------
  1283. void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
  1284. {
  1285. if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
  1286. {
  1287. // Check the environment variable with the same name as the cache
  1288. // entry.
  1289. std::string env;
  1290. if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
  1291. {
  1292. cmSystemTools::ConvertToUnixSlashes(env);
  1293. this->AddPathInternal(env, EnvPath);
  1294. }
  1295. this->AddEnvPath("CMAKE_PREFIX_PATH");
  1296. this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
  1297. this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
  1298. }
  1299. }
  1300. //----------------------------------------------------------------------------
  1301. void cmFindPackageCommand::AddPrefixesCMakeVariable()
  1302. {
  1303. if(!this->NoCMakePath && !this->NoDefaultPath)
  1304. {
  1305. this->AddCMakePath("CMAKE_PREFIX_PATH");
  1306. this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
  1307. this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
  1308. }
  1309. }
  1310. //----------------------------------------------------------------------------
  1311. void cmFindPackageCommand::AddPrefixesSystemEnvironment()
  1312. {
  1313. if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
  1314. {
  1315. // Use the system search path to generate prefixes.
  1316. // Relative paths are interpreted with respect to the current
  1317. // working directory.
  1318. std::vector<std::string> tmp;
  1319. cmSystemTools::GetPath(tmp);
  1320. for(std::vector<std::string>::iterator i = tmp.begin();
  1321. i != tmp.end(); ++i)
  1322. {
  1323. std::string const& d = *i;
  1324. // If the path is a PREFIX/bin case then add its parent instead.
  1325. if((d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0) ||
  1326. (d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0))
  1327. {
  1328. this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
  1329. }
  1330. else
  1331. {
  1332. this->AddPathInternal(d, EnvPath);
  1333. }
  1334. }
  1335. }
  1336. }
  1337. //----------------------------------------------------------------------------
  1338. void cmFindPackageCommand::AddPrefixesUserRegistry()
  1339. {
  1340. if(this->NoUserRegistry || this->NoDefaultPath)
  1341. {
  1342. return;
  1343. }
  1344. #if defined(_WIN32) && !defined(__CYGWIN__)
  1345. this->LoadPackageRegistryWinUser();
  1346. #elif defined(__HAIKU__)
  1347. BPath dir;
  1348. if (find_directory(B_USER_SETTINGS_DIRECTORY, &dir) == B_OK)
  1349. {
  1350. dir.Append("cmake/packages");
  1351. dir.Append(this->Name.c_str());
  1352. this->LoadPackageRegistryDir(dir.Path());
  1353. }
  1354. #else
  1355. if(const char* home = cmSystemTools::GetEnv("HOME"))
  1356. {
  1357. std::string dir = home;
  1358. dir += "/.cmake/packages/";
  1359. dir += this->Name;
  1360. this->LoadPackageRegistryDir(dir);
  1361. }
  1362. #endif
  1363. }
  1364. //----------------------------------------------------------------------------
  1365. void cmFindPackageCommand::AddPrefixesSystemRegistry()
  1366. {
  1367. if(this->NoSystemRegistry || this->NoDefaultPath)
  1368. {
  1369. return;
  1370. }
  1371. #if defined(_WIN32) && !defined(__CYGWIN__)
  1372. this->LoadPackageRegistryWinSystem();
  1373. #endif
  1374. }
  1375. #if defined(_WIN32) && !defined(__CYGWIN__)
  1376. # include <windows.h>
  1377. # undef GetCurrentDirectory
  1378. // http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
  1379. # if !defined(KEY_WOW64_32KEY)
  1380. # define KEY_WOW64_32KEY 0x0200
  1381. # endif
  1382. # if !defined(KEY_WOW64_64KEY)
  1383. # define KEY_WOW64_64KEY 0x0100
  1384. # endif
  1385. //----------------------------------------------------------------------------
  1386. void cmFindPackageCommand::LoadPackageRegistryWinUser()
  1387. {
  1388. // HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
  1389. this->LoadPackageRegistryWin(true, 0);
  1390. }
  1391. //----------------------------------------------------------------------------
  1392. void cmFindPackageCommand::LoadPackageRegistryWinSystem()
  1393. {
  1394. // HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
  1395. // Prefer the target platform view first.
  1396. if(this->Makefile->PlatformIs64Bit())
  1397. {
  1398. this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
  1399. this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
  1400. }
  1401. else
  1402. {
  1403. this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
  1404. this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
  1405. }
  1406. }
  1407. //----------------------------------------------------------------------------
  1408. void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
  1409. unsigned int view)
  1410. {
  1411. std::string key = "Software\\Kitware\\CMake\\Packages\\";
  1412. key += this->Name;
  1413. std::set<cmStdString> bad;
  1414. HKEY hKey;
  1415. if(RegOpenKeyEx(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
  1416. 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
  1417. {
  1418. DWORD valueType = REG_NONE;
  1419. char name[16384];
  1420. std::vector<char> data(512);
  1421. bool done = false;
  1422. DWORD index = 0;
  1423. while(!done)
  1424. {
  1425. DWORD nameSize = static_cast<DWORD>(sizeof(name));
  1426. DWORD dataSize = static_cast<DWORD>(data.size()-1);
  1427. switch(RegEnumValue(hKey, index, name, &nameSize,
  1428. 0, &valueType, (BYTE*)&data[0], &dataSize))
  1429. {
  1430. case ERROR_SUCCESS:
  1431. ++index;
  1432. if(valueType == REG_SZ)
  1433. {
  1434. data[dataSize] = 0;
  1435. cmsys_ios::stringstream ss(&data[0]);
  1436. if(!this->CheckPackageRegistryEntry(ss))
  1437. {
  1438. // The entry is invalid.
  1439. bad.insert(name);
  1440. }
  1441. }
  1442. break;
  1443. case ERROR_MORE_DATA:
  1444. data.resize(dataSize+1);
  1445. break;
  1446. case ERROR_NO_MORE_ITEMS: default: done = true; break;
  1447. }
  1448. }
  1449. RegCloseKey(hKey);
  1450. }
  1451. // Remove bad values if possible.
  1452. if(user && !bad.empty() &&
  1453. RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(),
  1454. 0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
  1455. {
  1456. for(std::set<cmStdString>::const_iterator vi = bad.begin();
  1457. vi != bad.end(); ++vi)
  1458. {
  1459. RegDeleteValue(hKey, vi->c_str());
  1460. }
  1461. RegCloseKey(hKey);
  1462. }
  1463. }
  1464. #else
  1465. //----------------------------------------------------------------------------
  1466. class cmFindPackageCommandHoldFile
  1467. {
  1468. const char* File;
  1469. public:
  1470. cmFindPackageCommandHoldFile(const char* f): File(f) {}
  1471. ~cmFindPackageCommandHoldFile()
  1472. { if(this->File) { cmSystemTools::RemoveFile(this->File); } }
  1473. void Release() { this->File = 0; }
  1474. };
  1475. //----------------------------------------------------------------------------
  1476. void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
  1477. {
  1478. cmsys::Directory files;
  1479. if(!files.Load(dir.c_str()))
  1480. {
  1481. return;
  1482. }
  1483. std::string fname;
  1484. for(unsigned long i=0; i < files.GetNumberOfFiles(); ++i)
  1485. {
  1486. fname = dir;
  1487. fname += "/";
  1488. fname += files.GetFile(i);
  1489. if(!cmSystemTools::FileIsDirectory(fname.c_str()))
  1490. {
  1491. // Hold this file hostage until it behaves.
  1492. cmFindPackageCommandHoldFile holdFile(fname.c_str());
  1493. // Load the file.
  1494. std::ifstream fin(fname.c_str(), std::ios::in | cmsys_ios_binary);
  1495. if(fin && this->CheckPackageRegistryEntry(fin))
  1496. {
  1497. // The file references an existing package, so release it.
  1498. holdFile.Release();
  1499. }
  1500. }
  1501. }
  1502. // TODO: Wipe out the directory if it is empty.
  1503. }
  1504. #endif
  1505. //----------------------------------------------------------------------------
  1506. bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
  1507. {
  1508. // Parse the content of one package registry entry.
  1509. std::string fname;
  1510. if(cmSystemTools::GetLineFromStream(is, fname) &&
  1511. cmSystemTools::FileIsFullPath(fname.c_str()))
  1512. {
  1513. // The first line in the stream is the full path to a file or
  1514. // directory containing the package.
  1515. if(cmSystemTools::FileExists(fname.c_str()))
  1516. {
  1517. // The path exists. Look for the package here.
  1518. if(!cmSystemTools::FileIsDirectory(fname.c_str()))
  1519. {
  1520. fname = cmSystemTools::GetFilenamePath(fname);
  1521. }
  1522. this->AddPathInternal(fname, FullPath);
  1523. return true;
  1524. }
  1525. else
  1526. {
  1527. // The path does not exist. Assume the stream content is
  1528. // associated with an old package that no longer exists, and
  1529. // delete it to keep the package registry clean.
  1530. return false;
  1531. }
  1532. }
  1533. else
  1534. {
  1535. // The first line in the stream is not the full path to a file or
  1536. // directory. Assume the stream content was created by a future
  1537. // version of CMake that uses a different format, and leave it.
  1538. return true;
  1539. }
  1540. }
  1541. //----------------------------------------------------------------------------
  1542. void cmFindPackageCommand::AddPrefixesBuilds()
  1543. {
  1544. if(!this->NoBuilds && !this->NoDefaultPath)
  1545. {
  1546. // It is likely that CMake will have recently built the project.
  1547. for(int i=0; i <= 10; ++i)
  1548. {
  1549. cmOStringStream r;
  1550. r <<
  1551. "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
  1552. "Settings\\StartPath;WhereBuild" << i << "]";
  1553. std::string f = r.str();
  1554. cmSystemTools::ExpandRegistryValues(f);
  1555. cmSystemTools::ConvertToUnixSlashes(f);
  1556. if(cmSystemTools::FileIsFullPath(f.c_str()) &&
  1557. cmSystemTools::FileIsDirectory(f.c_str()))
  1558. {
  1559. this->AddPathInternal(f, FullPath);
  1560. }
  1561. }
  1562. }
  1563. }
  1564. //----------------------------------------------------------------------------
  1565. void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
  1566. {
  1567. if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
  1568. {
  1569. this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
  1570. this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
  1571. this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
  1572. }
  1573. }
  1574. //----------------------------------------------------------------------------
  1575. void cmFindPackageCommand::AddPrefixesUserGuess()
  1576. {
  1577. // Add guesses specified by the caller.
  1578. this->AddPathsInternal(this->UserPaths, CMakePath);
  1579. }
  1580. //----------------------------------------------------------------------------
  1581. void cmFindPackageCommand::AddPrefixesUserHints()
  1582. {
  1583. // Add hints specified by the caller.
  1584. this->AddPathsInternal(this->UserHints, CMakePath);
  1585. }
  1586. //----------------------------------------------------------------------------
  1587. bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
  1588. {
  1589. assert(!dir.empty() && dir[dir.size()-1] == '/');
  1590. // Check each path suffix on this directory.
  1591. for(std::vector<std::string>::const_iterator
  1592. si = this->SearchPathSuffixes.begin();
  1593. si != this->SearchPathSuffixes.end(); ++si)
  1594. {
  1595. std::string d = dir;
  1596. if(!si->empty())
  1597. {
  1598. d += *si;
  1599. d += "/";
  1600. }
  1601. if(this->CheckDirectory(d))
  1602. {
  1603. return true;
  1604. }
  1605. }
  1606. return false;
  1607. }
  1608. //----------------------------------------------------------------------------
  1609. bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
  1610. {
  1611. assert(!dir.empty() && dir[dir.size()-1] == '/');
  1612. // Look for the file in this directory.
  1613. std::string d = dir.substr(0, dir.size()-1);
  1614. if(this->FindConfigFile(d, this->FileFound))
  1615. {
  1616. // Remove duplicate slashes.
  1617. cmSystemTools::ConvertToUnixSlashes(this->FileFound);
  1618. return true;
  1619. }
  1620. return false;
  1621. }
  1622. //----------------------------------------------------------------------------
  1623. bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
  1624. std::string& file)
  1625. {
  1626. if (this->IgnoredPaths.count(dir))
  1627. {
  1628. return false;
  1629. }
  1630. for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
  1631. ci != this->Configs.end(); ++ci)
  1632. {
  1633. file = dir;
  1634. file += "/";
  1635. file += *ci;
  1636. if(this->DebugMode)
  1637. {
  1638. fprintf(stderr, "Checking file [%s]\n", file.c_str());
  1639. }
  1640. if(cmSystemTools::FileExists(file.c_str(), true) &&
  1641. this->CheckVersion(file))
  1642. {
  1643. return true;
  1644. }
  1645. }
  1646. return false;
  1647. }
  1648. //----------------------------------------------------------------------------
  1649. bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
  1650. {
  1651. bool result = false; // by default, assume the version is not ok.
  1652. bool haveResult = false;
  1653. std::string version = "unknown";
  1654. // Get the filename without the .cmake extension.
  1655. std::string::size_type pos = config_file.rfind('.');
  1656. std::string version_file_base = config_file.substr(0, pos);
  1657. // Look for foo-config-version.cmake
  1658. std::string version_file = version_file_base;
  1659. version_file += "-version.cmake";
  1660. if ((haveResult == false)
  1661. && (cmSystemTools::FileExists(version_file.c_str(), true)))
  1662. {
  1663. result = this->CheckVersionFile(version_file, version);
  1664. haveResult = true;
  1665. }
  1666. // Look for fooConfigVersion.cmake
  1667. version_file = version_file_base;
  1668. version_file += "Version.cmake";
  1669. if ((haveResult == false)
  1670. && (cmSystemTools::FileExists(version_file.c_str(), true)))
  1671. {
  1672. result = this->CheckVersionFile(version_file, version);
  1673. haveResult = true;
  1674. }
  1675. // If no version was requested a versionless package is acceptable.
  1676. if ((haveResult == false) && (this->Version.empty()))
  1677. {
  1678. result = true;
  1679. haveResult = true;
  1680. }
  1681. ConfigFileInfo configFileInfo;
  1682. configFileInfo.filename = config_file;
  1683. configFileInfo.version = version;
  1684. this->ConsideredConfigs.push_back(configFileInfo);
  1685. return result;
  1686. }
  1687. //----------------------------------------------------------------------------
  1688. bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
  1689. std::string& result_version)
  1690. {
  1691. // The version file will be loaded in an isolated scope.
  1692. cmMakefile::ScopePushPop varScope(this->Makefile);
  1693. cmMakefile::PolicyPushPop polScope(this->Makefile);
  1694. static_cast<void>(varScope);
  1695. static_cast<void>(polScope);
  1696. // Clear the output variables.
  1697. this->Makefile->RemoveDefinition("PACKAGE_VERSION");
  1698. this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
  1699. this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
  1700. this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
  1701. // Set the input variables.
  1702. this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str());
  1703. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION",
  1704. this->Version.c_str());
  1705. char buf[64];
  1706. sprintf(buf, "%u", this->VersionMajor);
  1707. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf);
  1708. sprintf(buf, "%u", this->VersionMinor);
  1709. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MINOR", buf);
  1710. sprintf(buf, "%u", this->VersionPatch);
  1711. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_PATCH", buf);
  1712. sprintf(buf, "%u", this->VersionTweak);
  1713. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_TWEAK", buf);
  1714. sprintf(buf, "%u", this->VersionCount);
  1715. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COUNT", buf);
  1716. // Load the version check file. Pass NoPolicyScope because we do
  1717. // our own policy push/pop independent of CMP0011.
  1718. bool suitable = false;
  1719. if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
  1720. {
  1721. // Check the output variables.
  1722. bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
  1723. bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
  1724. if(!okay && !this->VersionExact)
  1725. {
  1726. okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
  1727. }
  1728. // The package is suitable if the version is okay and not
  1729. // explicitly unsuitable.
  1730. suitable = !unsuitable && (okay || this->Version.empty());
  1731. if(suitable)
  1732. {
  1733. // Get the version found.
  1734. this->VersionFound =
  1735. this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
  1736. // Try to parse the version number and store the results that were
  1737. // successfully parsed.
  1738. unsigned int parsed_major;
  1739. unsigned int parsed_minor;
  1740. unsigned int parsed_patch;
  1741. unsigned int parsed_tweak;
  1742. this->VersionFoundCount =
  1743. sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
  1744. &parsed_major, &parsed_minor,
  1745. &parsed_patch, &parsed_tweak);
  1746. switch(this->VersionFoundCount)
  1747. {
  1748. case 4: this->VersionFoundTweak = parsed_tweak; // no break!
  1749. case 3: this->VersionFoundPatch = parsed_patch; // no break!
  1750. case 2: this->VersionFoundMinor = parsed_minor; // no break!
  1751. case 1: this->VersionFoundMajor = parsed_major; // no break!
  1752. default: break;
  1753. }
  1754. }
  1755. }
  1756. result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
  1757. if (result_version.empty())
  1758. {
  1759. result_version = "unknown";
  1760. }
  1761. // Succeed if the version is suitable.
  1762. return suitable;
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. void cmFindPackageCommand::StoreVersionFound()
  1766. {
  1767. // Store the whole version string.
  1768. std::string ver = this->Name;
  1769. ver += "_VERSION";
  1770. if(this->VersionFound.empty())
  1771. {
  1772. this->Makefile->RemoveDefinition(ver.c_str());
  1773. }
  1774. else
  1775. {
  1776. this->Makefile->AddDefinition(ver.c_str(), this->VersionFound.c_str());
  1777. }
  1778. // Store the version components.
  1779. char buf[64];
  1780. sprintf(buf, "%u", this->VersionFoundMajor);
  1781. this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
  1782. sprintf(buf, "%u", this->VersionFoundMinor);
  1783. this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
  1784. sprintf(buf, "%u", this->VersionFoundPatch);
  1785. this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
  1786. sprintf(buf, "%u", this->VersionFoundTweak);
  1787. this->Makefile->AddDefinition((ver+"_TWEAK").c_str(), buf);
  1788. sprintf(buf, "%u", this->VersionFoundCount);
  1789. this->Makefile->AddDefinition((ver+"_COUNT").c_str(), buf);
  1790. }
  1791. //----------------------------------------------------------------------------
  1792. #include <cmsys/Glob.hxx>
  1793. #include <cmsys/String.h>
  1794. #include <cmsys/auto_ptr.hxx>
  1795. class cmFileList;
  1796. class cmFileListGeneratorBase
  1797. {
  1798. public:
  1799. virtual ~cmFileListGeneratorBase() {}
  1800. protected:
  1801. bool Consider(std::string const& fullPath, cmFileList& listing);
  1802. private:
  1803. bool Search(cmFileList&);
  1804. virtual bool Search(std::string const& parent, cmFileList&) = 0;
  1805. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const = 0;
  1806. friend class cmFileList;
  1807. cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next);
  1808. cmsys::auto_ptr<cmFileListGeneratorBase> Next;
  1809. };
  1810. class cmFileList
  1811. {
  1812. public:
  1813. cmFileList(): First(), Last(0) {}
  1814. virtual ~cmFileList() {}
  1815. cmFileList& operator/(cmFileListGeneratorBase const& rhs)
  1816. {
  1817. if(this->Last)
  1818. {
  1819. this->Last = this->Last->SetNext(rhs);
  1820. }
  1821. else
  1822. {
  1823. this->First = rhs.Clone();
  1824. this->Last = this->First.get();
  1825. }
  1826. return *this;
  1827. }
  1828. bool Search()
  1829. {
  1830. if(this->First.get())
  1831. {
  1832. return this->First->Search(*this);
  1833. }
  1834. return false;
  1835. }
  1836. private:
  1837. virtual bool Visit(std::string const& fullPath) = 0;
  1838. friend class cmFileListGeneratorBase;
  1839. cmsys::auto_ptr<cmFileListGeneratorBase> First;
  1840. cmFileListGeneratorBase* Last;
  1841. };
  1842. class cmFindPackageFileList: public cmFileList
  1843. {
  1844. public:
  1845. cmFindPackageFileList(cmFindPackageCommand* fpc,
  1846. bool use_suffixes = true):
  1847. cmFileList(), FPC(fpc), UseSuffixes(use_suffixes) {}
  1848. private:
  1849. bool Visit(std::string const& fullPath)
  1850. {
  1851. if(this->UseSuffixes)
  1852. {
  1853. return this->FPC->SearchDirectory(fullPath);
  1854. }
  1855. else
  1856. {
  1857. return this->FPC->CheckDirectory(fullPath);
  1858. }
  1859. }
  1860. cmFindPackageCommand* FPC;
  1861. bool UseSuffixes;
  1862. };
  1863. bool cmFileListGeneratorBase::Search(cmFileList& listing)
  1864. {
  1865. return this->Search("", listing);
  1866. }
  1867. cmFileListGeneratorBase*
  1868. cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
  1869. {
  1870. this->Next = next.Clone();
  1871. return this->Next.get();
  1872. }
  1873. bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
  1874. cmFileList& listing)
  1875. {
  1876. if(this->Next.get())
  1877. {
  1878. return this->Next->Search(fullPath + "/", listing);
  1879. }
  1880. else
  1881. {
  1882. return listing.Visit(fullPath + "/");
  1883. }
  1884. }
  1885. class cmFileListGeneratorFixed: public cmFileListGeneratorBase
  1886. {
  1887. public:
  1888. cmFileListGeneratorFixed(std::string const& str):
  1889. cmFileListGeneratorBase(), String(str) {}
  1890. cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r):
  1891. cmFileListGeneratorBase(), String(r.String) {}
  1892. private:
  1893. std::string String;
  1894. virtual bool Search(std::string const& parent, cmFileList& lister)
  1895. {
  1896. std::string fullPath = parent + this->String;
  1897. return this->Consider(fullPath, lister);
  1898. }
  1899. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1900. {
  1901. cmsys::auto_ptr<cmFileListGeneratorBase>
  1902. g(new cmFileListGeneratorFixed(*this));
  1903. return g;
  1904. }
  1905. };
  1906. class cmFileListGeneratorEnumerate: public cmFileListGeneratorBase
  1907. {
  1908. public:
  1909. cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
  1910. cmFileListGeneratorBase(), Vector(v) {}
  1911. cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
  1912. cmFileListGeneratorBase(), Vector(r.Vector) {}
  1913. private:
  1914. std::vector<std::string> const& Vector;
  1915. virtual bool Search(std::string const& parent, cmFileList& lister)
  1916. {
  1917. for(std::vector<std::string>::const_iterator i = this->Vector.begin();
  1918. i != this->Vector.end(); ++i)
  1919. {
  1920. if(this->Consider(parent + *i, lister))
  1921. {
  1922. return true;
  1923. }
  1924. }
  1925. return false;
  1926. }
  1927. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1928. {
  1929. cmsys::auto_ptr<cmFileListGeneratorBase>
  1930. g(new cmFileListGeneratorEnumerate(*this));
  1931. return g;
  1932. }
  1933. };
  1934. class cmFileListGeneratorProject: public cmFileListGeneratorBase
  1935. {
  1936. public:
  1937. cmFileListGeneratorProject(std::vector<std::string> const& names):
  1938. cmFileListGeneratorBase(), Names(names) {}
  1939. cmFileListGeneratorProject(cmFileListGeneratorProject const& r):
  1940. cmFileListGeneratorBase(), Names(r.Names) {}
  1941. private:
  1942. std::vector<std::string> const& Names;
  1943. virtual bool Search(std::string const& parent, cmFileList& lister)
  1944. {
  1945. // Construct a list of matches.
  1946. std::vector<std::string> matches;
  1947. cmsys::Directory d;
  1948. d.Load(parent.c_str());
  1949. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  1950. {
  1951. const char* fname = d.GetFile(i);
  1952. if(strcmp(fname, ".") == 0 ||
  1953. strcmp(fname, "..") == 0)
  1954. {
  1955. continue;
  1956. }
  1957. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  1958. ni != this->Names.end(); ++ni)
  1959. {
  1960. if(cmsysString_strncasecmp(fname, ni->c_str(),
  1961. ni->length()) == 0)
  1962. {
  1963. matches.push_back(fname);
  1964. }
  1965. }
  1966. }
  1967. for(std::vector<std::string>::const_iterator i = matches.begin();
  1968. i != matches.end(); ++i)
  1969. {
  1970. if(this->Consider(parent + *i, lister))
  1971. {
  1972. return true;
  1973. }
  1974. }
  1975. return false;
  1976. }
  1977. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  1978. {
  1979. cmsys::auto_ptr<cmFileListGeneratorBase>
  1980. g(new cmFileListGeneratorProject(*this));
  1981. return g;
  1982. }
  1983. };
  1984. class cmFileListGeneratorMacProject: public cmFileListGeneratorBase
  1985. {
  1986. public:
  1987. cmFileListGeneratorMacProject(std::vector<std::string> const& names,
  1988. const char* ext):
  1989. cmFileListGeneratorBase(), Names(names), Extension(ext) {}
  1990. cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r):
  1991. cmFileListGeneratorBase(), Names(r.Names), Extension(r.Extension) {}
  1992. private:
  1993. std::vector<std::string> const& Names;
  1994. std::string Extension;
  1995. virtual bool Search(std::string const& parent, cmFileList& lister)
  1996. {
  1997. // Construct a list of matches.
  1998. std::vector<std::string> matches;
  1999. cmsys::Directory d;
  2000. d.Load(parent.c_str());
  2001. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  2002. {
  2003. const char* fname = d.GetFile(i);
  2004. if(strcmp(fname, ".") == 0 ||
  2005. strcmp(fname, "..") == 0)
  2006. {
  2007. continue;
  2008. }
  2009. for(std::vector<std::string>::const_iterator ni = this->Names.begin();
  2010. ni != this->Names.end(); ++ni)
  2011. {
  2012. std::string name = *ni;
  2013. name += this->Extension;
  2014. if(cmsysString_strcasecmp(fname, name.c_str()) == 0)
  2015. {
  2016. matches.push_back(fname);
  2017. }
  2018. }
  2019. }
  2020. for(std::vector<std::string>::const_iterator i = matches.begin();
  2021. i != matches.end(); ++i)
  2022. {
  2023. if(this->Consider(parent + *i, lister))
  2024. {
  2025. return true;
  2026. }
  2027. }
  2028. return false;
  2029. }
  2030. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  2031. {
  2032. cmsys::auto_ptr<cmFileListGeneratorBase>
  2033. g(new cmFileListGeneratorMacProject(*this));
  2034. return g;
  2035. }
  2036. };
  2037. class cmFileListGeneratorCaseInsensitive: public cmFileListGeneratorBase
  2038. {
  2039. public:
  2040. cmFileListGeneratorCaseInsensitive(std::string const& str):
  2041. cmFileListGeneratorBase(), String(str) {}
  2042. cmFileListGeneratorCaseInsensitive(
  2043. cmFileListGeneratorCaseInsensitive const& r):
  2044. cmFileListGeneratorBase(), String(r.String) {}
  2045. private:
  2046. std::string String;
  2047. virtual bool Search(std::string const& parent, cmFileList& lister)
  2048. {
  2049. // Look for matching files.
  2050. std::vector<std::string> matches;
  2051. cmsys::Directory d;
  2052. d.Load(parent.c_str());
  2053. for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
  2054. {
  2055. const char* fname = d.GetFile(i);
  2056. if(strcmp(fname, ".") == 0 ||
  2057. strcmp(fname, "..") == 0)
  2058. {
  2059. continue;
  2060. }
  2061. if(cmsysString_strcasecmp(fname, this->String.c_str()) == 0)
  2062. {
  2063. if(this->Consider(parent + fname, lister))
  2064. {
  2065. return true;
  2066. }
  2067. }
  2068. }
  2069. return false;
  2070. }
  2071. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  2072. {
  2073. cmsys::auto_ptr<cmFileListGeneratorBase>
  2074. g(new cmFileListGeneratorCaseInsensitive(*this));
  2075. return g;
  2076. }
  2077. };
  2078. class cmFileListGeneratorGlob: public cmFileListGeneratorBase
  2079. {
  2080. public:
  2081. cmFileListGeneratorGlob(std::string const& str):
  2082. cmFileListGeneratorBase(), Pattern(str) {}
  2083. cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r):
  2084. cmFileListGeneratorBase(), Pattern(r.Pattern) {}
  2085. private:
  2086. std::string Pattern;
  2087. virtual bool Search(std::string const& parent, cmFileList& lister)
  2088. {
  2089. // Glob the set of matching files.
  2090. std::string expr = parent;
  2091. expr += this->Pattern;
  2092. cmsys::Glob g;
  2093. if(!g.FindFiles(expr))
  2094. {
  2095. return false;
  2096. }
  2097. std::vector<std::string> const& files = g.GetFiles();
  2098. // Look for directories among the matches.
  2099. for(std::vector<std::string>::const_iterator fi = files.begin();
  2100. fi != files.end(); ++fi)
  2101. {
  2102. if(cmSystemTools::FileIsDirectory(fi->c_str()))
  2103. {
  2104. if(this->Consider(*fi, lister))
  2105. {
  2106. return true;
  2107. }
  2108. }
  2109. }
  2110. return false;
  2111. }
  2112. virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
  2113. {
  2114. cmsys::auto_ptr<cmFileListGeneratorBase>
  2115. g(new cmFileListGeneratorGlob(*this));
  2116. return g;
  2117. }
  2118. };
  2119. //----------------------------------------------------------------------------
  2120. bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
  2121. {
  2122. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  2123. if(this->DebugMode)
  2124. {
  2125. fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
  2126. }
  2127. // Skip this if the prefix does not exist.
  2128. if(!cmSystemTools::FileIsDirectory(prefix_in.c_str()))
  2129. {
  2130. return false;
  2131. }
  2132. // PREFIX/ (useful on windows or in build trees)
  2133. if(this->SearchDirectory(prefix_in))
  2134. {
  2135. return true;
  2136. }
  2137. // Strip the trailing slash because the path generator is about to
  2138. // add one.
  2139. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  2140. // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
  2141. {
  2142. cmFindPackageFileList lister(this);
  2143. lister
  2144. / cmFileListGeneratorFixed(prefix)
  2145. / cmFileListGeneratorCaseInsensitive("cmake");
  2146. if(lister.Search())
  2147. {
  2148. return true;
  2149. }
  2150. }
  2151. // PREFIX/(Foo|foo|FOO).*/
  2152. {
  2153. cmFindPackageFileList lister(this);
  2154. lister
  2155. / cmFileListGeneratorFixed(prefix)
  2156. / cmFileListGeneratorProject(this->Names);
  2157. if(lister.Search())
  2158. {
  2159. return true;
  2160. }
  2161. }
  2162. // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
  2163. {
  2164. cmFindPackageFileList lister(this);
  2165. lister
  2166. / cmFileListGeneratorFixed(prefix)
  2167. / cmFileListGeneratorProject(this->Names)
  2168. / cmFileListGeneratorCaseInsensitive("cmake");
  2169. if(lister.Search())
  2170. {
  2171. return true;
  2172. }
  2173. }
  2174. // Construct list of common install locations (lib and share).
  2175. std::vector<std::string> common;
  2176. if(!this->LibraryArchitecture.empty())
  2177. {
  2178. common.push_back("lib/"+this->LibraryArchitecture);
  2179. }
  2180. if(this->UseLib64Paths)
  2181. {
  2182. common.push_back("lib64");
  2183. }
  2184. common.push_back("lib");
  2185. common.push_back("share");
  2186. // PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
  2187. {
  2188. cmFindPackageFileList lister(this);
  2189. lister
  2190. / cmFileListGeneratorFixed(prefix)
  2191. / cmFileListGeneratorEnumerate(common)
  2192. / cmFileListGeneratorFixed("cmake")
  2193. / cmFileListGeneratorProject(this->Names);
  2194. if(lister.Search())
  2195. {
  2196. return true;
  2197. }
  2198. }
  2199. // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
  2200. {
  2201. cmFindPackageFileList lister(this);
  2202. lister
  2203. / cmFileListGeneratorFixed(prefix)
  2204. / cmFileListGeneratorEnumerate(common)
  2205. / cmFileListGeneratorProject(this->Names);
  2206. if(lister.Search())
  2207. {
  2208. return true;
  2209. }
  2210. }
  2211. // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
  2212. {
  2213. cmFindPackageFileList lister(this);
  2214. lister
  2215. / cmFileListGeneratorFixed(prefix)
  2216. / cmFileListGeneratorEnumerate(common)
  2217. / cmFileListGeneratorProject(this->Names)
  2218. / cmFileListGeneratorCaseInsensitive("cmake");
  2219. if(lister.Search())
  2220. {
  2221. return true;
  2222. }
  2223. }
  2224. return false;
  2225. }
  2226. //----------------------------------------------------------------------------
  2227. bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
  2228. {
  2229. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  2230. if(this->DebugMode)
  2231. {
  2232. fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
  2233. }
  2234. // Strip the trailing slash because the path generator is about to
  2235. // add one.
  2236. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  2237. // <prefix>/Foo.framework/Resources/
  2238. {
  2239. cmFindPackageFileList lister(this);
  2240. lister
  2241. / cmFileListGeneratorFixed(prefix)
  2242. / cmFileListGeneratorMacProject(this->Names, ".framework")
  2243. / cmFileListGeneratorFixed("Resources");
  2244. if(lister.Search())
  2245. {
  2246. return true;
  2247. }
  2248. }
  2249. // <prefix>/Foo.framework/Resources/CMake/
  2250. {
  2251. cmFindPackageFileList lister(this);
  2252. lister
  2253. / cmFileListGeneratorFixed(prefix)
  2254. / cmFileListGeneratorMacProject(this->Names, ".framework")
  2255. / cmFileListGeneratorFixed("Resources")
  2256. / cmFileListGeneratorCaseInsensitive("cmake");
  2257. if(lister.Search())
  2258. {
  2259. return true;
  2260. }
  2261. }
  2262. // <prefix>/Foo.framework/Versions/*/Resources/
  2263. {
  2264. cmFindPackageFileList lister(this);
  2265. lister
  2266. / cmFileListGeneratorFixed(prefix)
  2267. / cmFileListGeneratorMacProject(this->Names, ".framework")
  2268. / cmFileListGeneratorFixed("Versions")
  2269. / cmFileListGeneratorGlob("*/Resources");
  2270. if(lister.Search())
  2271. {
  2272. return true;
  2273. }
  2274. }
  2275. // <prefix>/Foo.framework/Versions/*/Resources/CMake/
  2276. {
  2277. cmFindPackageFileList lister(this);
  2278. lister
  2279. / cmFileListGeneratorFixed(prefix)
  2280. / cmFileListGeneratorMacProject(this->Names, ".framework")
  2281. / cmFileListGeneratorFixed("Versions")
  2282. / cmFileListGeneratorGlob("*/Resources")
  2283. / cmFileListGeneratorCaseInsensitive("cmake");
  2284. if(lister.Search())
  2285. {
  2286. return true;
  2287. }
  2288. }
  2289. return false;
  2290. }
  2291. //----------------------------------------------------------------------------
  2292. bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
  2293. {
  2294. assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
  2295. if(this->DebugMode)
  2296. {
  2297. fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
  2298. }
  2299. // Strip the trailing slash because the path generator is about to
  2300. // add one.
  2301. std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
  2302. // <prefix>/Foo.app/Contents/Resources
  2303. {
  2304. cmFindPackageFileList lister(this);
  2305. lister
  2306. / cmFileListGeneratorFixed(prefix)
  2307. / cmFileListGeneratorMacProject(this->Names, ".app")
  2308. / cmFileListGeneratorFixed("Contents/Resources");
  2309. if(lister.Search())
  2310. {
  2311. return true;
  2312. }
  2313. }
  2314. // <prefix>/Foo.app/Contents/Resources/CMake
  2315. {
  2316. cmFindPackageFileList lister(this);
  2317. lister
  2318. / cmFileListGeneratorFixed(prefix)
  2319. / cmFileListGeneratorMacProject(this->Names, ".app")
  2320. / cmFileListGeneratorFixed("Contents/Resources")
  2321. / cmFileListGeneratorCaseInsensitive("cmake");
  2322. if(lister.Search())
  2323. {
  2324. return true;
  2325. }
  2326. }
  2327. return false;
  2328. }
  2329. // TODO: Debug cmsys::Glob double slash problem.