cmFindLibraryCommand.cxx 20 KB

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