cmFindPackageCommand.cxx 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmFindPackageCommand.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <cstdio>
  7. #include <deque>
  8. #include <functional>
  9. #include <iterator>
  10. #include <sstream>
  11. #include <utility>
  12. #include <cm/memory>
  13. #include <cm/optional>
  14. #include <cmext/string_view>
  15. #include "cmsys/Directory.hxx"
  16. #include "cmsys/FStream.hxx"
  17. #include "cmsys/Glob.hxx"
  18. #include "cmsys/RegularExpression.hxx"
  19. #include "cmsys/String.h"
  20. #include "cmAlgorithms.h"
  21. #include "cmDependencyProvider.h"
  22. #include "cmListFileCache.h"
  23. #include "cmMakefile.h"
  24. #include "cmMessageType.h"
  25. #include "cmPolicies.h"
  26. #include "cmRange.h"
  27. #include "cmSearchPath.h"
  28. #include "cmState.h"
  29. #include "cmStateTypes.h"
  30. #include "cmStringAlgorithms.h"
  31. #include "cmSystemTools.h"
  32. #include "cmValue.h"
  33. #include "cmVersion.h"
  34. #include "cmWindowsRegistry.h"
  35. #if defined(__HAIKU__)
  36. # include <FindDirectory.h>
  37. # include <StorageDefs.h>
  38. #endif
  39. #if defined(_WIN32) && !defined(__CYGWIN__)
  40. # include <windows.h>
  41. // http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
  42. # if !defined(KEY_WOW64_32KEY)
  43. # define KEY_WOW64_32KEY 0x0200
  44. # endif
  45. # if !defined(KEY_WOW64_64KEY)
  46. # define KEY_WOW64_64KEY 0x0100
  47. # endif
  48. #endif
  49. class cmExecutionStatus;
  50. namespace {
  51. template <template <typename> class Op>
  52. struct StrverscmpOp
  53. {
  54. bool operator()(const std::string& lhs, const std::string& rhs) const
  55. {
  56. return Op<int>()(cmSystemTools::strverscmp(lhs, rhs), 0);
  57. }
  58. };
  59. std::size_t collectPathsForDebug(std::string& buffer,
  60. cmSearchPath const& searchPath,
  61. std::size_t const startIndex = 0)
  62. {
  63. const auto& paths = searchPath.GetPaths();
  64. if (paths.empty()) {
  65. buffer += " none\n";
  66. return 0;
  67. }
  68. for (auto i = startIndex; i < paths.size(); i++) {
  69. buffer += " " + paths[i].Path + "\n";
  70. }
  71. return paths.size();
  72. }
  73. #if !(defined(_WIN32) && !defined(__CYGWIN__))
  74. class cmFindPackageCommandHoldFile
  75. {
  76. const char* File;
  77. public:
  78. cmFindPackageCommandHoldFile(const char* const f)
  79. : File(f)
  80. {
  81. }
  82. ~cmFindPackageCommandHoldFile()
  83. {
  84. if (this->File) {
  85. cmSystemTools::RemoveFile(this->File);
  86. }
  87. }
  88. cmFindPackageCommandHoldFile(const cmFindPackageCommandHoldFile&) = delete;
  89. cmFindPackageCommandHoldFile& operator=(
  90. const cmFindPackageCommandHoldFile&) = delete;
  91. void Release() { this->File = nullptr; }
  92. };
  93. #endif
  94. bool isDirentryToIgnore(const char* const fname)
  95. {
  96. assert(fname != nullptr);
  97. assert(fname[0] != 0);
  98. return fname[0] == '.' &&
  99. (fname[1] == 0 || (fname[1] == '.' && fname[2] == 0));
  100. }
  101. class cmAppendPathSegmentGenerator
  102. {
  103. public:
  104. cmAppendPathSegmentGenerator(cm::string_view dirName)
  105. : DirName{ dirName }
  106. {
  107. }
  108. std::string GetNextCandidate(const std::string& parent)
  109. {
  110. if (this->NeedReset) {
  111. return {};
  112. }
  113. this->NeedReset = true;
  114. return cmStrCat(parent, '/', this->DirName);
  115. }
  116. void Reset() { this->NeedReset = false; }
  117. private:
  118. const cm::string_view DirName;
  119. bool NeedReset = false;
  120. };
  121. class cmEnumPathSegmentsGenerator
  122. {
  123. public:
  124. cmEnumPathSegmentsGenerator(const std::vector<cm::string_view>& init)
  125. : Names{ init }
  126. , Current{ this->Names.get().cbegin() }
  127. {
  128. }
  129. std::string GetNextCandidate(const std::string& parent)
  130. {
  131. if (this->Current != this->Names.get().cend()) {
  132. return cmStrCat(parent, '/', *this->Current++);
  133. }
  134. return {};
  135. }
  136. void Reset() { this->Current = this->Names.get().cbegin(); }
  137. private:
  138. std::reference_wrapper<const std::vector<cm::string_view>> Names;
  139. std::vector<cm::string_view>::const_iterator Current;
  140. };
  141. class cmCaseInsensitiveDirectoryListGenerator
  142. {
  143. public:
  144. cmCaseInsensitiveDirectoryListGenerator(cm::string_view name)
  145. : DirectoryLister{}
  146. , DirName{ name }
  147. {
  148. }
  149. std::string GetNextCandidate(const std::string& parent)
  150. {
  151. if (!this->Loaded) {
  152. this->CurrentIdx = 0ul;
  153. this->Loaded = true;
  154. if (!this->DirectoryLister.Load(parent)) {
  155. return {};
  156. }
  157. }
  158. while (this->CurrentIdx < this->DirectoryLister.GetNumberOfFiles()) {
  159. const char* const fname =
  160. this->DirectoryLister.GetFile(this->CurrentIdx++);
  161. if (isDirentryToIgnore(fname)) {
  162. continue;
  163. }
  164. if (cmsysString_strcasecmp(fname, this->DirName.data()) == 0) {
  165. auto candidate = cmStrCat(parent, '/', fname);
  166. if (cmSystemTools::FileIsDirectory(candidate)) {
  167. return candidate;
  168. }
  169. }
  170. }
  171. return {};
  172. }
  173. void Reset() { this->Loaded = false; }
  174. private:
  175. cmsys::Directory DirectoryLister;
  176. const cm::string_view DirName;
  177. unsigned long CurrentIdx = 0ul;
  178. bool Loaded = false;
  179. };
  180. class cmDirectoryListGenerator
  181. {
  182. public:
  183. cmDirectoryListGenerator(std::vector<std::string> const& names)
  184. : Names{ names }
  185. , Matches{}
  186. , Current{ this->Matches.cbegin() }
  187. {
  188. }
  189. virtual ~cmDirectoryListGenerator() = default;
  190. std::string GetNextCandidate(const std::string& parent)
  191. {
  192. // Construct a list of matches if not yet
  193. if (this->Matches.empty()) {
  194. cmsys::Directory directoryLister;
  195. // ALERT `Directory::Load()` keeps only names
  196. // internally and LOST entry type from `dirent`.
  197. // So, `Directory::FileIsDirectory` gonna use
  198. // `SystemTools::FileIsDirectory()` and waste a syscall.
  199. // TODO Need to enhance the `Directory` class.
  200. directoryLister.Load(parent);
  201. // ATTENTION Is it guaranteed that first two entries are
  202. // `.` and `..`?
  203. // TODO If so, just start with index 2 and drop the
  204. // `isDirentryToIgnore(i)` condition to check.
  205. for (auto i = 0ul; i < directoryLister.GetNumberOfFiles(); ++i) {
  206. const char* const fname = directoryLister.GetFile(i);
  207. if (isDirentryToIgnore(fname)) {
  208. continue;
  209. }
  210. for (const auto& n : this->Names.get()) {
  211. // NOTE Customization point for `cmMacProjectDirectoryListGenerator`
  212. const auto name = this->TransformNameBeforeCmp(n);
  213. // Skip entries that don't match and non-directories.
  214. // ATTENTION BTW, original code also didn't check if it's a symlink
  215. // to a directory!
  216. const auto equal =
  217. (cmsysString_strncasecmp(fname, name.c_str(), name.length()) == 0);
  218. if (equal && directoryLister.FileIsDirectory(i)) {
  219. this->Matches.emplace_back(fname);
  220. }
  221. }
  222. }
  223. // NOTE Customization point for `cmProjectDirectoryListGenerator`
  224. this->OnMatchesLoaded();
  225. this->Current = this->Matches.cbegin();
  226. }
  227. if (this->Current != this->Matches.cend()) {
  228. auto candidate = cmStrCat(parent, '/', *this->Current++);
  229. return candidate;
  230. }
  231. return {};
  232. }
  233. void Reset()
  234. {
  235. this->Matches.clear();
  236. this->Current = this->Matches.cbegin();
  237. }
  238. protected:
  239. virtual void OnMatchesLoaded() {}
  240. virtual std::string TransformNameBeforeCmp(std::string same) { return same; }
  241. std::reference_wrapper<const std::vector<std::string>> Names;
  242. std::vector<std::string> Matches;
  243. std::vector<std::string>::const_iterator Current;
  244. };
  245. class cmProjectDirectoryListGenerator : public cmDirectoryListGenerator
  246. {
  247. public:
  248. cmProjectDirectoryListGenerator(std::vector<std::string> const& names,
  249. cmFindPackageCommand::SortOrderType so,
  250. cmFindPackageCommand::SortDirectionType sd)
  251. : cmDirectoryListGenerator{ names }
  252. , SortOrder{ so }
  253. , SortDirection{ sd }
  254. {
  255. }
  256. protected:
  257. void OnMatchesLoaded() override
  258. {
  259. // check if there is a specific sorting order to perform
  260. if (this->SortOrder != cmFindPackageCommand::None) {
  261. cmFindPackageCommand::Sort(this->Matches.begin(), this->Matches.end(),
  262. this->SortOrder, this->SortDirection);
  263. }
  264. }
  265. private:
  266. // sort parameters
  267. const cmFindPackageCommand::SortOrderType SortOrder;
  268. const cmFindPackageCommand::SortDirectionType SortDirection;
  269. };
  270. class cmMacProjectDirectoryListGenerator : public cmDirectoryListGenerator
  271. {
  272. public:
  273. cmMacProjectDirectoryListGenerator(const std::vector<std::string>& names,
  274. cm::string_view ext)
  275. : cmDirectoryListGenerator{ names }
  276. , Extension{ ext }
  277. {
  278. }
  279. protected:
  280. std::string TransformNameBeforeCmp(std::string name) override
  281. {
  282. return cmStrCat(name, this->Extension);
  283. }
  284. private:
  285. const cm::string_view Extension;
  286. };
  287. class cmFileListGeneratorGlob
  288. {
  289. public:
  290. cmFileListGeneratorGlob(cm::string_view pattern)
  291. : Pattern(pattern)
  292. , Files{}
  293. , Current{}
  294. {
  295. }
  296. std::string GetNextCandidate(const std::string& parent)
  297. {
  298. if (this->Files.empty()) {
  299. // Glob the set of matching files.
  300. std::string expr = cmStrCat(parent, this->Pattern);
  301. cmsys::Glob g;
  302. if (!g.FindFiles(expr)) {
  303. return {};
  304. }
  305. this->Files = g.GetFiles();
  306. this->Current = this->Files.cbegin();
  307. }
  308. // Skip non-directories
  309. for (; this->Current != this->Files.cend() &&
  310. !cmSystemTools::FileIsDirectory(*this->Current);
  311. ++this->Current) {
  312. }
  313. return (this->Current != this->Files.cend()) ? *this->Current++
  314. : std::string{};
  315. }
  316. void Reset()
  317. {
  318. this->Files.clear();
  319. this->Current = this->Files.cbegin();
  320. }
  321. private:
  322. cm::string_view Pattern;
  323. std::vector<std::string> Files;
  324. std::vector<std::string>::const_iterator Current;
  325. };
  326. #if defined(__LCC__)
  327. # define CM_LCC_DIAG_SUPPRESS_1222
  328. # pragma diag_suppress 1222 // invalid error number (3288, but works anyway)
  329. # define CM_LCC_DIAG_SUPPRESS_3288
  330. # pragma diag_suppress 3288 // parameter was declared but never referenced
  331. # define CM_LCC_DIAG_SUPPRESS_3301
  332. # pragma diag_suppress 3301 // parameter was declared but never referenced
  333. # define CM_LCC_DIAG_SUPPRESS_3308
  334. # pragma diag_suppress 3308 // parameter was declared but never referenced
  335. #endif
  336. void ResetGenerator()
  337. {
  338. }
  339. template <typename Generator>
  340. void ResetGenerator(Generator&& generator)
  341. {
  342. std::forward<Generator&&>(generator).Reset();
  343. }
  344. template <typename Generator, typename... Generators>
  345. void ResetGenerator(Generator&& generator, Generators&&... generators)
  346. {
  347. ResetGenerator(std::forward<Generator&&>(generator));
  348. ResetGenerator(std::forward<Generators&&>(generators)...);
  349. }
  350. template <typename CallbackFn>
  351. bool TryGeneratedPaths(CallbackFn&& filesCollector,
  352. const std::string& fullPath)
  353. {
  354. assert(!fullPath.empty() && fullPath.back() != '/');
  355. return std::forward<CallbackFn&&>(filesCollector)(fullPath + '/');
  356. }
  357. template <typename CallbackFn, typename Generator, typename... Rest>
  358. bool TryGeneratedPaths(CallbackFn&& filesCollector,
  359. const std::string& startPath, Generator&& gen,
  360. Rest&&... tail)
  361. {
  362. ResetGenerator(std::forward<Generator&&>(gen));
  363. for (auto path = gen.GetNextCandidate(startPath); !path.empty();
  364. path = gen.GetNextCandidate(startPath)) {
  365. ResetGenerator(std::forward<Rest&&>(tail)...);
  366. if (TryGeneratedPaths(std::forward<CallbackFn&&>(filesCollector), path,
  367. std::forward<Rest&&>(tail)...)) {
  368. return true;
  369. }
  370. }
  371. return false;
  372. }
  373. #ifdef CM_LCC_DIAG_SUPPRESS_3308
  374. # undef CM_LCC_DIAG_SUPPRESS_3308
  375. # pragma diag_default 3308
  376. #endif
  377. #ifdef CM_LCC_DIAG_SUPPRESS_3301
  378. # undef CM_LCC_DIAG_SUPPRESS_3301
  379. # pragma diag_default 3301
  380. #endif
  381. #ifdef CM_LCC_DIAG_SUPPRESS_3288
  382. # undef CM_LCC_DIAG_SUPPRESS_3288
  383. # pragma diag_default 3288
  384. #endif
  385. #ifdef CM_LCC_DIAG_SUPPRESS_1222
  386. # undef CM_LCC_DIAG_SUPPRESS_1222
  387. # pragma diag_default 1222
  388. #endif
  389. // Parse the version number and store the results that were
  390. // successfully parsed.
  391. int parseVersion(const std::string& version, unsigned int& major,
  392. unsigned int& minor, unsigned int& patch, unsigned int& tweak)
  393. {
  394. return std::sscanf(version.c_str(), "%u.%u.%u.%u", &major, &minor, &patch,
  395. &tweak);
  396. }
  397. } // anonymous namespace
  398. cmFindPackageCommand::PathLabel
  399. cmFindPackageCommand::PathLabel::PackageRedirect("PACKAGE_REDIRECT");
  400. cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::UserRegistry(
  401. "PACKAGE_REGISTRY");
  402. cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::Builds(
  403. "BUILDS");
  404. cmFindPackageCommand::PathLabel
  405. cmFindPackageCommand::PathLabel::SystemRegistry("SYSTEM_PACKAGE_REGISTRY");
  406. const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_INCLUDED(
  407. "INCLUDE");
  408. const cm::string_view cmFindPackageCommand::VERSION_ENDPOINT_EXCLUDED(
  409. "EXCLUDE");
  410. void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
  411. std::vector<std::string>::iterator end,
  412. SortOrderType const order,
  413. SortDirectionType const dir)
  414. {
  415. if (order == Name_order) {
  416. if (dir == Dec) {
  417. std::sort(begin, end, std::greater<std::string>());
  418. } else {
  419. std::sort(begin, end);
  420. }
  421. } else if (order == Natural) {
  422. // natural order uses letters and numbers (contiguous numbers digit are
  423. // compared such that e.g. 000 00 < 01 < 010 < 09 < 0 < 1 < 9 < 10
  424. if (dir == Dec) {
  425. std::sort(begin, end, StrverscmpOp<std::greater>());
  426. } else {
  427. std::sort(begin, end, StrverscmpOp<std::less>());
  428. }
  429. }
  430. // else do not sort
  431. }
  432. cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status)
  433. : cmFindCommon(status)
  434. , VersionRangeMin(VERSION_ENDPOINT_INCLUDED)
  435. , VersionRangeMax(VERSION_ENDPOINT_INCLUDED)
  436. {
  437. this->CMakePathName = "PACKAGE";
  438. this->DebugMode = false;
  439. this->AppendSearchPathGroups();
  440. this->DeprecatedFindModules["Dart"] = cmPolicies::CMP0145;
  441. this->DeprecatedFindModules["Qt"] = cmPolicies::CMP0084;
  442. }
  443. void cmFindPackageCommand::AppendSearchPathGroups()
  444. {
  445. // Update the All group with new paths. Note that package redirection must
  446. // take precedence over everything else, so it has to be first in the array.
  447. std::vector<cmFindCommon::PathLabel>* const labels =
  448. &this->PathGroupLabelMap[PathGroup::All];
  449. labels->insert(labels->begin(), PathLabel::PackageRedirect);
  450. labels->insert(
  451. std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
  452. PathLabel::UserRegistry);
  453. labels->insert(
  454. std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
  455. PathLabel::Builds);
  456. labels->insert(std::find(labels->begin(), labels->end(), PathLabel::Guess),
  457. PathLabel::SystemRegistry);
  458. // Create the new path objects
  459. this->LabeledPaths.insert(
  460. std::make_pair(PathLabel::PackageRedirect, cmSearchPath(this)));
  461. this->LabeledPaths.insert(
  462. std::make_pair(PathLabel::UserRegistry, cmSearchPath(this)));
  463. this->LabeledPaths.insert(
  464. std::make_pair(PathLabel::Builds, cmSearchPath(this)));
  465. this->LabeledPaths.insert(
  466. std::make_pair(PathLabel::SystemRegistry, cmSearchPath(this)));
  467. }
  468. bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
  469. {
  470. if (args.empty()) {
  471. this->SetError("called with incorrect number of arguments");
  472. return false;
  473. }
  474. // Lookup required version of CMake.
  475. if (cmValue const rv =
  476. this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) {
  477. unsigned int v[3] = { 0, 0, 0 };
  478. std::sscanf(rv->c_str(), "%u.%u.%u", &v[0], &v[1], &v[2]);
  479. this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0], v[1], v[2]);
  480. }
  481. // Lookup target architecture, if any.
  482. if (cmValue const arch =
  483. this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) {
  484. this->LibraryArchitecture = *arch;
  485. }
  486. // Lookup whether lib32 paths should be used.
  487. if (this->Makefile->PlatformIs32Bit() &&
  488. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  489. "FIND_LIBRARY_USE_LIB32_PATHS")) {
  490. this->UseLib32Paths = true;
  491. }
  492. // Lookup whether lib64 paths should be used.
  493. if (this->Makefile->PlatformIs64Bit() &&
  494. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  495. "FIND_LIBRARY_USE_LIB64_PATHS")) {
  496. this->UseLib64Paths = true;
  497. }
  498. // Lookup whether libx32 paths should be used.
  499. if (this->Makefile->PlatformIsx32() &&
  500. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  501. "FIND_LIBRARY_USE_LIBX32_PATHS")) {
  502. this->UseLibx32Paths = true;
  503. }
  504. // Check if User Package Registry should be disabled
  505. // The `CMAKE_FIND_USE_PACKAGE_REGISTRY` has
  506. // priority over the deprecated CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
  507. if (cmValue const def =
  508. this->Makefile->GetDefinition("CMAKE_FIND_USE_PACKAGE_REGISTRY")) {
  509. this->NoUserRegistry = !cmIsOn(*def);
  510. } else if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY")) {
  511. this->NoUserRegistry = true;
  512. }
  513. // Check if System Package Registry should be disabled
  514. // The `CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY` has
  515. // priority over the deprecated CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
  516. if (cmValue const def = this->Makefile->GetDefinition(
  517. "CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY")) {
  518. this->NoSystemRegistry = !cmIsOn(*def);
  519. } else if (this->Makefile->IsOn(
  520. "CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY")) {
  521. this->NoSystemRegistry = true;
  522. }
  523. // Check whether we should resolve symlinks when finding packages
  524. if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS")) {
  525. this->UseRealPath = true;
  526. }
  527. // Check if Sorting should be enabled
  528. if (cmValue const so =
  529. this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_SORT_ORDER")) {
  530. if (*so == "NAME") {
  531. this->SortOrder = Name_order;
  532. } else if (*so == "NATURAL") {
  533. this->SortOrder = Natural;
  534. } else {
  535. this->SortOrder = None;
  536. }
  537. }
  538. if (cmValue const sd =
  539. this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_SORT_DIRECTION")) {
  540. this->SortDirection = (*sd == "ASC") ? Asc : Dec;
  541. }
  542. // Find what search path locations have been enabled/disable
  543. this->SelectDefaultSearchModes();
  544. // Find the current root path mode.
  545. this->SelectDefaultRootPathMode();
  546. // Find the current bundle/framework search policy.
  547. this->SelectDefaultMacMode();
  548. // Record options.
  549. this->Name = args[0];
  550. std::string components;
  551. const char* components_sep = "";
  552. std::set<std::string> requiredComponents;
  553. std::set<std::string> optionalComponents;
  554. std::vector<std::pair<std::string, const char*>> componentVarDefs;
  555. bool bypassProvider = false;
  556. // Always search directly in a generated path.
  557. this->SearchPathSuffixes.emplace_back();
  558. // Process debug mode
  559. cmMakefile::DebugFindPkgRAII debugFindPkgRAII(this->Makefile, this->Name);
  560. this->DebugMode = this->ComputeIfDebugModeWanted();
  561. // Parse the arguments.
  562. enum Doing
  563. {
  564. DoingNone,
  565. DoingComponents,
  566. DoingOptionalComponents,
  567. DoingNames,
  568. DoingPaths,
  569. DoingPathSuffixes,
  570. DoingConfigs,
  571. DoingHints
  572. };
  573. Doing doing = DoingNone;
  574. cmsys::RegularExpression versionRegex(
  575. R"V(^([0-9]+(\.[0-9]+)*)(\.\.\.(<?)([0-9]+(\.[0-9]+)*))?$)V");
  576. bool haveVersion = false;
  577. std::vector<std::size_t> configArgs;
  578. std::vector<std::size_t> moduleArgs;
  579. for (std::size_t i = 1u; i < args.size(); ++i) {
  580. if (args[i] == "QUIET") {
  581. this->Quiet = true;
  582. doing = DoingNone;
  583. } else if (args[i] == "BYPASS_PROVIDER") {
  584. bypassProvider = true;
  585. doing = DoingNone;
  586. } else if (args[i] == "EXACT") {
  587. this->VersionExact = true;
  588. doing = DoingNone;
  589. } else if (args[i] == "GLOBAL") {
  590. this->GlobalScope = true;
  591. doing = DoingNone;
  592. } else if (args[i] == "MODULE") {
  593. moduleArgs.push_back(i);
  594. doing = DoingNone;
  595. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  596. // NOLINTNEXTLINE(bugprone-branch-clone)
  597. } else if (args[i] == "CONFIG") {
  598. configArgs.push_back(i);
  599. doing = DoingNone;
  600. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  601. // NOLINTNEXTLINE(bugprone-branch-clone)
  602. } else if (args[i] == "NO_MODULE") {
  603. configArgs.push_back(i);
  604. doing = DoingNone;
  605. } else if (args[i] == "REQUIRED") {
  606. this->Required = true;
  607. doing = DoingComponents;
  608. } else if (args[i] == "COMPONENTS") {
  609. doing = DoingComponents;
  610. } else if (args[i] == "OPTIONAL_COMPONENTS") {
  611. doing = DoingOptionalComponents;
  612. } else if (args[i] == "NAMES") {
  613. configArgs.push_back(i);
  614. doing = DoingNames;
  615. } else if (args[i] == "PATHS") {
  616. configArgs.push_back(i);
  617. doing = DoingPaths;
  618. } else if (args[i] == "HINTS") {
  619. configArgs.push_back(i);
  620. doing = DoingHints;
  621. } else if (args[i] == "PATH_SUFFIXES") {
  622. configArgs.push_back(i);
  623. doing = DoingPathSuffixes;
  624. } else if (args[i] == "CONFIGS") {
  625. configArgs.push_back(i);
  626. doing = DoingConfigs;
  627. } else if (args[i] == "NO_POLICY_SCOPE") {
  628. this->PolicyScope = false;
  629. doing = DoingNone;
  630. } else if (args[i] == "NO_CMAKE_PACKAGE_REGISTRY") {
  631. this->NoUserRegistry = true;
  632. configArgs.push_back(i);
  633. doing = DoingNone;
  634. } else if (args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY") {
  635. this->NoSystemRegistry = true;
  636. configArgs.push_back(i);
  637. doing = DoingNone;
  638. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  639. // NOLINTNEXTLINE(bugprone-branch-clone)
  640. } else if (args[i] == "NO_CMAKE_BUILDS_PATH") {
  641. // Ignore legacy option.
  642. configArgs.push_back(i);
  643. doing = DoingNone;
  644. } else if (args[i] == "REGISTRY_VIEW") {
  645. if (++i == args.size()) {
  646. this->SetError("missing required argument for \"REGISTRY_VIEW\"");
  647. return false;
  648. }
  649. auto view = cmWindowsRegistry::ToView(args[i]);
  650. if (view) {
  651. this->RegistryView = *view;
  652. this->RegistryViewDefined = true;
  653. } else {
  654. this->SetError(
  655. cmStrCat("given invalid value for \"REGISTRY_VIEW\": ", args[i]));
  656. return false;
  657. }
  658. } else if (this->CheckCommonArgument(args[i])) {
  659. configArgs.push_back(i);
  660. doing = DoingNone;
  661. } else if ((doing == DoingComponents) ||
  662. (doing == DoingOptionalComponents)) {
  663. // Set a variable telling the find script whether this component
  664. // is required.
  665. const char* isRequired = "1";
  666. if (doing == DoingOptionalComponents) {
  667. isRequired = "0";
  668. optionalComponents.insert(args[i]);
  669. } else {
  670. requiredComponents.insert(args[i]);
  671. }
  672. componentVarDefs.emplace_back(this->Name + "_FIND_REQUIRED_" + args[i],
  673. isRequired);
  674. // Append to the list of required components.
  675. components += components_sep;
  676. components += args[i];
  677. components_sep = ";";
  678. } else if (doing == DoingNames) {
  679. this->Names.push_back(args[i]);
  680. } else if (doing == DoingPaths) {
  681. this->UserGuessArgs.push_back(args[i]);
  682. } else if (doing == DoingHints) {
  683. this->UserHintsArgs.push_back(args[i]);
  684. } else if (doing == DoingPathSuffixes) {
  685. this->AddPathSuffix(args[i]);
  686. } else if (doing == DoingConfigs) {
  687. if (args[i].find_first_of(":/\\") != std::string::npos ||
  688. cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake") {
  689. this->SetError(cmStrCat(
  690. "given CONFIGS option followed by invalid file name \"", args[i],
  691. "\". The names given must be file names without "
  692. "a path and with a \".cmake\" extension."));
  693. return false;
  694. }
  695. this->Configs.push_back(args[i]);
  696. } else if (!haveVersion && versionRegex.find(args[i])) {
  697. haveVersion = true;
  698. this->VersionComplete = args[i];
  699. } else {
  700. this->SetError(
  701. cmStrCat("called with invalid argument \"", args[i], "\""));
  702. return false;
  703. }
  704. }
  705. if (!this->GlobalScope) {
  706. cmValue value(
  707. this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_TARGETS_GLOBAL"));
  708. this->GlobalScope = value.IsOn();
  709. }
  710. std::vector<std::string> doubledComponents;
  711. std::set_intersection(requiredComponents.begin(), requiredComponents.end(),
  712. optionalComponents.begin(), optionalComponents.end(),
  713. std::back_inserter(doubledComponents));
  714. if (!doubledComponents.empty()) {
  715. this->SetError(
  716. cmStrCat("called with components that are both required and "
  717. "optional:\n",
  718. cmWrap(" ", doubledComponents, "", "\n"), "\n"));
  719. return false;
  720. }
  721. // Check and eliminate search modes not allowed by the args provided
  722. this->UseFindModules = configArgs.empty();
  723. this->UseConfigFiles = moduleArgs.empty();
  724. if (!this->UseFindModules && !this->UseConfigFiles) {
  725. std::ostringstream e;
  726. e << "given options exclusive to Module mode:\n";
  727. for (auto si : moduleArgs) {
  728. e << " " << args[si] << "\n";
  729. }
  730. e << "and options exclusive to Config mode:\n";
  731. for (auto si : configArgs) {
  732. e << " " << args[si] << "\n";
  733. }
  734. e << "The options are incompatible.";
  735. this->SetError(e.str());
  736. return false;
  737. }
  738. // Ignore EXACT with no version.
  739. if (this->VersionComplete.empty() && this->VersionExact) {
  740. this->VersionExact = false;
  741. this->Makefile->IssueMessage(
  742. MessageType::AUTHOR_WARNING,
  743. "Ignoring EXACT since no version is requested.");
  744. }
  745. if (this->VersionComplete.empty() || components.empty()) {
  746. // Check whether we are recursing inside "Find<name>.cmake" within
  747. // another find_package(<name>) call.
  748. std::string const mod = cmStrCat(this->Name, "_FIND_MODULE");
  749. if (this->Makefile->IsOn(mod)) {
  750. if (this->VersionComplete.empty()) {
  751. // Get version information from the outer call if necessary.
  752. // Requested version string.
  753. std::string const ver = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
  754. this->VersionComplete = this->Makefile->GetSafeDefinition(ver);
  755. // Whether an exact version is required.
  756. std::string const exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
  757. this->VersionExact = this->Makefile->IsOn(exact);
  758. }
  759. if (components.empty()) {
  760. std::string const components_var = this->Name + "_FIND_COMPONENTS";
  761. components = this->Makefile->GetSafeDefinition(components_var);
  762. }
  763. }
  764. }
  765. // fill various parts of version specification
  766. if (!this->VersionComplete.empty()) {
  767. if (!versionRegex.find(this->VersionComplete)) {
  768. this->SetError("called with invalid version specification.");
  769. return false;
  770. }
  771. this->Version = versionRegex.match(1);
  772. this->VersionMax = versionRegex.match(5);
  773. if (versionRegex.match(4) == "<"_s) {
  774. this->VersionRangeMax = VERSION_ENDPOINT_EXCLUDED;
  775. }
  776. if (!this->VersionMax.empty()) {
  777. this->VersionRange = this->VersionComplete;
  778. }
  779. }
  780. if (!this->VersionRange.empty()) {
  781. // version range must not be empty
  782. if ((this->VersionRangeMax == VERSION_ENDPOINT_INCLUDED &&
  783. cmSystemTools::VersionCompareGreater(this->Version,
  784. this->VersionMax)) ||
  785. (this->VersionRangeMax == VERSION_ENDPOINT_EXCLUDED &&
  786. cmSystemTools::VersionCompareGreaterEq(this->Version,
  787. this->VersionMax))) {
  788. this->SetError("specified version range is empty.");
  789. return false;
  790. }
  791. }
  792. if (this->VersionExact && !this->VersionRange.empty()) {
  793. this->SetError("EXACT cannot be specified with a version range.");
  794. return false;
  795. }
  796. if (!this->Version.empty()) {
  797. this->VersionCount =
  798. parseVersion(this->Version, this->VersionMajor, this->VersionMinor,
  799. this->VersionPatch, this->VersionTweak);
  800. }
  801. if (!this->VersionMax.empty()) {
  802. this->VersionMaxCount = parseVersion(
  803. this->VersionMax, this->VersionMaxMajor, this->VersionMaxMinor,
  804. this->VersionMaxPatch, this->VersionMaxTweak);
  805. }
  806. const std::string makePackageRequiredVar =
  807. cmStrCat("CMAKE_REQUIRE_FIND_PACKAGE_", this->Name);
  808. const bool makePackageRequiredSet =
  809. this->Makefile->IsOn(makePackageRequiredVar);
  810. if (makePackageRequiredSet) {
  811. if (this->Required) {
  812. this->Makefile->IssueMessage(
  813. MessageType::WARNING,
  814. cmStrCat("for module ", this->Name,
  815. " already called with REQUIRED, thus ",
  816. makePackageRequiredVar, " has no effect."));
  817. } else {
  818. this->Required = true;
  819. }
  820. }
  821. std::string const disableFindPackageVar =
  822. cmStrCat("CMAKE_DISABLE_FIND_PACKAGE_", this->Name);
  823. if (this->Makefile->IsOn(disableFindPackageVar)) {
  824. if (this->Required) {
  825. this->SetError(
  826. cmStrCat("for module ", this->Name,
  827. (makePackageRequiredSet
  828. ? " was made REQUIRED with " + makePackageRequiredVar
  829. : " called with REQUIRED, "),
  830. " but ", disableFindPackageVar,
  831. " is enabled. A REQUIRED package cannot be disabled."));
  832. return false;
  833. }
  834. return true;
  835. }
  836. // Now choose what method(s) we will use to satisfy the request. Note that
  837. // we still want all the above checking of arguments, etc. regardless of the
  838. // method used. This will ensure ill-formed arguments are caught earlier,
  839. // before things like dependency providers need to deal with them.
  840. // A dependency provider (if set) gets first look before other methods.
  841. // We do this before modifying the package root path stack because a
  842. // provider might use methods that ignore that.
  843. cmState* const state = this->Makefile->GetState();
  844. cmState::Command const providerCommand = state->GetDependencyProviderCommand(
  845. cmDependencyProvider::Method::FindPackage);
  846. if (bypassProvider) {
  847. if (this->DebugMode && providerCommand) {
  848. this->DebugMessage(
  849. "BYPASS_PROVIDER given, skipping dependency provider");
  850. }
  851. } else if (providerCommand) {
  852. if (this->DebugMode) {
  853. this->DebugMessage(cmStrCat("Trying dependency provider command: ",
  854. state->GetDependencyProvider()->GetCommand(),
  855. "()"));
  856. }
  857. std::vector<cmListFileArgument> listFileArgs(args.size() + 1);
  858. listFileArgs[0] =
  859. cmListFileArgument("FIND_PACKAGE", cmListFileArgument::Unquoted, 0);
  860. std::transform(args.begin(), args.end(), listFileArgs.begin() + 1,
  861. [](const std::string& arg) {
  862. return cmListFileArgument(arg,
  863. cmListFileArgument::Bracket, 0);
  864. });
  865. if (!providerCommand(listFileArgs, this->Status)) {
  866. return false;
  867. }
  868. if (this->Makefile->IsOn(cmStrCat(this->Name, "_FOUND"))) {
  869. if (this->DebugMode) {
  870. this->DebugMessage("Package was found by the dependency provider");
  871. }
  872. this->AppendSuccessInformation();
  873. return true;
  874. }
  875. }
  876. // Limit package nesting depth well below the recursion depth limit because
  877. // find_package nesting uses more stack space than normal recursion.
  878. {
  879. static std::size_t const findPackageDepthMinMax = 100;
  880. std::size_t const findPackageDepthMax = std::max(
  881. this->Makefile->GetRecursionDepthLimit() / 2, findPackageDepthMinMax);
  882. std::size_t const findPackageDepth =
  883. this->Makefile->FindPackageRootPathStack.size() + 1;
  884. if (findPackageDepth > findPackageDepthMax) {
  885. this->SetError(cmStrCat("maximum nesting depth of ", findPackageDepthMax,
  886. " exceeded."));
  887. return false;
  888. }
  889. }
  890. this->PushFindPackageRootPathStack();
  891. this->SetModuleVariables(components, componentVarDefs);
  892. // See if we have been told to delegate to FetchContent or some other
  893. // redirected config package first. We have to check all names that
  894. // find_package() may look for, but only need to invoke the override for the
  895. // first one that matches.
  896. auto overrideNames = this->Names;
  897. if (overrideNames.empty()) {
  898. overrideNames.push_back(this->Name);
  899. }
  900. bool forceConfigMode = false;
  901. const auto redirectsDir =
  902. this->Makefile->GetSafeDefinition("CMAKE_FIND_PACKAGE_REDIRECTS_DIR");
  903. for (const auto& overrideName : overrideNames) {
  904. const auto nameLower = cmSystemTools::LowerCase(overrideName);
  905. const auto delegatePropName =
  906. cmStrCat("_FetchContent_", nameLower, "_override_find_package");
  907. const cmValue delegateToFetchContentProp =
  908. this->Makefile->GetState()->GetGlobalProperty(delegatePropName);
  909. if (delegateToFetchContentProp.IsOn()) {
  910. // When this property is set, the FetchContent module has already been
  911. // included at least once, so we know the FetchContent_MakeAvailable()
  912. // command will be defined. Any future find_package() calls after this
  913. // one for this package will by-pass this once-only delegation.
  914. // The following call will typically create a <name>-config.cmake file
  915. // in the redirectsDir, which we still want to process like any other
  916. // config file to ensure we follow normal find_package() processing.
  917. cmListFileFunction func(
  918. "FetchContent_MakeAvailable", 0, 0,
  919. { cmListFileArgument(overrideName, cmListFileArgument::Unquoted, 0) });
  920. if (!this->Makefile->ExecuteCommand(func, this->Status)) {
  921. return false;
  922. }
  923. }
  924. if (cmSystemTools::FileExists(
  925. cmStrCat(redirectsDir, '/', nameLower, "-config.cmake")) ||
  926. cmSystemTools::FileExists(
  927. cmStrCat(redirectsDir, '/', overrideName, "Config.cmake"))) {
  928. // Force the use of this redirected config package file, regardless of
  929. // the type of find_package() call. Files in the redirectsDir must always
  930. // take priority over everything else.
  931. forceConfigMode = true;
  932. this->UseConfigFiles = true;
  933. this->UseFindModules = false;
  934. this->Names.clear();
  935. this->Names.emplace_back(overrideName); // Force finding this one
  936. this->Variable = cmStrCat(this->Name, "_DIR");
  937. this->SetConfigDirCacheVariable(redirectsDir);
  938. break;
  939. }
  940. }
  941. // See if there is a Find<PackageName>.cmake module.
  942. bool loadedPackage = false;
  943. if (forceConfigMode) {
  944. loadedPackage = this->FindPackageUsingConfigMode();
  945. } else if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
  946. if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) {
  947. loadedPackage = true;
  948. } else {
  949. if (this->FindPackageUsingModuleMode()) {
  950. loadedPackage = true;
  951. } else {
  952. // The package was not loaded. Report errors.
  953. if (this->HandlePackageMode(HandlePackageModeType::Module)) {
  954. loadedPackage = true;
  955. }
  956. }
  957. }
  958. } else {
  959. if (this->UseFindModules && this->FindPackageUsingModuleMode()) {
  960. loadedPackage = true;
  961. } else {
  962. // Handle CMAKE_FIND_PACKAGE_WARN_NO_MODULE (warn when CONFIG mode is
  963. // implicitly assumed)
  964. if (this->UseFindModules && this->UseConfigFiles &&
  965. this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) {
  966. std::ostringstream aw;
  967. if (this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2, 8, 8)) {
  968. aw << "find_package called without either MODULE or CONFIG option "
  969. "and "
  970. "no Find"
  971. << this->Name
  972. << ".cmake module is in CMAKE_MODULE_PATH. "
  973. "Add MODULE to exclusively request Module mode and fail if "
  974. "Find"
  975. << this->Name
  976. << ".cmake is missing. "
  977. "Add CONFIG to exclusively request Config mode and search for "
  978. "a "
  979. "package configuration file provided by "
  980. << this->Name << " (" << this->Name << "Config.cmake or "
  981. << cmSystemTools::LowerCase(this->Name) << "-config.cmake). ";
  982. } else {
  983. aw << "find_package called without NO_MODULE option and no "
  984. "Find"
  985. << this->Name
  986. << ".cmake module is in CMAKE_MODULE_PATH. "
  987. "Add NO_MODULE to exclusively request Config mode and search "
  988. "for a "
  989. "package configuration file provided by "
  990. << this->Name << " (" << this->Name << "Config.cmake or "
  991. << cmSystemTools::LowerCase(this->Name)
  992. << "-config.cmake). Otherwise make Find" << this->Name
  993. << ".cmake available in CMAKE_MODULE_PATH.";
  994. }
  995. aw << "\n"
  996. "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this "
  997. "warning.)";
  998. this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, aw.str());
  999. }
  1000. if (this->FindPackageUsingConfigMode()) {
  1001. loadedPackage = true;
  1002. }
  1003. }
  1004. }
  1005. this->AppendSuccessInformation();
  1006. // Restore original state of "_FIND_" variables set in SetModuleVariables()
  1007. this->RestoreFindDefinitions();
  1008. this->PopFindPackageRootPathStack();
  1009. if (!this->DebugBuffer.empty()) {
  1010. this->DebugMessage(this->DebugBuffer);
  1011. }
  1012. return loadedPackage;
  1013. }
  1014. bool cmFindPackageCommand::FindPackageUsingModuleMode()
  1015. {
  1016. bool foundModule = false;
  1017. if (!this->FindModule(foundModule)) {
  1018. return false;
  1019. }
  1020. return foundModule;
  1021. }
  1022. bool cmFindPackageCommand::FindPackageUsingConfigMode()
  1023. {
  1024. this->Variable = cmStrCat(this->Name, "_DIR");
  1025. // Add the default name.
  1026. if (this->Names.empty()) {
  1027. this->Names.push_back(this->Name);
  1028. }
  1029. // Add the default configs.
  1030. if (this->Configs.empty()) {
  1031. for (std::string const& n : this->Names) {
  1032. std::string config = cmStrCat(n, "Config.cmake");
  1033. this->Configs.push_back(config);
  1034. config = cmStrCat(cmSystemTools::LowerCase(n), "-config.cmake");
  1035. this->Configs.push_back(std::move(config));
  1036. }
  1037. }
  1038. // get igonored paths from vars and reroot them.
  1039. std::vector<std::string> ignored;
  1040. this->GetIgnoredPaths(ignored);
  1041. this->RerootPaths(ignored);
  1042. // Construct a set of ignored paths
  1043. this->IgnoredPaths.clear();
  1044. this->IgnoredPaths.insert(ignored.begin(), ignored.end());
  1045. // get igonored prefix paths from vars and reroot them.
  1046. std::vector<std::string> ignoredPrefixes;
  1047. this->GetIgnoredPrefixPaths(ignoredPrefixes);
  1048. this->RerootPaths(ignoredPrefixes);
  1049. // Construct a set of ignored prefix paths
  1050. this->IgnoredPrefixPaths.clear();
  1051. this->IgnoredPrefixPaths.insert(ignoredPrefixes.begin(),
  1052. ignoredPrefixes.end());
  1053. // Find and load the package.
  1054. return this->HandlePackageMode(HandlePackageModeType::Config);
  1055. }
  1056. void cmFindPackageCommand::SetVersionVariables(
  1057. const std::function<void(const std::string&, cm::string_view)>&
  1058. addDefinition,
  1059. const std::string& prefix, const std::string& version,
  1060. const unsigned int count, const unsigned int major, const unsigned int minor,
  1061. const unsigned int patch, const unsigned int tweak)
  1062. {
  1063. addDefinition(prefix, version);
  1064. char buf[64];
  1065. snprintf(buf, sizeof(buf), "%u", major);
  1066. addDefinition(prefix + "_MAJOR", buf);
  1067. snprintf(buf, sizeof(buf), "%u", minor);
  1068. addDefinition(prefix + "_MINOR", buf);
  1069. snprintf(buf, sizeof(buf), "%u", patch);
  1070. addDefinition(prefix + "_PATCH", buf);
  1071. snprintf(buf, sizeof(buf), "%u", tweak);
  1072. addDefinition(prefix + "_TWEAK", buf);
  1073. snprintf(buf, sizeof(buf), "%u", count);
  1074. addDefinition(prefix + "_COUNT", buf);
  1075. }
  1076. void cmFindPackageCommand::SetModuleVariables(
  1077. const std::string& components,
  1078. const std::vector<std::pair<std::string, const char*>>& componentVarDefs)
  1079. {
  1080. this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name);
  1081. // Store the list of components and associated variable definitions
  1082. std::string components_var = this->Name + "_FIND_COMPONENTS";
  1083. this->AddFindDefinition(components_var, components);
  1084. for (const auto& varDef : componentVarDefs) {
  1085. this->AddFindDefinition(varDef.first, varDef.second);
  1086. }
  1087. if (this->Quiet) {
  1088. // Tell the module that is about to be read that it should find
  1089. // quietly.
  1090. std::string quietly = cmStrCat(this->Name, "_FIND_QUIETLY");
  1091. this->AddFindDefinition(quietly, "1"_s);
  1092. }
  1093. if (this->Required) {
  1094. // Tell the module that is about to be read that it should report
  1095. // a fatal error if the package is not found.
  1096. std::string req = cmStrCat(this->Name, "_FIND_REQUIRED");
  1097. this->AddFindDefinition(req, "1"_s);
  1098. }
  1099. if (!this->VersionComplete.empty()) {
  1100. std::string req = cmStrCat(this->Name, "_FIND_VERSION_COMPLETE");
  1101. this->AddFindDefinition(req, this->VersionComplete);
  1102. }
  1103. // Tell the module that is about to be read what version of the
  1104. // package has been requested.
  1105. auto addDefinition = [this](const std::string& variable,
  1106. cm::string_view value) {
  1107. this->AddFindDefinition(variable, value);
  1108. };
  1109. if (!this->Version.empty()) {
  1110. auto prefix = cmStrCat(this->Name, "_FIND_VERSION"_s);
  1111. this->SetVersionVariables(addDefinition, prefix, this->Version,
  1112. this->VersionCount, this->VersionMajor,
  1113. this->VersionMinor, this->VersionPatch,
  1114. this->VersionTweak);
  1115. // Tell the module whether an exact version has been requested.
  1116. auto exact = cmStrCat(this->Name, "_FIND_VERSION_EXACT");
  1117. this->AddFindDefinition(exact, this->VersionExact ? "1"_s : "0"_s);
  1118. }
  1119. if (!this->VersionRange.empty()) {
  1120. auto prefix = cmStrCat(this->Name, "_FIND_VERSION_MIN"_s);
  1121. this->SetVersionVariables(addDefinition, prefix, this->Version,
  1122. this->VersionCount, this->VersionMajor,
  1123. this->VersionMinor, this->VersionPatch,
  1124. this->VersionTweak);
  1125. prefix = cmStrCat(this->Name, "_FIND_VERSION_MAX"_s);
  1126. this->SetVersionVariables(addDefinition, prefix, this->VersionMax,
  1127. this->VersionMaxCount, this->VersionMaxMajor,
  1128. this->VersionMaxMinor, this->VersionMaxPatch,
  1129. this->VersionMaxTweak);
  1130. auto id = cmStrCat(this->Name, "_FIND_VERSION_RANGE");
  1131. this->AddFindDefinition(id, this->VersionRange);
  1132. id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MIN");
  1133. this->AddFindDefinition(id, this->VersionRangeMin);
  1134. id = cmStrCat(this->Name, "_FIND_VERSION_RANGE_MAX");
  1135. this->AddFindDefinition(id, this->VersionRangeMax);
  1136. }
  1137. if (this->RegistryViewDefined) {
  1138. this->AddFindDefinition(cmStrCat(this->Name, "_FIND_REGISTRY_VIEW"),
  1139. cmWindowsRegistry::FromView(this->RegistryView));
  1140. }
  1141. }
  1142. void cmFindPackageCommand::AddFindDefinition(const std::string& var,
  1143. const cm::string_view value)
  1144. {
  1145. if (cmValue old = this->Makefile->GetDefinition(var)) {
  1146. this->OriginalDefs[var].exists = true;
  1147. this->OriginalDefs[var].value = *old;
  1148. } else {
  1149. this->OriginalDefs[var].exists = false;
  1150. }
  1151. this->Makefile->AddDefinition(var, value);
  1152. }
  1153. void cmFindPackageCommand::RestoreFindDefinitions()
  1154. {
  1155. for (auto const& i : this->OriginalDefs) {
  1156. OriginalDef const& od = i.second;
  1157. if (od.exists) {
  1158. this->Makefile->AddDefinition(i.first, od.value);
  1159. } else {
  1160. this->Makefile->RemoveDefinition(i.first);
  1161. }
  1162. }
  1163. }
  1164. bool cmFindPackageCommand::FindModule(bool& found)
  1165. {
  1166. std::string moduleFileName = cmStrCat("Find", this->Name, ".cmake");
  1167. bool system = false;
  1168. std::string debugBuffer = cmStrCat(
  1169. "find_package considered the following paths for ", moduleFileName, ":\n");
  1170. std::string mfile = this->Makefile->GetModulesFile(
  1171. moduleFileName, system, this->DebugMode, debugBuffer);
  1172. if (this->DebugMode) {
  1173. if (mfile.empty()) {
  1174. debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n");
  1175. } else {
  1176. debugBuffer =
  1177. cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n");
  1178. }
  1179. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1180. }
  1181. if (!mfile.empty()) {
  1182. if (system) {
  1183. auto const it = this->DeprecatedFindModules.find(this->Name);
  1184. if (it != this->DeprecatedFindModules.end()) {
  1185. cmPolicies::PolicyStatus status =
  1186. this->Makefile->GetPolicyStatus(it->second);
  1187. switch (status) {
  1188. case cmPolicies::WARN: {
  1189. this->Makefile->IssueMessage(
  1190. MessageType::AUTHOR_WARNING,
  1191. cmStrCat(cmPolicies::GetPolicyWarning(it->second), "\n"));
  1192. CM_FALLTHROUGH;
  1193. }
  1194. case cmPolicies::OLD:
  1195. break;
  1196. case cmPolicies::REQUIRED_IF_USED:
  1197. case cmPolicies::REQUIRED_ALWAYS:
  1198. case cmPolicies::NEW:
  1199. return true;
  1200. }
  1201. }
  1202. }
  1203. // Load the module we found, and set "<name>_FIND_MODULE" to true
  1204. // while inside it.
  1205. found = true;
  1206. std::string const var = cmStrCat(this->Name, "_FIND_MODULE");
  1207. this->Makefile->AddDefinition(var, "1");
  1208. bool result = this->ReadListFile(mfile, DoPolicyScope);
  1209. this->Makefile->RemoveDefinition(var);
  1210. if (this->DebugMode) {
  1211. std::string const foundVar = cmStrCat(this->Name, "_FOUND");
  1212. if (this->Makefile->IsDefinitionSet(foundVar) &&
  1213. !this->Makefile->IsOn(foundVar)) {
  1214. this->DebugBuffer = cmStrCat(
  1215. this->DebugBuffer, "The module is considered not found due to ",
  1216. foundVar, " being FALSE.");
  1217. }
  1218. }
  1219. return result;
  1220. }
  1221. return true;
  1222. }
  1223. bool cmFindPackageCommand::HandlePackageMode(
  1224. const HandlePackageModeType handlePackageModeType)
  1225. {
  1226. this->ConsideredConfigs.clear();
  1227. // Try to find the config file.
  1228. cmValue def = this->Makefile->GetDefinition(this->Variable);
  1229. // Try to load the config file if the directory is known
  1230. bool fileFound = false;
  1231. if (this->UseConfigFiles) {
  1232. if (!cmIsOff(def)) {
  1233. // Get the directory from the variable value.
  1234. std::string dir = *def;
  1235. cmSystemTools::ConvertToUnixSlashes(dir);
  1236. // Treat relative paths with respect to the current source dir.
  1237. if (!cmSystemTools::FileIsFullPath(dir)) {
  1238. dir = "/" + dir;
  1239. dir = this->Makefile->GetCurrentSourceDirectory() + dir;
  1240. }
  1241. // The file location was cached. Look for the correct file.
  1242. std::string file;
  1243. if (this->FindConfigFile(dir, file)) {
  1244. this->FileFound = file;
  1245. fileFound = true;
  1246. }
  1247. def = this->Makefile->GetDefinition(this->Variable);
  1248. }
  1249. // Search for the config file if it is not already found.
  1250. if (cmIsOff(def) || !fileFound) {
  1251. fileFound = this->FindConfig();
  1252. }
  1253. // Sanity check.
  1254. if (fileFound && this->FileFound.empty()) {
  1255. this->Makefile->IssueMessage(
  1256. MessageType::INTERNAL_ERROR,
  1257. "fileFound is true but FileFound is empty!");
  1258. fileFound = false;
  1259. }
  1260. }
  1261. std::string const foundVar = cmStrCat(this->Name, "_FOUND");
  1262. std::string const notFoundMessageVar =
  1263. cmStrCat(this->Name, "_NOT_FOUND_MESSAGE");
  1264. std::string notFoundMessage;
  1265. // If the directory for the config file was found, try to read the file.
  1266. bool result = true;
  1267. bool found = false;
  1268. bool configFileSetFOUNDFalse = false;
  1269. if (fileFound) {
  1270. if (this->Makefile->IsDefinitionSet(foundVar) &&
  1271. !this->Makefile->IsOn(foundVar)) {
  1272. // by removing Foo_FOUND here if it is FALSE, we don't really change
  1273. // the situation for the Config file which is about to be included,
  1274. // but we make it possible to detect later on whether the Config file
  1275. // has set Foo_FOUND to FALSE itself:
  1276. this->Makefile->RemoveDefinition(foundVar);
  1277. }
  1278. this->Makefile->RemoveDefinition(notFoundMessageVar);
  1279. // Set the version variables before loading the config file.
  1280. // It may override them.
  1281. this->StoreVersionFound();
  1282. // Parse the configuration file.
  1283. if (this->ReadListFile(this->FileFound, DoPolicyScope)) {
  1284. // The package has been found.
  1285. found = true;
  1286. // Check whether the Config file has set Foo_FOUND to FALSE:
  1287. if (this->Makefile->IsDefinitionSet(foundVar) &&
  1288. !this->Makefile->IsOn(foundVar)) {
  1289. // we get here if the Config file has set Foo_FOUND actively to FALSE
  1290. found = false;
  1291. configFileSetFOUNDFalse = true;
  1292. notFoundMessage =
  1293. this->Makefile->GetSafeDefinition(notFoundMessageVar);
  1294. }
  1295. } else {
  1296. // The configuration file is invalid.
  1297. result = false;
  1298. }
  1299. }
  1300. if (this->UseFindModules && !found &&
  1301. handlePackageModeType == HandlePackageModeType::Config &&
  1302. this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
  1303. // Config mode failed. Allow Module case.
  1304. result = false;
  1305. }
  1306. // package not found
  1307. if (result && !found) {
  1308. // warn if package required or neither quiet nor in config mode
  1309. if (this->Required ||
  1310. !(this->Quiet ||
  1311. (this->UseConfigFiles && !this->UseFindModules &&
  1312. this->ConsideredConfigs.empty()))) {
  1313. // The variable is not set.
  1314. std::ostringstream e;
  1315. std::ostringstream aw;
  1316. if (configFileSetFOUNDFalse) {
  1317. /* clang-format off */
  1318. e << "Found package configuration file:\n"
  1319. " " << this->FileFound << "\n"
  1320. "but it set " << foundVar << " to FALSE so package \"" <<
  1321. this->Name << "\" is considered to be NOT FOUND.";
  1322. /* clang-format on */
  1323. if (!notFoundMessage.empty()) {
  1324. e << " Reason given by package: \n" << notFoundMessage << "\n";
  1325. }
  1326. }
  1327. // If there are files in ConsideredConfigs, it means that FooConfig.cmake
  1328. // have been found, but they didn't have appropriate versions.
  1329. else if (!this->ConsideredConfigs.empty()) {
  1330. auto duplicate_end = cmRemoveDuplicates(this->ConsideredConfigs);
  1331. e << "Could not find a configuration file for package \"" << this->Name
  1332. << "\" that "
  1333. << (this->VersionExact ? "exactly matches" : "is compatible with")
  1334. << " requested version "
  1335. << (this->VersionRange.empty() ? "" : "range ") << "\""
  1336. << this->VersionComplete
  1337. << "\".\n"
  1338. "The following configuration files were considered but not "
  1339. "accepted:\n";
  1340. for (ConfigFileInfo const& info :
  1341. cmMakeRange(this->ConsideredConfigs.cbegin(), duplicate_end)) {
  1342. e << " " << info.filename << ", version: " << info.version << "\n";
  1343. }
  1344. } else {
  1345. std::string requestedVersionString;
  1346. if (!this->VersionComplete.empty()) {
  1347. requestedVersionString =
  1348. cmStrCat(" (requested version ", this->VersionComplete, ')');
  1349. }
  1350. if (this->UseConfigFiles) {
  1351. if (this->UseFindModules) {
  1352. e << "By not providing \"Find" << this->Name
  1353. << ".cmake\" in "
  1354. "CMAKE_MODULE_PATH this project has asked CMake to find a "
  1355. "package configuration file provided by \""
  1356. << this->Name
  1357. << "\", "
  1358. "but CMake did not find one.\n";
  1359. }
  1360. if (this->Configs.size() == 1) {
  1361. e << "Could not find a package configuration file named \""
  1362. << this->Configs[0] << "\" provided by package \"" << this->Name
  1363. << "\"" << requestedVersionString << ".\n";
  1364. } else {
  1365. e << "Could not find a package configuration file provided by \""
  1366. << this->Name << "\"" << requestedVersionString
  1367. << " with any of the following names:\n"
  1368. << cmWrap(" ", this->Configs, "", "\n") << "\n";
  1369. }
  1370. e << "Add the installation prefix of \"" << this->Name
  1371. << "\" to "
  1372. "CMAKE_PREFIX_PATH or set \""
  1373. << this->Variable
  1374. << "\" to a "
  1375. "directory containing one of the above files. "
  1376. "If \""
  1377. << this->Name
  1378. << "\" provides a separate development "
  1379. "package or SDK, be sure it has been installed.";
  1380. } else // if(!this->UseFindModules && !this->UseConfigFiles)
  1381. {
  1382. e << "No \"Find" << this->Name
  1383. << ".cmake\" found in "
  1384. "CMAKE_MODULE_PATH.";
  1385. aw
  1386. << "Find" << this->Name
  1387. << ".cmake must either be part of this "
  1388. "project itself, in this case adjust CMAKE_MODULE_PATH so that "
  1389. "it points to the correct location inside its source tree.\n"
  1390. "Or it must be installed by a package which has already been "
  1391. "found via find_package(). In this case make sure that "
  1392. "package has indeed been found and adjust CMAKE_MODULE_PATH to "
  1393. "contain the location where that package has installed "
  1394. "Find"
  1395. << this->Name
  1396. << ".cmake. This must be a location "
  1397. "provided by that package. This error in general means that "
  1398. "the buildsystem of this project is relying on a Find-module "
  1399. "without ensuring that it is actually available.\n";
  1400. }
  1401. }
  1402. this->Makefile->IssueMessage(this->Required ? MessageType::FATAL_ERROR
  1403. : MessageType::WARNING,
  1404. e.str());
  1405. if (this->Required) {
  1406. cmSystemTools::SetFatalErrorOccurred();
  1407. }
  1408. if (!aw.str().empty()) {
  1409. this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, aw.str());
  1410. }
  1411. }
  1412. // output result if in config mode but not in quiet mode
  1413. else if (!this->Quiet) {
  1414. this->Makefile->DisplayStatus(cmStrCat("Could NOT find ", this->Name,
  1415. " (missing: ", this->Name,
  1416. "_DIR)"),
  1417. -1);
  1418. }
  1419. }
  1420. // Set a variable marking whether the package was found.
  1421. this->Makefile->AddDefinition(foundVar, found ? "1" : "0");
  1422. // Set a variable naming the configuration file that was found.
  1423. std::string const fileVar = cmStrCat(this->Name, "_CONFIG");
  1424. if (found) {
  1425. this->Makefile->AddDefinition(fileVar, this->FileFound);
  1426. } else {
  1427. this->Makefile->RemoveDefinition(fileVar);
  1428. }
  1429. std::string const consideredConfigsVar =
  1430. cmStrCat(this->Name, "_CONSIDERED_CONFIGS");
  1431. std::string const consideredVersionsVar =
  1432. cmStrCat(this->Name, "_CONSIDERED_VERSIONS");
  1433. std::string consideredConfigFiles;
  1434. std::string consideredVersions;
  1435. const char* sep = "";
  1436. for (ConfigFileInfo const& i : this->ConsideredConfigs) {
  1437. consideredConfigFiles += sep;
  1438. consideredVersions += sep;
  1439. consideredConfigFiles += i.filename;
  1440. consideredVersions += i.version;
  1441. sep = ";";
  1442. }
  1443. this->Makefile->AddDefinition(consideredConfigsVar, consideredConfigFiles);
  1444. this->Makefile->AddDefinition(consideredVersionsVar, consideredVersions);
  1445. return result;
  1446. }
  1447. bool cmFindPackageCommand::FindConfig()
  1448. {
  1449. // Compute the set of search prefixes.
  1450. this->ComputePrefixes();
  1451. // Look for the project's configuration file.
  1452. bool found = false;
  1453. if (this->DebugMode) {
  1454. this->DebugBuffer = cmStrCat(this->DebugBuffer,
  1455. "find_package considered the following "
  1456. "locations for ",
  1457. this->Name, "'s Config module:\n");
  1458. }
  1459. // Search for frameworks.
  1460. if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) {
  1461. found = this->FindFrameworkConfig();
  1462. }
  1463. // Search for apps.
  1464. if (!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly)) {
  1465. found = this->FindAppBundleConfig();
  1466. }
  1467. // Search prefixes.
  1468. if (!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly)) {
  1469. found = this->FindPrefixedConfig();
  1470. }
  1471. // Search for frameworks.
  1472. if (!found && this->SearchFrameworkLast) {
  1473. found = this->FindFrameworkConfig();
  1474. }
  1475. // Search for apps.
  1476. if (!found && this->SearchAppBundleLast) {
  1477. found = this->FindAppBundleConfig();
  1478. }
  1479. if (this->DebugMode) {
  1480. if (found) {
  1481. this->DebugBuffer = cmStrCat(
  1482. this->DebugBuffer, "The file was found at\n ", this->FileFound, "\n");
  1483. } else {
  1484. this->DebugBuffer =
  1485. cmStrCat(this->DebugBuffer, "The file was not found.\n");
  1486. }
  1487. }
  1488. // Store the entry in the cache so it can be set by the user.
  1489. std::string init;
  1490. if (found) {
  1491. init = cmSystemTools::GetFilenamePath(this->FileFound);
  1492. } else {
  1493. init = this->Variable + "-NOTFOUND";
  1494. }
  1495. // We force the value since we do not get here if it was already set.
  1496. this->SetConfigDirCacheVariable(init);
  1497. return found;
  1498. }
  1499. void cmFindPackageCommand::SetConfigDirCacheVariable(const std::string& value)
  1500. {
  1501. std::string const help =
  1502. cmStrCat("The directory containing a CMake configuration file for ",
  1503. this->Name, '.');
  1504. this->Makefile->AddCacheDefinition(this->Variable, value, help.c_str(),
  1505. cmStateEnums::PATH, true);
  1506. if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) ==
  1507. cmPolicies::NEW &&
  1508. this->Makefile->IsNormalDefinitionSet(this->Variable)) {
  1509. this->Makefile->AddDefinition(this->Variable, value);
  1510. }
  1511. }
  1512. bool cmFindPackageCommand::FindPrefixedConfig()
  1513. {
  1514. std::vector<std::string> const& prefixes = this->SearchPaths;
  1515. return std::any_of(
  1516. prefixes.begin(), prefixes.end(),
  1517. [this](std::string const& p) -> bool { return this->SearchPrefix(p); });
  1518. }
  1519. bool cmFindPackageCommand::FindFrameworkConfig()
  1520. {
  1521. std::vector<std::string> const& prefixes = this->SearchPaths;
  1522. return std::any_of(prefixes.begin(), prefixes.end(),
  1523. [this](std::string const& p) -> bool {
  1524. return this->SearchFrameworkPrefix(p);
  1525. });
  1526. }
  1527. bool cmFindPackageCommand::FindAppBundleConfig()
  1528. {
  1529. std::vector<std::string> const& prefixes = this->SearchPaths;
  1530. return std::any_of(prefixes.begin(), prefixes.end(),
  1531. [this](std::string const& p) -> bool {
  1532. return this->SearchAppBundlePrefix(p);
  1533. });
  1534. }
  1535. bool cmFindPackageCommand::ReadListFile(const std::string& f,
  1536. const PolicyScopeRule psr)
  1537. {
  1538. const bool noPolicyScope = !this->PolicyScope || psr == NoPolicyScope;
  1539. using ITScope = cmMakefile::ImportedTargetScope;
  1540. ITScope scope = this->GlobalScope ? ITScope::Global : ITScope::Local;
  1541. cmMakefile::SetGlobalTargetImportScope globScope(this->Makefile, scope);
  1542. if (this->Makefile->ReadDependentFile(f, noPolicyScope)) {
  1543. return true;
  1544. }
  1545. std::string const e = cmStrCat("Error reading CMake code from \"", f, "\".");
  1546. this->SetError(e);
  1547. return false;
  1548. }
  1549. void cmFindPackageCommand::AppendToFoundProperty(const bool found)
  1550. {
  1551. std::vector<std::string> foundContents;
  1552. cmValue foundProp =
  1553. this->Makefile->GetState()->GetGlobalProperty("PACKAGES_FOUND");
  1554. if (cmNonempty(foundProp)) {
  1555. cmExpandList(*foundProp, foundContents, false);
  1556. auto nameIt =
  1557. std::find(foundContents.begin(), foundContents.end(), this->Name);
  1558. if (nameIt != foundContents.end()) {
  1559. foundContents.erase(nameIt);
  1560. }
  1561. }
  1562. std::vector<std::string> notFoundContents;
  1563. cmValue notFoundProp =
  1564. this->Makefile->GetState()->GetGlobalProperty("PACKAGES_NOT_FOUND");
  1565. if (cmNonempty(notFoundProp)) {
  1566. cmExpandList(*notFoundProp, notFoundContents, false);
  1567. auto nameIt =
  1568. std::find(notFoundContents.begin(), notFoundContents.end(), this->Name);
  1569. if (nameIt != notFoundContents.end()) {
  1570. notFoundContents.erase(nameIt);
  1571. }
  1572. }
  1573. if (found) {
  1574. foundContents.push_back(this->Name);
  1575. } else {
  1576. notFoundContents.push_back(this->Name);
  1577. }
  1578. std::string tmp = cmJoin(foundContents, ";");
  1579. this->Makefile->GetState()->SetGlobalProperty("PACKAGES_FOUND", tmp.c_str());
  1580. tmp = cmJoin(notFoundContents, ";");
  1581. this->Makefile->GetState()->SetGlobalProperty("PACKAGES_NOT_FOUND",
  1582. tmp.c_str());
  1583. }
  1584. void cmFindPackageCommand::AppendSuccessInformation()
  1585. {
  1586. {
  1587. std::string const transitivePropName =
  1588. cmStrCat("_CMAKE_", this->Name, "_TRANSITIVE_DEPENDENCY");
  1589. this->Makefile->GetState()->SetGlobalProperty(transitivePropName, "False");
  1590. }
  1591. std::string const found = cmStrCat(this->Name, "_FOUND");
  1592. std::string const upperFound = cmSystemTools::UpperCase(found);
  1593. bool const upperResult = this->Makefile->IsOn(upperFound);
  1594. bool const result = this->Makefile->IsOn(found);
  1595. bool const packageFound = (result || upperResult);
  1596. this->AppendToFoundProperty(packageFound);
  1597. // Record whether the find was quiet or not, so this can be used
  1598. // e.g. in FeatureSummary.cmake
  1599. std::string const quietInfoPropName =
  1600. cmStrCat("_CMAKE_", this->Name, "_QUIET");
  1601. this->Makefile->GetState()->SetGlobalProperty(
  1602. quietInfoPropName, this->Quiet ? "TRUE" : "FALSE");
  1603. // set a global property to record the required version of this package
  1604. std::string const versionInfoPropName =
  1605. cmStrCat("_CMAKE_", this->Name, "_REQUIRED_VERSION");
  1606. std::string versionInfo;
  1607. if (!this->VersionRange.empty()) {
  1608. versionInfo = this->VersionRange;
  1609. } else if (!this->Version.empty()) {
  1610. versionInfo =
  1611. cmStrCat(this->VersionExact ? "==" : ">=", ' ', this->Version);
  1612. }
  1613. this->Makefile->GetState()->SetGlobalProperty(versionInfoPropName,
  1614. versionInfo.c_str());
  1615. if (this->Required) {
  1616. std::string const requiredInfoPropName =
  1617. cmStrCat("_CMAKE_", this->Name, "_TYPE");
  1618. this->Makefile->GetState()->SetGlobalProperty(requiredInfoPropName,
  1619. "REQUIRED");
  1620. }
  1621. }
  1622. void cmFindPackageCommand::PushFindPackageRootPathStack()
  1623. {
  1624. // Allocate a PACKAGE_ROOT_PATH for the current find_package call.
  1625. this->Makefile->FindPackageRootPathStack.emplace_back();
  1626. std::vector<std::string>& rootPaths =
  1627. this->Makefile->FindPackageRootPathStack.back();
  1628. // Add root paths from <PackageName>_ROOT CMake and environment variables,
  1629. // subject to CMP0074.
  1630. std::string const rootVar = this->Name + "_ROOT";
  1631. cmValue rootDef = this->Makefile->GetDefinition(rootVar);
  1632. if (rootDef && rootDef.IsEmpty()) {
  1633. rootDef = nullptr;
  1634. }
  1635. cm::optional<std::string> rootEnv = cmSystemTools::GetEnvVar(rootVar);
  1636. if (rootEnv && rootEnv->empty()) {
  1637. rootEnv = cm::nullopt;
  1638. }
  1639. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0074)) {
  1640. case cmPolicies::WARN:
  1641. this->Makefile->MaybeWarnCMP0074(rootVar, rootDef, rootEnv);
  1642. CM_FALLTHROUGH;
  1643. case cmPolicies::OLD:
  1644. // OLD behavior is to ignore the <PackageName>_ROOT variables.
  1645. return;
  1646. case cmPolicies::REQUIRED_IF_USED:
  1647. case cmPolicies::REQUIRED_ALWAYS:
  1648. this->Makefile->IssueMessage(
  1649. MessageType::FATAL_ERROR,
  1650. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0074));
  1651. return;
  1652. case cmPolicies::NEW: {
  1653. // NEW behavior is to honor the <PackageName>_ROOT variables.
  1654. } break;
  1655. }
  1656. // Add root paths from <PACKAGENAME>_ROOT CMake and environment variables,
  1657. // if they are different than <PackageName>_ROOT, and subject to CMP0144.
  1658. std::string const rootVAR = cmSystemTools::UpperCase(rootVar);
  1659. cmValue rootDEF;
  1660. cm::optional<std::string> rootENV;
  1661. if (rootVAR != rootVar) {
  1662. rootDEF = this->Makefile->GetDefinition(rootVAR);
  1663. if (rootDEF && (rootDEF.IsEmpty() || rootDEF == rootDef)) {
  1664. rootDEF = nullptr;
  1665. }
  1666. rootENV = cmSystemTools::GetEnvVar(rootVAR);
  1667. if (rootENV && (rootENV->empty() || rootENV == rootEnv)) {
  1668. rootENV = cm::nullopt;
  1669. }
  1670. }
  1671. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0144)) {
  1672. case cmPolicies::WARN:
  1673. this->Makefile->MaybeWarnCMP0144(rootVAR, rootDEF, rootENV);
  1674. CM_FALLTHROUGH;
  1675. case cmPolicies::OLD:
  1676. // OLD behavior is to ignore the <PACKAGENAME>_ROOT variables.
  1677. rootDEF = nullptr;
  1678. rootENV = cm::nullopt;
  1679. break;
  1680. case cmPolicies::REQUIRED_IF_USED:
  1681. case cmPolicies::REQUIRED_ALWAYS:
  1682. this->Makefile->IssueMessage(
  1683. MessageType::FATAL_ERROR,
  1684. cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0144));
  1685. return;
  1686. case cmPolicies::NEW: {
  1687. // NEW behavior is to honor the <PACKAGENAME>_ROOT variables.
  1688. } break;
  1689. }
  1690. if (rootDef) {
  1691. cmExpandList(*rootDef, rootPaths);
  1692. }
  1693. if (rootDEF) {
  1694. cmExpandList(*rootDEF, rootPaths);
  1695. }
  1696. if (rootEnv) {
  1697. std::vector<std::string> p = cmSystemTools::SplitEnvPath(*rootEnv);
  1698. std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
  1699. }
  1700. if (rootENV) {
  1701. std::vector<std::string> p = cmSystemTools::SplitEnvPath(*rootENV);
  1702. std::move(p.begin(), p.end(), std::back_inserter(rootPaths));
  1703. }
  1704. }
  1705. void cmFindPackageCommand::PopFindPackageRootPathStack()
  1706. {
  1707. this->Makefile->FindPackageRootPathStack.pop_back();
  1708. }
  1709. void cmFindPackageCommand::ComputePrefixes()
  1710. {
  1711. this->FillPrefixesPackageRedirect();
  1712. if (!this->NoDefaultPath) {
  1713. if (!this->NoPackageRootPath) {
  1714. this->FillPrefixesPackageRoot();
  1715. }
  1716. if (!this->NoCMakePath) {
  1717. this->FillPrefixesCMakeVariable();
  1718. }
  1719. if (!this->NoCMakeEnvironmentPath) {
  1720. this->FillPrefixesCMakeEnvironment();
  1721. }
  1722. }
  1723. this->FillPrefixesUserHints();
  1724. if (!this->NoDefaultPath) {
  1725. if (!this->NoSystemEnvironmentPath) {
  1726. this->FillPrefixesSystemEnvironment();
  1727. }
  1728. if (!this->NoUserRegistry) {
  1729. this->FillPrefixesUserRegistry();
  1730. }
  1731. if (!this->NoCMakeSystemPath) {
  1732. this->FillPrefixesCMakeSystemVariable();
  1733. }
  1734. if (!this->NoSystemRegistry) {
  1735. this->FillPrefixesSystemRegistry();
  1736. }
  1737. }
  1738. this->FillPrefixesUserGuess();
  1739. this->ComputeFinalPaths(IgnorePaths::No);
  1740. }
  1741. void cmFindPackageCommand::FillPrefixesPackageRedirect()
  1742. {
  1743. cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRedirect];
  1744. const auto redirectDir =
  1745. this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_REDIRECTS_DIR");
  1746. if (redirectDir && !redirectDir->empty()) {
  1747. paths.AddPath(*redirectDir);
  1748. }
  1749. if (this->DebugMode) {
  1750. std::string debugBuffer =
  1751. "The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.\n";
  1752. collectPathsForDebug(debugBuffer, paths);
  1753. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1754. }
  1755. }
  1756. void cmFindPackageCommand::FillPrefixesPackageRoot()
  1757. {
  1758. cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
  1759. // Add the PACKAGE_ROOT_PATH from each enclosing find_package call.
  1760. for (auto pkgPaths = this->Makefile->FindPackageRootPathStack.rbegin();
  1761. pkgPaths != this->Makefile->FindPackageRootPathStack.rend();
  1762. ++pkgPaths) {
  1763. for (std::string const& path : *pkgPaths) {
  1764. paths.AddPath(path);
  1765. }
  1766. }
  1767. if (this->DebugMode) {
  1768. std::string debugBuffer = "<PackageName>_ROOT CMake variable "
  1769. "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n";
  1770. collectPathsForDebug(debugBuffer, paths);
  1771. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1772. }
  1773. }
  1774. void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
  1775. {
  1776. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
  1777. std::string debugBuffer;
  1778. std::size_t debugOffset = 0;
  1779. // Check the environment variable with the same name as the cache
  1780. // entry.
  1781. paths.AddEnvPath(this->Variable);
  1782. if (this->DebugMode) {
  1783. debugBuffer = cmStrCat("Env variable ", this->Variable,
  1784. " [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
  1785. debugOffset = collectPathsForDebug(debugBuffer, paths);
  1786. }
  1787. // And now the general CMake environment variables
  1788. paths.AddEnvPath("CMAKE_PREFIX_PATH");
  1789. if (this->DebugMode) {
  1790. debugBuffer = cmStrCat(debugBuffer,
  1791. "CMAKE_PREFIX_PATH env variable "
  1792. "[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
  1793. debugOffset = collectPathsForDebug(debugBuffer, paths, debugOffset);
  1794. }
  1795. paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
  1796. paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
  1797. if (this->DebugMode) {
  1798. debugBuffer =
  1799. cmStrCat(debugBuffer,
  1800. "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env "
  1801. "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
  1802. collectPathsForDebug(debugBuffer, paths, debugOffset);
  1803. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1804. }
  1805. }
  1806. void cmFindPackageCommand::FillPrefixesCMakeVariable()
  1807. {
  1808. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
  1809. std::string debugBuffer;
  1810. std::size_t debugOffset = 0;
  1811. paths.AddCMakePath("CMAKE_PREFIX_PATH");
  1812. if (this->DebugMode) {
  1813. debugBuffer = "CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].\n";
  1814. debugOffset = collectPathsForDebug(debugBuffer, paths);
  1815. }
  1816. paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
  1817. paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
  1818. if (this->DebugMode) {
  1819. debugBuffer =
  1820. cmStrCat(debugBuffer,
  1821. "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables "
  1822. "[CMAKE_FIND_USE_CMAKE_PATH].\n");
  1823. collectPathsForDebug(debugBuffer, paths, debugOffset);
  1824. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1825. }
  1826. }
  1827. void cmFindPackageCommand::FillPrefixesSystemEnvironment()
  1828. {
  1829. cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemEnvironment];
  1830. // Use the system search path to generate prefixes.
  1831. // Relative paths are interpreted with respect to the current
  1832. // working directory.
  1833. std::vector<std::string> tmp;
  1834. cmSystemTools::GetPath(tmp);
  1835. for (std::string const& i : tmp) {
  1836. // If the path is a PREFIX/bin case then add its parent instead.
  1837. if ((cmHasLiteralSuffix(i, "/bin")) || (cmHasLiteralSuffix(i, "/sbin"))) {
  1838. paths.AddPath(cmSystemTools::GetFilenamePath(i));
  1839. } else {
  1840. paths.AddPath(i);
  1841. }
  1842. }
  1843. if (this->DebugMode) {
  1844. std::string debugBuffer = "Standard system environment variables "
  1845. "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n";
  1846. collectPathsForDebug(debugBuffer, paths);
  1847. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1848. }
  1849. }
  1850. void cmFindPackageCommand::FillPrefixesUserRegistry()
  1851. {
  1852. #if defined(_WIN32) && !defined(__CYGWIN__)
  1853. this->LoadPackageRegistryWinUser();
  1854. #elif defined(__HAIKU__)
  1855. char dir[B_PATH_NAME_LENGTH];
  1856. if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  1857. B_OK) {
  1858. std::string fname = cmStrCat(dir, "/cmake/packages/", Name);
  1859. this->LoadPackageRegistryDir(fname,
  1860. this->LabeledPaths[PathLabel::UserRegistry]);
  1861. }
  1862. #else
  1863. std::string dir;
  1864. if (cmSystemTools::GetEnv("HOME", dir)) {
  1865. dir += "/.cmake/packages/";
  1866. dir += this->Name;
  1867. this->LoadPackageRegistryDir(dir,
  1868. this->LabeledPaths[PathLabel::UserRegistry]);
  1869. }
  1870. #endif
  1871. if (this->DebugMode) {
  1872. std::string debugBuffer =
  1873. "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n";
  1874. collectPathsForDebug(debugBuffer,
  1875. this->LabeledPaths[PathLabel::UserRegistry]);
  1876. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1877. }
  1878. }
  1879. void cmFindPackageCommand::FillPrefixesSystemRegistry()
  1880. {
  1881. if (this->NoSystemRegistry || this->NoDefaultPath) {
  1882. return;
  1883. }
  1884. #if defined(_WIN32) && !defined(__CYGWIN__)
  1885. this->LoadPackageRegistryWinSystem();
  1886. #endif
  1887. if (this->DebugMode) {
  1888. std::string debugBuffer =
  1889. "CMake System Package Registry "
  1890. "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n";
  1891. collectPathsForDebug(debugBuffer,
  1892. this->LabeledPaths[PathLabel::SystemRegistry]);
  1893. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  1894. }
  1895. }
  1896. #if defined(_WIN32) && !defined(__CYGWIN__)
  1897. void cmFindPackageCommand::LoadPackageRegistryWinUser()
  1898. {
  1899. // HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
  1900. this->LoadPackageRegistryWin(true, 0,
  1901. this->LabeledPaths[PathLabel::UserRegistry]);
  1902. }
  1903. void cmFindPackageCommand::LoadPackageRegistryWinSystem()
  1904. {
  1905. cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemRegistry];
  1906. // HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
  1907. // Prefer the target platform view first.
  1908. if (this->Makefile->PlatformIs64Bit()) {
  1909. this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
  1910. this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
  1911. } else {
  1912. this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
  1913. this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
  1914. }
  1915. }
  1916. void cmFindPackageCommand::LoadPackageRegistryWin(const bool user,
  1917. const unsigned int view,
  1918. cmSearchPath& outPaths)
  1919. {
  1920. std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
  1921. key += cmsys::Encoding::ToWide(this->Name);
  1922. std::set<std::wstring> bad;
  1923. HKEY hKey;
  1924. if (RegOpenKeyExW(user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
  1925. 0, KEY_QUERY_VALUE | view, &hKey) == ERROR_SUCCESS) {
  1926. DWORD valueType = REG_NONE;
  1927. wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
  1928. std::vector<wchar_t> data(512);
  1929. bool done = false;
  1930. DWORD index = 0;
  1931. while (!done) {
  1932. DWORD nameSize = static_cast<DWORD>(sizeof(name));
  1933. DWORD dataSize = static_cast<DWORD>(data.size() * sizeof(data[0]));
  1934. switch (RegEnumValueW(hKey, index, name, &nameSize, 0, &valueType,
  1935. (BYTE*)&data[0], &dataSize)) {
  1936. case ERROR_SUCCESS:
  1937. ++index;
  1938. if (valueType == REG_SZ) {
  1939. data[dataSize] = 0;
  1940. if (!this->CheckPackageRegistryEntry(
  1941. cmsys::Encoding::ToNarrow(&data[0]), outPaths)) {
  1942. // The entry is invalid.
  1943. bad.insert(name);
  1944. }
  1945. }
  1946. break;
  1947. case ERROR_MORE_DATA:
  1948. data.resize((dataSize + sizeof(data[0]) - 1) / sizeof(data[0]));
  1949. break;
  1950. case ERROR_NO_MORE_ITEMS:
  1951. default:
  1952. done = true;
  1953. break;
  1954. }
  1955. }
  1956. RegCloseKey(hKey);
  1957. }
  1958. // Remove bad values if possible.
  1959. if (user && !bad.empty() &&
  1960. RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(), 0, KEY_SET_VALUE | view,
  1961. &hKey) == ERROR_SUCCESS) {
  1962. for (std::wstring const& v : bad) {
  1963. RegDeleteValueW(hKey, v.c_str());
  1964. }
  1965. RegCloseKey(hKey);
  1966. }
  1967. }
  1968. #else
  1969. void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,
  1970. cmSearchPath& outPaths)
  1971. {
  1972. cmsys::Directory files;
  1973. if (!files.Load(dir)) {
  1974. return;
  1975. }
  1976. std::string fname;
  1977. for (unsigned long i = 0; i < files.GetNumberOfFiles(); ++i) {
  1978. fname = cmStrCat(dir, '/', files.GetFile(i));
  1979. if (!cmSystemTools::FileIsDirectory(fname)) {
  1980. // Hold this file hostage until it behaves.
  1981. cmFindPackageCommandHoldFile holdFile(fname.c_str());
  1982. // Load the file.
  1983. cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
  1984. std::string fentry;
  1985. if (fin && cmSystemTools::GetLineFromStream(fin, fentry) &&
  1986. this->CheckPackageRegistryEntry(fentry, outPaths)) {
  1987. // The file references an existing package, so release it.
  1988. holdFile.Release();
  1989. }
  1990. }
  1991. }
  1992. // TODO: Wipe out the directory if it is empty.
  1993. }
  1994. #endif
  1995. bool cmFindPackageCommand::CheckPackageRegistryEntry(const std::string& fname,
  1996. cmSearchPath& outPaths)
  1997. {
  1998. // Parse the content of one package registry entry.
  1999. if (cmSystemTools::FileIsFullPath(fname)) {
  2000. // The first line in the stream is the full path to a file or
  2001. // directory containing the package.
  2002. if (cmSystemTools::FileExists(fname)) {
  2003. // The path exists. Look for the package here.
  2004. if (!cmSystemTools::FileIsDirectory(fname)) {
  2005. outPaths.AddPath(cmSystemTools::GetFilenamePath(fname));
  2006. } else {
  2007. outPaths.AddPath(fname);
  2008. }
  2009. return true;
  2010. }
  2011. // The path does not exist. Assume the stream content is
  2012. // associated with an old package that no longer exists, and
  2013. // delete it to keep the package registry clean.
  2014. return false;
  2015. }
  2016. // The first line in the stream is not the full path to a file or
  2017. // directory. Assume the stream content was created by a future
  2018. // version of CMake that uses a different format, and leave it.
  2019. return true;
  2020. }
  2021. void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
  2022. {
  2023. cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem];
  2024. const bool install_prefix_in_list =
  2025. !this->Makefile->IsOn("CMAKE_FIND_NO_INSTALL_PREFIX");
  2026. const bool remove_install_prefix = this->NoCMakeInstallPath;
  2027. const bool add_install_prefix = !this->NoCMakeInstallPath &&
  2028. this->Makefile->IsDefinitionSet("CMAKE_FIND_USE_INSTALL_PREFIX");
  2029. // We have 3 possible states for `CMAKE_SYSTEM_PREFIX_PATH` and
  2030. // `CMAKE_INSTALL_PREFIX`.
  2031. // Either we need to remove `CMAKE_INSTALL_PREFIX`, add
  2032. // `CMAKE_INSTALL_PREFIX`, or do nothing.
  2033. //
  2034. // When we need to remove `CMAKE_INSTALL_PREFIX` we remove the Nth occurrence
  2035. // of `CMAKE_INSTALL_PREFIX` from `CMAKE_SYSTEM_PREFIX_PATH`, where `N` is
  2036. // computed by `CMakeSystemSpecificInformation.cmake` while constructing
  2037. // `CMAKE_SYSTEM_PREFIX_PATH`. This ensures that if projects / toolchains
  2038. // have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove
  2039. // some other entry by mistake
  2040. long install_prefix_count = -1;
  2041. std::string install_path_to_remove;
  2042. if (cmValue to_skip = this->Makefile->GetDefinition(
  2043. "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT")) {
  2044. cmStrToLong(*to_skip, &install_prefix_count);
  2045. }
  2046. if (cmValue install_value = this->Makefile->GetDefinition(
  2047. "_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE")) {
  2048. install_path_to_remove = *install_value;
  2049. }
  2050. if (remove_install_prefix && install_prefix_in_list &&
  2051. install_prefix_count > 0 && !install_path_to_remove.empty()) {
  2052. cmValue prefix_paths =
  2053. this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH");
  2054. // remove entry from CMAKE_SYSTEM_PREFIX_PATH
  2055. std::vector<std::string> expanded = cmExpandedList(*prefix_paths);
  2056. long count = 0;
  2057. for (const auto& path : expanded) {
  2058. bool const to_add =
  2059. !(path == install_path_to_remove && ++count == install_prefix_count);
  2060. if (to_add) {
  2061. paths.AddPath(path);
  2062. }
  2063. }
  2064. } else if (add_install_prefix && !install_prefix_in_list) {
  2065. paths.AddCMakePath("CMAKE_INSTALL_PREFIX");
  2066. paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
  2067. } else {
  2068. // Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct
  2069. paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
  2070. }
  2071. paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
  2072. paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
  2073. if (this->DebugMode) {
  2074. std::string debugBuffer = "CMake variables defined in the Platform file "
  2075. "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n";
  2076. collectPathsForDebug(debugBuffer, paths);
  2077. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  2078. }
  2079. }
  2080. void cmFindPackageCommand::FillPrefixesUserGuess()
  2081. {
  2082. cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
  2083. for (std::string const& p : this->UserGuessArgs) {
  2084. paths.AddUserPath(p);
  2085. }
  2086. if (this->DebugMode) {
  2087. std::string debugBuffer =
  2088. "Paths specified by the find_package PATHS option.\n";
  2089. collectPathsForDebug(debugBuffer, paths);
  2090. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  2091. }
  2092. }
  2093. void cmFindPackageCommand::FillPrefixesUserHints()
  2094. {
  2095. cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
  2096. for (std::string const& p : this->UserHintsArgs) {
  2097. paths.AddUserPath(p);
  2098. }
  2099. if (this->DebugMode) {
  2100. std::string debugBuffer =
  2101. "Paths specified by the find_package HINTS option.\n";
  2102. collectPathsForDebug(debugBuffer, paths);
  2103. this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer);
  2104. }
  2105. }
  2106. bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
  2107. {
  2108. assert(!dir.empty() && dir.back() == '/');
  2109. // Check each path suffix on this directory.
  2110. for (std::string const& s : this->SearchPathSuffixes) {
  2111. std::string d = dir;
  2112. if (!s.empty()) {
  2113. d += s;
  2114. d += '/';
  2115. }
  2116. if (this->CheckDirectory(d)) {
  2117. return true;
  2118. }
  2119. }
  2120. return false;
  2121. }
  2122. bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
  2123. {
  2124. assert(!dir.empty() && dir.back() == '/');
  2125. // Look for the file in this directory.
  2126. std::string const d = dir.substr(0, dir.size() - 1);
  2127. if (this->FindConfigFile(d, this->FileFound)) {
  2128. // Remove duplicate slashes.
  2129. cmSystemTools::ConvertToUnixSlashes(this->FileFound);
  2130. return true;
  2131. }
  2132. return false;
  2133. }
  2134. bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
  2135. std::string& file)
  2136. {
  2137. if (this->IgnoredPaths.count(dir)) {
  2138. return false;
  2139. }
  2140. for (std::string const& c : this->Configs) {
  2141. file = cmStrCat(dir, '/', c);
  2142. if (this->DebugMode) {
  2143. this->DebugBuffer = cmStrCat(this->DebugBuffer, " ", file, "\n");
  2144. }
  2145. if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) {
  2146. // Allow resolving symlinks when the config file is found through a link
  2147. if (this->UseRealPath) {
  2148. file = cmSystemTools::GetRealPath(file);
  2149. }
  2150. return true;
  2151. }
  2152. }
  2153. return false;
  2154. }
  2155. bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
  2156. {
  2157. bool result = false; // by default, assume the version is not ok.
  2158. bool haveResult = false;
  2159. std::string version = "unknown";
  2160. // Get the filename without the .cmake extension.
  2161. std::string::size_type pos = config_file.rfind('.');
  2162. std::string version_file_base = config_file.substr(0, pos);
  2163. // Look for foo-config-version.cmake
  2164. std::string version_file = cmStrCat(version_file_base, "-version.cmake");
  2165. if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
  2166. result = this->CheckVersionFile(version_file, version);
  2167. haveResult = true;
  2168. }
  2169. // Look for fooConfigVersion.cmake
  2170. version_file = cmStrCat(version_file_base, "Version.cmake");
  2171. if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
  2172. result = this->CheckVersionFile(version_file, version);
  2173. haveResult = true;
  2174. }
  2175. // If no version was requested a versionless package is acceptable.
  2176. if (!haveResult && this->Version.empty()) {
  2177. result = true;
  2178. }
  2179. ConfigFileInfo configFileInfo;
  2180. configFileInfo.filename = config_file;
  2181. configFileInfo.version = version;
  2182. this->ConsideredConfigs.push_back(std::move(configFileInfo));
  2183. return result;
  2184. }
  2185. bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
  2186. std::string& result_version)
  2187. {
  2188. // The version file will be loaded in an isolated scope.
  2189. cmMakefile::ScopePushPop const varScope(this->Makefile);
  2190. cmMakefile::PolicyPushPop const polScope(this->Makefile);
  2191. static_cast<void>(varScope);
  2192. static_cast<void>(polScope);
  2193. // Clear the output variables.
  2194. this->Makefile->RemoveDefinition("PACKAGE_VERSION");
  2195. this->Makefile->RemoveDefinition("PACKAGE_VERSION_UNSUITABLE");
  2196. this->Makefile->RemoveDefinition("PACKAGE_VERSION_COMPATIBLE");
  2197. this->Makefile->RemoveDefinition("PACKAGE_VERSION_EXACT");
  2198. // Set the input variables.
  2199. this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name);
  2200. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COMPLETE",
  2201. this->VersionComplete);
  2202. auto addDefinition = [this](const std::string& variable,
  2203. cm::string_view value) {
  2204. this->Makefile->AddDefinition(variable, value);
  2205. };
  2206. this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION",
  2207. this->Version, this->VersionCount,
  2208. this->VersionMajor, this->VersionMinor,
  2209. this->VersionPatch, this->VersionTweak);
  2210. if (!this->VersionRange.empty()) {
  2211. this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MIN",
  2212. this->Version, this->VersionCount,
  2213. this->VersionMajor, this->VersionMinor,
  2214. this->VersionPatch, this->VersionTweak);
  2215. this->SetVersionVariables(addDefinition, "PACKAGE_FIND_VERSION_MAX",
  2216. this->VersionMax, this->VersionMaxCount,
  2217. this->VersionMaxMajor, this->VersionMaxMinor,
  2218. this->VersionMaxPatch, this->VersionMaxTweak);
  2219. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE",
  2220. this->VersionComplete);
  2221. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MIN",
  2222. this->VersionRangeMin);
  2223. this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_RANGE_MAX",
  2224. this->VersionRangeMax);
  2225. }
  2226. // Load the version check file. Pass NoPolicyScope because we do
  2227. // our own policy push/pop independent of CMP0011.
  2228. bool suitable = false;
  2229. if (this->ReadListFile(version_file, NoPolicyScope)) {
  2230. // Check the output variables.
  2231. bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
  2232. bool const unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
  2233. if (!okay && !this->VersionExact) {
  2234. okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
  2235. }
  2236. // The package is suitable if the version is okay and not
  2237. // explicitly unsuitable.
  2238. suitable = !unsuitable && (okay || this->Version.empty());
  2239. if (suitable) {
  2240. // Get the version found.
  2241. this->VersionFound =
  2242. this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
  2243. // Try to parse the version number and store the results that were
  2244. // successfully parsed.
  2245. unsigned int parsed_major;
  2246. unsigned int parsed_minor;
  2247. unsigned int parsed_patch;
  2248. unsigned int parsed_tweak;
  2249. this->VersionFoundCount =
  2250. parseVersion(this->VersionFound, parsed_major, parsed_minor,
  2251. parsed_patch, parsed_tweak);
  2252. switch (this->VersionFoundCount) {
  2253. case 4:
  2254. this->VersionFoundTweak = parsed_tweak;
  2255. CM_FALLTHROUGH;
  2256. case 3:
  2257. this->VersionFoundPatch = parsed_patch;
  2258. CM_FALLTHROUGH;
  2259. case 2:
  2260. this->VersionFoundMinor = parsed_minor;
  2261. CM_FALLTHROUGH;
  2262. case 1:
  2263. this->VersionFoundMajor = parsed_major;
  2264. CM_FALLTHROUGH;
  2265. default:
  2266. break;
  2267. }
  2268. }
  2269. }
  2270. result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
  2271. if (result_version.empty()) {
  2272. result_version = "unknown";
  2273. }
  2274. // Succeed if the version is suitable.
  2275. return suitable;
  2276. }
  2277. void cmFindPackageCommand::StoreVersionFound()
  2278. {
  2279. // Store the whole version string.
  2280. std::string const ver = cmStrCat(this->Name, "_VERSION");
  2281. auto addDefinition = [this](const std::string& variable,
  2282. cm::string_view value) {
  2283. this->Makefile->AddDefinition(variable, value);
  2284. };
  2285. this->SetVersionVariables(addDefinition, ver, this->VersionFound,
  2286. this->VersionFoundCount, this->VersionFoundMajor,
  2287. this->VersionFoundMinor, this->VersionFoundPatch,
  2288. this->VersionFoundTweak);
  2289. if (this->VersionFound.empty()) {
  2290. this->Makefile->RemoveDefinition(ver);
  2291. }
  2292. }
  2293. bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
  2294. {
  2295. assert(!prefix_in.empty() && prefix_in.back() == '/');
  2296. // Skip this if the prefix does not exist.
  2297. if (!cmSystemTools::FileIsDirectory(prefix_in)) {
  2298. return false;
  2299. }
  2300. // Skip this if it's in ignored paths.
  2301. std::string prefixWithoutSlash = prefix_in;
  2302. if (prefixWithoutSlash != "/" && prefixWithoutSlash.back() == '/') {
  2303. prefixWithoutSlash.erase(prefixWithoutSlash.length() - 1);
  2304. }
  2305. if (this->IgnoredPaths.count(prefixWithoutSlash) ||
  2306. this->IgnoredPrefixPaths.count(prefixWithoutSlash)) {
  2307. return false;
  2308. }
  2309. // PREFIX/ (useful on windows or in build trees)
  2310. if (this->SearchDirectory(prefix_in)) {
  2311. return true;
  2312. }
  2313. // Strip the trailing slash because the path generator is about to
  2314. // add one.
  2315. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1);
  2316. auto searchFn = [this](const std::string& fullPath) -> bool {
  2317. return this->SearchDirectory(fullPath);
  2318. };
  2319. auto iCMakeGen = cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s };
  2320. auto firstPkgDirGen =
  2321. cmProjectDirectoryListGenerator{ this->Names, this->SortOrder,
  2322. this->SortDirection };
  2323. // PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
  2324. if (TryGeneratedPaths(searchFn, prefix, iCMakeGen)) {
  2325. return true;
  2326. }
  2327. // PREFIX/(Foo|foo|FOO).*/
  2328. if (TryGeneratedPaths(searchFn, prefix, firstPkgDirGen)) {
  2329. return true;
  2330. }
  2331. // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
  2332. if (TryGeneratedPaths(searchFn, prefix, firstPkgDirGen, iCMakeGen)) {
  2333. return true;
  2334. }
  2335. auto secondPkgDirGen =
  2336. cmProjectDirectoryListGenerator{ this->Names, this->SortOrder,
  2337. this->SortDirection };
  2338. // PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/(Foo|foo|FOO).*/
  2339. if (TryGeneratedPaths(searchFn, prefix, firstPkgDirGen, iCMakeGen,
  2340. secondPkgDirGen)) {
  2341. return true;
  2342. }
  2343. // Construct list of common install locations (lib and share).
  2344. std::vector<cm::string_view> common;
  2345. std::string libArch;
  2346. if (!this->LibraryArchitecture.empty()) {
  2347. libArch = "lib/" + this->LibraryArchitecture;
  2348. common.emplace_back(libArch);
  2349. }
  2350. if (this->UseLib32Paths) {
  2351. common.emplace_back("lib32"_s);
  2352. }
  2353. if (this->UseLib64Paths) {
  2354. common.emplace_back("lib64"_s);
  2355. }
  2356. if (this->UseLibx32Paths) {
  2357. common.emplace_back("libx32"_s);
  2358. }
  2359. common.emplace_back("lib"_s);
  2360. common.emplace_back("share"_s);
  2361. auto cmnGen = cmEnumPathSegmentsGenerator{ common };
  2362. auto cmakeGen = cmAppendPathSegmentGenerator{ "cmake"_s };
  2363. // PREFIX/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
  2364. if (TryGeneratedPaths(searchFn, prefix, cmnGen, cmakeGen, firstPkgDirGen)) {
  2365. return true;
  2366. }
  2367. // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
  2368. if (TryGeneratedPaths(searchFn, prefix, cmnGen, firstPkgDirGen)) {
  2369. return true;
  2370. }
  2371. // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
  2372. if (TryGeneratedPaths(searchFn, prefix, cmnGen, firstPkgDirGen, iCMakeGen)) {
  2373. return true;
  2374. }
  2375. // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
  2376. if (TryGeneratedPaths(searchFn, prefix, firstPkgDirGen, cmnGen, cmakeGen,
  2377. secondPkgDirGen)) {
  2378. return true;
  2379. }
  2380. // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
  2381. if (TryGeneratedPaths(searchFn, prefix, firstPkgDirGen, cmnGen,
  2382. secondPkgDirGen)) {
  2383. return true;
  2384. }
  2385. // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
  2386. return TryGeneratedPaths(searchFn, prefix, firstPkgDirGen, cmnGen,
  2387. secondPkgDirGen, iCMakeGen);
  2388. }
  2389. bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
  2390. {
  2391. assert(!prefix_in.empty() && prefix_in.back() == '/');
  2392. // Strip the trailing slash because the path generator is about to
  2393. // add one.
  2394. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1);
  2395. auto searchFn = [this](const std::string& fullPath) -> bool {
  2396. return this->SearchDirectory(fullPath);
  2397. };
  2398. auto iCMakeGen = cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s };
  2399. auto fwGen =
  2400. cmMacProjectDirectoryListGenerator{ this->Names, ".framework"_s };
  2401. auto rGen = cmAppendPathSegmentGenerator{ "Resources"_s };
  2402. auto vGen = cmAppendPathSegmentGenerator{ "Versions"_s };
  2403. auto grGen = cmFileListGeneratorGlob{ "/*/Resources"_s };
  2404. // <prefix>/Foo.framework/Resources/
  2405. if (TryGeneratedPaths(searchFn, prefix, fwGen, rGen)) {
  2406. return true;
  2407. }
  2408. // <prefix>/Foo.framework/Resources/CMake/
  2409. if (TryGeneratedPaths(searchFn, prefix, fwGen, rGen, iCMakeGen)) {
  2410. return true;
  2411. }
  2412. // <prefix>/Foo.framework/Versions/*/Resources/
  2413. if (TryGeneratedPaths(searchFn, prefix, fwGen, vGen, grGen)) {
  2414. return true;
  2415. }
  2416. // <prefix>/Foo.framework/Versions/*/Resources/CMake/
  2417. return TryGeneratedPaths(searchFn, prefix, fwGen, vGen, grGen, iCMakeGen);
  2418. }
  2419. bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
  2420. {
  2421. assert(!prefix_in.empty() && prefix_in.back() == '/');
  2422. // Strip the trailing slash because the path generator is about to
  2423. // add one.
  2424. std::string const prefix = prefix_in.substr(0, prefix_in.size() - 1);
  2425. auto searchFn = [this](const std::string& fullPath) -> bool {
  2426. return this->SearchDirectory(fullPath);
  2427. };
  2428. auto appGen = cmMacProjectDirectoryListGenerator{ this->Names, ".app"_s };
  2429. auto crGen = cmAppendPathSegmentGenerator{ "Contents/Resources"_s };
  2430. // <prefix>/Foo.app/Contents/Resources
  2431. if (TryGeneratedPaths(searchFn, prefix, appGen, crGen)) {
  2432. return true;
  2433. }
  2434. // <prefix>/Foo.app/Contents/Resources/CMake
  2435. return TryGeneratedPaths(
  2436. searchFn, prefix, appGen, crGen,
  2437. cmCaseInsensitiveDirectoryListGenerator{ "cmake"_s });
  2438. }
  2439. // TODO: Debug cmsys::Glob double slash problem.
  2440. bool cmFindPackage(std::vector<std::string> const& args,
  2441. cmExecutionStatus& status)
  2442. {
  2443. return cmFindPackageCommand(status).InitialPass(args);
  2444. }