cmFindPackageCommand.cxx 77 KB

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