cmFindLibraryCommand.cxx 20 KB

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