cmFindLibraryCommand.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmFindLibraryCommand.h"
  4. #include <algorithm>
  5. #include <cctype>
  6. #include <cstdio>
  7. #include <cstring>
  8. #include <set>
  9. #include <utility>
  10. #include <cm/optional>
  11. #include "cmsys/RegularExpression.hxx"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmList.h"
  14. #include "cmMakefile.h"
  15. #include "cmState.h"
  16. #include "cmStateTypes.h"
  17. #include "cmStringAlgorithms.h"
  18. #include "cmSystemTools.h"
  19. #include "cmValue.h"
  20. class cmExecutionStatus;
  21. cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status)
  22. : cmFindBase("find_library", status)
  23. {
  24. this->EnvironmentPath = "LIB";
  25. this->NamesPerDirAllowed = true;
  26. this->VariableDocumentation = "Path to a library.";
  27. this->VariableType = cmStateEnums::FILEPATH;
  28. }
  29. // cmFindLibraryCommand
  30. bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
  31. {
  32. this->CMakePathName = "LIBRARY";
  33. if (!this->ParseArguments(argsIn)) {
  34. return false;
  35. }
  36. this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
  37. if (this->IsFound()) {
  38. this->NormalizeFindResult();
  39. return true;
  40. }
  41. // add custom lib<qual> paths instead of using fixed lib32, lib64 or
  42. // libx32
  43. if (cmValue customLib = this->Makefile->GetDefinition(
  44. "CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX")) {
  45. this->AddArchitecturePaths(customLib->c_str());
  46. }
  47. // add special 32 bit paths if this is a 32 bit compile.
  48. else if (this->Makefile->PlatformIs32Bit() &&
  49. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  50. "FIND_LIBRARY_USE_LIB32_PATHS")) {
  51. this->AddArchitecturePaths("32");
  52. }
  53. // add special 64 bit paths if this is a 64 bit compile.
  54. else if (this->Makefile->PlatformIs64Bit() &&
  55. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  56. "FIND_LIBRARY_USE_LIB64_PATHS")) {
  57. this->AddArchitecturePaths("64");
  58. }
  59. // add special 32 bit paths if this is an x32 compile.
  60. else if (this->Makefile->PlatformIsx32() &&
  61. this->Makefile->GetState()->GetGlobalPropertyAsBool(
  62. "FIND_LIBRARY_USE_LIBX32_PATHS")) {
  63. this->AddArchitecturePaths("x32");
  64. }
  65. std::string const library = this->FindLibrary();
  66. this->StoreFindResult(library);
  67. return true;
  68. }
  69. void cmFindLibraryCommand::AddArchitecturePaths(char const* suffix)
  70. {
  71. std::vector<std::string> original;
  72. original.swap(this->SearchPaths);
  73. for (std::string const& o : original) {
  74. this->AddArchitecturePath(o, 0, suffix);
  75. if (this->DebugMode) {
  76. std::string msg = cmStrCat(
  77. "find_library(", this->VariableName, ") removed original suffix ", o,
  78. " from PATH_SUFFIXES while adding architecture paths for suffix '",
  79. suffix, "'");
  80. this->DebugMessage(msg);
  81. }
  82. }
  83. }
  84. static bool cmLibDirsLinked(std::string const& l, std::string const& r)
  85. {
  86. // Compare the real paths of the two directories.
  87. // Since our caller only changed the trailing component of each
  88. // directory, the real paths can be the same only if at least one of
  89. // the trailing components is a symlink. Use this as an optimization
  90. // to avoid excessive realpath calls.
  91. return (cmSystemTools::FileIsSymlink(l) ||
  92. cmSystemTools::FileIsSymlink(r)) &&
  93. cmSystemTools::GetRealPath(l) == cmSystemTools::GetRealPath(r);
  94. }
  95. void cmFindLibraryCommand::AddArchitecturePath(
  96. std::string const& dir, std::string::size_type start_pos, char const* suffix,
  97. bool fresh)
  98. {
  99. std::string::size_type pos = dir.find("lib/", start_pos);
  100. if (pos != std::string::npos) {
  101. // Check for "lib".
  102. std::string lib = dir.substr(0, pos + 3);
  103. bool use_lib = cmSystemTools::FileIsDirectory(lib);
  104. // Check for "lib<suffix>" and use it first.
  105. std::string libX = lib + suffix;
  106. bool use_libX = cmSystemTools::FileIsDirectory(libX);
  107. // Avoid copies of the same directory due to symlinks.
  108. if (use_libX && use_lib && cmLibDirsLinked(libX, lib)) {
  109. use_libX = false;
  110. }
  111. if (use_libX) {
  112. libX += dir.substr(pos + 3);
  113. std::string::size_type libX_pos = pos + 3 + strlen(suffix) + 1;
  114. this->AddArchitecturePath(libX, libX_pos, suffix);
  115. }
  116. if (use_lib) {
  117. this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false);
  118. }
  119. }
  120. if (fresh) {
  121. // Check for the original unchanged path.
  122. bool use_dir = cmSystemTools::FileIsDirectory(dir);
  123. // Check for <dir><suffix>/ and use it first.
  124. std::string dirX = dir + suffix;
  125. bool use_dirX = cmSystemTools::FileIsDirectory(dirX);
  126. // Avoid copies of the same directory due to symlinks.
  127. if (use_dirX && use_dir && cmLibDirsLinked(dirX, dir)) {
  128. use_dirX = false;
  129. }
  130. if (use_dirX) {
  131. dirX += "/";
  132. if (this->DebugMode) {
  133. std::string msg = cmStrCat(
  134. "find_library(", this->VariableName, ") added replacement path ",
  135. dirX, " to PATH_SUFFIXES for architecture suffix '", suffix, "'");
  136. this->DebugMessage(msg);
  137. }
  138. this->SearchPaths.push_back(std::move(dirX));
  139. }
  140. if (use_dir) {
  141. this->SearchPaths.push_back(dir);
  142. if (this->DebugMode) {
  143. std::string msg = cmStrCat(
  144. "find_library(", this->VariableName, ") added replacement path ",
  145. dir, " to PATH_SUFFIXES for architecture suffix '", suffix, "'");
  146. this->DebugMessage(msg);
  147. }
  148. }
  149. }
  150. }
  151. std::string cmFindLibraryCommand::FindLibrary()
  152. {
  153. std::string library;
  154. if (this->SearchFrameworkFirst || this->SearchFrameworkOnly) {
  155. library = this->FindFrameworkLibrary();
  156. }
  157. if (library.empty() && !this->SearchFrameworkOnly) {
  158. library = this->FindNormalLibrary();
  159. }
  160. if (library.empty() && this->SearchFrameworkLast) {
  161. library = this->FindFrameworkLibrary();
  162. }
  163. return library;
  164. }
  165. struct cmFindLibraryHelper
  166. {
  167. cmFindLibraryHelper(cmMakefile* mf, cmFindBase const* findBase);
  168. // Context information.
  169. cmMakefile* Makefile;
  170. cmFindBase const* FindBase;
  171. cmGlobalGenerator* GG;
  172. // List of valid prefixes and suffixes.
  173. cmList Prefixes;
  174. cmList Suffixes;
  175. std::string PrefixRegexStr;
  176. std::string ICasePrefixRegexStr; // case insensitive
  177. std::string SuffixRegexStr;
  178. std::string ICaseSuffixRegexStr; // case insensitive
  179. // Keep track of the best library file found so far.
  180. using size_type = std::vector<std::string>::size_type;
  181. std::string BestPath;
  182. // Support for OpenBSD shared library naming: lib<name>.so.<major>.<minor>
  183. bool IsOpenBSD;
  184. bool DebugMode;
  185. // Current names under consideration.
  186. struct Name
  187. {
  188. bool TryRaw = false;
  189. std::string Raw;
  190. cmsys::RegularExpression Regex;
  191. cmsys::RegularExpression ICaseRegex; // case insensitive
  192. };
  193. std::vector<Name> Names;
  194. void RegexFromLiteral(std::string& out, std::string const& in,
  195. cmSystemTools::DirCase dirCase);
  196. void RegexFromList(std::string& out, cmList const& in,
  197. cmSystemTools::DirCase dirCase);
  198. size_type GetPrefixIndex(std::string const& prefix)
  199. {
  200. return std::find(this->Prefixes.begin(), this->Prefixes.end(), prefix) -
  201. this->Prefixes.begin();
  202. }
  203. size_type GetSuffixIndex(std::string const& suffix)
  204. {
  205. return std::find(this->Suffixes.begin(), this->Suffixes.end(), suffix) -
  206. this->Suffixes.begin();
  207. }
  208. bool HasValidSuffix(std::string const& name);
  209. void AddName(std::string const& name);
  210. void SetName(std::string const& name);
  211. bool CheckDirectory(std::string const& path);
  212. bool CheckDirectoryForName(std::string const& path, Name& name);
  213. bool Validate(std::string const& path) const
  214. {
  215. return this->FindBase->Validate(path);
  216. }
  217. cmFindBaseDebugState DebugSearches;
  218. void DebugLibraryFailed(std::string const& name, std::string const& path)
  219. {
  220. if (this->DebugMode) {
  221. // To improve readability of the debug output, if there is only one
  222. // prefix/suffix, use the plain prefix/suffix instead of the regex.
  223. auto const& prefix = (this->Prefixes.size() == 1) ? this->Prefixes[0]
  224. : this->PrefixRegexStr;
  225. auto const& suffix = (this->Suffixes.size() == 1) ? this->Suffixes[0]
  226. : this->SuffixRegexStr;
  227. auto regexName = cmStrCat(prefix, name, suffix);
  228. this->DebugSearches.FailedAt(path, regexName);
  229. }
  230. }
  231. void DebugLibraryFound(std::string const& name, std::string const& path)
  232. {
  233. if (this->DebugMode) {
  234. auto regexName =
  235. cmStrCat(this->PrefixRegexStr, name, this->SuffixRegexStr);
  236. this->DebugSearches.FoundAt(path, regexName);
  237. }
  238. }
  239. };
  240. namespace {
  241. std::string const& get_prefixes(cmMakefile* mf)
  242. {
  243. #ifdef _WIN32
  244. static std::string defaultPrefix = ";lib";
  245. #else
  246. static std::string defaultPrefix = "lib";
  247. #endif
  248. cmValue prefixProp = mf->GetDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
  249. return (prefixProp) ? *prefixProp : defaultPrefix;
  250. }
  251. std::string const& get_suffixes(cmMakefile* mf)
  252. {
  253. #ifdef _WIN32
  254. static std::string defaultSuffix = ".lib;.dll.a;.a";
  255. #elif defined(__APPLE__)
  256. static std::string defaultSuffix = ".tbd;.dylib;.so;.a";
  257. #elif defined(__hpux)
  258. static std::string defaultSuffix = ".sl;.so;.a";
  259. #else
  260. static std::string defaultSuffix = ".so;.a";
  261. #endif
  262. cmValue suffixProp = mf->GetDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
  263. return (suffixProp) ? *suffixProp : defaultSuffix;
  264. }
  265. }
  266. cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf,
  267. cmFindBase const* base)
  268. : Makefile(mf)
  269. , FindBase(base)
  270. , DebugMode(base->DebugModeEnabled())
  271. , DebugSearches(base)
  272. {
  273. this->GG = this->Makefile->GetGlobalGenerator();
  274. // Collect the list of library name prefixes/suffixes to try.
  275. std::string const& prefixes_list = get_prefixes(this->Makefile);
  276. std::string const& suffixes_list = get_suffixes(this->Makefile);
  277. this->Prefixes.assign(prefixes_list, cmList::EmptyElements::Yes);
  278. this->Suffixes.assign(suffixes_list, cmList::EmptyElements::Yes);
  279. this->RegexFromList(this->PrefixRegexStr, this->Prefixes,
  280. cmSystemTools::DirCase::Sensitive);
  281. this->RegexFromList(this->ICasePrefixRegexStr, this->Prefixes,
  282. cmSystemTools::DirCase::Insensitive);
  283. this->RegexFromList(this->SuffixRegexStr, this->Suffixes,
  284. cmSystemTools::DirCase::Sensitive);
  285. this->RegexFromList(this->ICaseSuffixRegexStr, this->Suffixes,
  286. cmSystemTools::DirCase::Insensitive);
  287. // Check whether to use OpenBSD-style library version comparisons.
  288. this->IsOpenBSD = this->Makefile->GetState()->GetGlobalPropertyAsBool(
  289. "FIND_LIBRARY_USE_OPENBSD_VERSIONING");
  290. }
  291. void cmFindLibraryHelper::RegexFromLiteral(std::string& out,
  292. std::string const& in,
  293. cmSystemTools::DirCase dirCase)
  294. {
  295. for (char ch : in) {
  296. if (ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' ||
  297. ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' ||
  298. ch == '^' || ch == '$') {
  299. out += "\\";
  300. }
  301. if (dirCase == cmSystemTools::DirCase::Insensitive) {
  302. out += static_cast<char>(tolower(ch));
  303. } else {
  304. out += ch;
  305. }
  306. }
  307. }
  308. void cmFindLibraryHelper::RegexFromList(std::string& out, cmList const& in,
  309. cmSystemTools::DirCase dirCase)
  310. {
  311. // Surround the list in parens so the '|' does not apply to anything
  312. // else and the result can be checked after matching.
  313. out += "(";
  314. char const* sep = "";
  315. for (auto const& s : in) {
  316. // Separate from previous item.
  317. out += sep;
  318. sep = "|";
  319. // Append this item.
  320. this->RegexFromLiteral(out, s, dirCase);
  321. }
  322. out += ")";
  323. }
  324. bool cmFindLibraryHelper::HasValidSuffix(std::string const& name)
  325. {
  326. for (std::string suffix : this->Suffixes) {
  327. if (name.length() <= suffix.length()) {
  328. continue;
  329. }
  330. // Check if the given name ends in a valid library suffix.
  331. if (name.substr(name.size() - suffix.length()) == suffix) {
  332. return true;
  333. }
  334. // Check if a valid library suffix is somewhere in the name,
  335. // this may happen e.g. for versioned shared libraries: libfoo.so.2
  336. suffix += ".";
  337. if (name.find(suffix) != std::string::npos) {
  338. return true;
  339. }
  340. }
  341. return false;
  342. }
  343. void cmFindLibraryHelper::AddName(std::string const& name)
  344. {
  345. Name entry;
  346. // Consider checking the raw name too.
  347. entry.TryRaw = this->HasValidSuffix(name);
  348. entry.Raw = name;
  349. // Build a regular expression to match library names.
  350. {
  351. std::string regex = cmStrCat('^', this->PrefixRegexStr);
  352. this->RegexFromLiteral(regex, name, cmSystemTools::DirCase::Sensitive);
  353. regex += this->SuffixRegexStr;
  354. if (this->IsOpenBSD) {
  355. regex += "(\\.[0-9]+\\.[0-9]+)?";
  356. }
  357. regex += "$";
  358. entry.Regex.compile(regex);
  359. }
  360. // case insensitive version
  361. {
  362. std::string regex = cmStrCat('^', this->ICasePrefixRegexStr);
  363. this->RegexFromLiteral(regex, name, cmSystemTools::DirCase::Insensitive);
  364. regex += this->ICaseSuffixRegexStr;
  365. if (this->IsOpenBSD) {
  366. regex += "(\\.[0-9]+\\.[0-9]+)?";
  367. }
  368. regex += "$";
  369. entry.ICaseRegex.compile(regex);
  370. }
  371. this->Names.push_back(std::move(entry));
  372. }
  373. void cmFindLibraryHelper::SetName(std::string const& name)
  374. {
  375. this->Names.clear();
  376. this->AddName(name);
  377. }
  378. bool cmFindLibraryHelper::CheckDirectory(std::string const& path)
  379. {
  380. for (Name& i : this->Names) {
  381. if (this->CheckDirectoryForName(path, i)) {
  382. return true;
  383. }
  384. }
  385. return false;
  386. }
  387. bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
  388. Name& name)
  389. {
  390. // If the original library name provided by the user matches one of
  391. // the suffixes, try it first. This allows users to search
  392. // specifically for a static library on some platforms (on MS tools
  393. // one cannot tell just from the library name whether it is a static
  394. // library or an import library).
  395. if (name.TryRaw) {
  396. std::string testPath = cmStrCat(path, name.Raw);
  397. if (cmSystemTools::FileExists(testPath, true)) {
  398. testPath = cmSystemTools::ToNormalizedPathOnDisk(testPath);
  399. if (this->Validate(testPath)) {
  400. this->DebugLibraryFound(name.Raw, path);
  401. this->BestPath = testPath;
  402. return true;
  403. }
  404. }
  405. this->DebugLibraryFailed(name.Raw, path);
  406. }
  407. // No library file has yet been found.
  408. size_type bestPrefix = this->Prefixes.size();
  409. size_type bestSuffix = this->Suffixes.size();
  410. unsigned int bestMajor = 0;
  411. unsigned int bestMinor = 0;
  412. // Search for a file matching the library name regex.
  413. cm::optional<cmSystemTools::DirCase> dirCase =
  414. cmSystemTools::GetDirCase(path).value_or(
  415. cmSystemTools::DirCase::Sensitive);
  416. cmsys::RegularExpression& regex =
  417. dirCase == cmSystemTools::DirCase::Insensitive ? name.ICaseRegex
  418. : name.Regex;
  419. std::set<std::string> const& files = this->GG->GetDirectoryContent(path);
  420. for (std::string const& origName : files) {
  421. std::string testName = dirCase == cmSystemTools::DirCase::Insensitive
  422. ? cmSystemTools::LowerCase(origName)
  423. : origName;
  424. if (regex.find(testName)) {
  425. std::string testPath = cmStrCat(path, origName);
  426. // Make sure the path is readable and is not a directory.
  427. if (cmSystemTools::FileExists(testPath, true)) {
  428. testPath = cmSystemTools::ToNormalizedPathOnDisk(testPath);
  429. if (!this->Validate(testPath)) {
  430. continue;
  431. }
  432. this->DebugLibraryFound(name.Raw, path);
  433. // This is a matching file. Check if it is better than the
  434. // best name found so far. Earlier prefixes are preferred,
  435. // followed by earlier suffixes. For OpenBSD, shared library
  436. // version extensions are compared.
  437. size_type prefix = this->GetPrefixIndex(regex.match(1));
  438. size_type suffix = this->GetSuffixIndex(regex.match(2));
  439. unsigned int major = 0;
  440. unsigned int minor = 0;
  441. if (this->IsOpenBSD) {
  442. sscanf(regex.match(3).c_str(), ".%u.%u", &major, &minor);
  443. }
  444. if (this->BestPath.empty() || prefix < bestPrefix ||
  445. (prefix == bestPrefix && suffix < bestSuffix) ||
  446. (prefix == bestPrefix && suffix == bestSuffix &&
  447. (major > bestMajor ||
  448. (major == bestMajor && minor > bestMinor)))) {
  449. this->BestPath = testPath;
  450. bestPrefix = prefix;
  451. bestSuffix = suffix;
  452. bestMajor = major;
  453. bestMinor = minor;
  454. }
  455. }
  456. }
  457. }
  458. if (this->BestPath.empty()) {
  459. this->DebugLibraryFailed(name.Raw, path);
  460. } else {
  461. this->DebugLibraryFound(name.Raw, this->BestPath);
  462. }
  463. // Use the best candidate found in this directory, if any.
  464. return !this->BestPath.empty();
  465. }
  466. std::string cmFindLibraryCommand::FindNormalLibrary()
  467. {
  468. if (this->NamesPerDir) {
  469. return this->FindNormalLibraryNamesPerDir();
  470. }
  471. return this->FindNormalLibraryDirsPerName();
  472. }
  473. std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir()
  474. {
  475. // Search for all names in each directory.
  476. cmFindLibraryHelper helper(this->Makefile, this);
  477. for (std::string const& n : this->Names) {
  478. helper.AddName(n);
  479. }
  480. // Search every directory.
  481. for (std::string const& sp : this->SearchPaths) {
  482. if (helper.CheckDirectory(sp)) {
  483. return helper.BestPath;
  484. }
  485. }
  486. // Couldn't find the library.
  487. return "";
  488. }
  489. std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName()
  490. {
  491. // Search the entire path for each name.
  492. cmFindLibraryHelper helper(this->Makefile, this);
  493. for (std::string const& n : this->Names) {
  494. // Switch to searching for this name.
  495. helper.SetName(n);
  496. // Search every directory.
  497. for (std::string const& sp : this->SearchPaths) {
  498. if (helper.CheckDirectory(sp)) {
  499. return helper.BestPath;
  500. }
  501. }
  502. }
  503. // Couldn't find the library.
  504. return "";
  505. }
  506. std::string cmFindLibraryCommand::FindFrameworkLibrary()
  507. {
  508. if (this->NamesPerDir) {
  509. return this->FindFrameworkLibraryNamesPerDir();
  510. }
  511. return this->FindFrameworkLibraryDirsPerName();
  512. }
  513. std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir()
  514. {
  515. std::string fwPath;
  516. // Search for all names in each search path.
  517. for (std::string const& d : this->SearchPaths) {
  518. for (std::string const& n : this->Names) {
  519. fwPath = cmStrCat(d, n, ".xcframework");
  520. if (cmSystemTools::FileIsDirectory(fwPath)) {
  521. auto finalPath = cmSystemTools::ToNormalizedPathOnDisk(fwPath);
  522. if (this->Validate(finalPath)) {
  523. return finalPath;
  524. }
  525. }
  526. fwPath = cmStrCat(d, n, ".framework");
  527. if (cmSystemTools::FileIsDirectory(fwPath)) {
  528. auto finalPath = cmSystemTools::ToNormalizedPathOnDisk(fwPath);
  529. if (this->Validate(finalPath)) {
  530. return finalPath;
  531. }
  532. }
  533. }
  534. }
  535. // No framework found.
  536. return "";
  537. }
  538. std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName()
  539. {
  540. std::string fwPath;
  541. // Search for each name in all search paths.
  542. for (std::string const& n : this->Names) {
  543. for (std::string const& d : this->SearchPaths) {
  544. fwPath = cmStrCat(d, n, ".xcframework");
  545. if (cmSystemTools::FileIsDirectory(fwPath)) {
  546. auto finalPath = cmSystemTools::ToNormalizedPathOnDisk(fwPath);
  547. if (this->Validate(finalPath)) {
  548. return finalPath;
  549. }
  550. }
  551. fwPath = cmStrCat(d, n, ".framework");
  552. if (cmSystemTools::FileIsDirectory(fwPath)) {
  553. auto finalPath = cmSystemTools::ToNormalizedPathOnDisk(fwPath);
  554. if (this->Validate(finalPath)) {
  555. return finalPath;
  556. }
  557. }
  558. }
  559. }
  560. // No framework found.
  561. return "";
  562. }
  563. bool cmFindLibrary(std::vector<std::string> const& args,
  564. cmExecutionStatus& status)
  565. {
  566. return cmFindLibraryCommand(status).InitialPass(args);
  567. }