cmFindPackageCommand.cxx 80 KB

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