cmFindLibraryCommand.cxx 20 KB

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