| 446 | } |
| 447 | |
| 448 | bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, |
| 449 | Name& name) |
| 450 | { |
| 451 | // If the original library name provided by the user matches one of |
| 452 | // the suffixes, try it first. This allows users to search |
| 453 | // specifically for a static library on some platforms (on MS tools |
| 454 | // one cannot tell just from the library name whether it is a static |
| 455 | // library or an import library). |
| 456 | if (name.TryRaw) { |
| 457 | std::string testPath = cmStrCat(path, name.Raw); |
| 458 | |
| 459 | if (cmSystemTools::FileExists(testPath, true)) { |
| 460 | testPath = cmSystemTools::ToNormalizedPathOnDisk(testPath); |
| 461 | if (this->Validate(testPath)) { |
| 462 | this->DebugLibraryFound(name.Raw, path); |
| 463 | this->BestPath = testPath; |
| 464 | return true; |
| 465 | } |
| 466 | } |
| 467 | this->DebugLibraryFailed(name.Raw, path); |
| 468 | } |
| 469 | |
| 470 | // No library file has yet been found. |
| 471 | size_type bestPrefix = this->Prefixes.size(); |
| 472 | size_type bestSuffix = this->Suffixes.size(); |
| 473 | unsigned int bestMajor = 0; |
| 474 | unsigned int bestMinor = 0; |
| 475 | |
| 476 | // Search for a file matching the library name regex. |
| 477 | cm::optional<cmSystemTools::DirCase> dirCase = |
| 478 | cmSystemTools::GetDirCase(path).value_or( |
| 479 | cmSystemTools::DirCase::Sensitive); |
| 480 | cmsys::RegularExpression& regex = |
| 481 | dirCase == cmSystemTools::DirCase::Insensitive ? name.ICaseRegex |
| 482 | : name.Regex; |
| 483 | std::set<std::string> const& files = this->GG->GetDirectoryContent(path); |
| 484 | for (std::string const& origName : files) { |
| 485 | std::string testName = dirCase == cmSystemTools::DirCase::Insensitive |
| 486 | ? cmSystemTools::LowerCase(origName) |
| 487 | : origName; |
| 488 | |
| 489 | if (regex.find(testName)) { |
| 490 | std::string testPath = cmStrCat(path, origName); |
| 491 | // Make sure the path is readable and is not a directory. |
| 492 | if (cmSystemTools::FileExists(testPath, true)) { |
| 493 | testPath = cmSystemTools::ToNormalizedPathOnDisk(testPath); |
| 494 | if (!this->Validate(testPath)) { |
| 495 | continue; |
| 496 | } |
| 497 | |
| 498 | this->DebugLibraryFound(name.Raw, path); |
| 499 | // This is a matching file. Check if it is better than the |
| 500 | // best name found so far. Earlier prefixes are preferred, |
| 501 | // followed by earlier suffixes. For OpenBSD, shared library |
| 502 | // version extensions are compared. |
| 503 | size_type prefix = this->GetPrefixIndex(regex.match(1)); |
| 504 | size_type suffix = this->GetSuffixIndex(regex.match(2)); |
| 505 | unsigned int major = 0; |
no test coverage detected