cmFindPackageCommand.cxx 82 KB

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