diff options
author | Brad King <brad.king@kitware.com> | 2008-09-22 15:08:17 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-09-22 15:08:17 (GMT) |
commit | 434a99bbeb6ddb063a17b7065eaddf90b0157c65 (patch) | |
tree | 93d0303a08c515fd3217d41a8132b99a2c7d926b /Source/cmFindLibraryCommand.cxx | |
parent | 6b851669204adb55490df124a62ffb15f2da4630 (diff) | |
download | CMake-434a99bbeb6ddb063a17b7065eaddf90b0157c65.zip CMake-434a99bbeb6ddb063a17b7065eaddf90b0157c65.tar.gz CMake-434a99bbeb6ddb063a17b7065eaddf90b0157c65.tar.bz2 |
ENH: Teach find_library to find OpenBSD-style libs
OpenBSD shared libraries use a ".so.<major>.<minor>" extension and do
not have a symlink with just a ".so" extension. Its "ld" is capable of
finding the library with the best version. This change adds support for
finding such libraries. See issue #3470.
Diffstat (limited to 'Source/cmFindLibraryCommand.cxx')
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 228ea18..b81a5bf 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -249,6 +249,11 @@ struct cmFindLibraryHelper size_type BestPrefix; size_type BestSuffix; + // Support for OpenBSD shared library naming: lib<name>.so.<major>.<minor> + bool OpenBSD; + unsigned int BestMajor; + unsigned int BestMinor; + // Current name under consideration. cmsys::RegularExpression NameRegex; bool TryRawName; @@ -290,11 +295,18 @@ cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf): this->RegexFromList(this->PrefixRegexStr, this->Prefixes); this->RegexFromList(this->SuffixRegexStr, this->Suffixes); + // Check whether to use OpenBSD-style library version comparisons. + this->OpenBSD = + this->Makefile->GetCMakeInstance() + ->GetPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING"); + this->TryRawName = false; // No library file has yet been found. this->BestPrefix = this->Prefixes.size(); this->BestSuffix = this->Suffixes.size(); + this->BestMajor = 0; + this->BestMinor = 0; } //---------------------------------------------------------------------------- @@ -368,6 +380,10 @@ void cmFindLibraryHelper::SetName(std::string const& name) regex += this->PrefixRegexStr; this->RegexFromLiteral(regex, name); regex += this->SuffixRegexStr; + if(this->OpenBSD) + { + regex += "(\\.[0-9]+\\.[0-9]+)?"; + } regex += "$"; this->NameRegex.compile(regex.c_str()); } @@ -414,15 +430,27 @@ bool cmFindLibraryHelper::CheckDirectory(std::string const& path) { // This is a matching file. Check if it is better than the // best name found so far. Earlier prefixes are preferred, - // followed by earlier suffixes. + // followed by earlier suffixes. For OpenBSD, shared library + // version extensions are compared. size_type prefix = this->GetPrefixIndex(this->NameRegex.match(1)); size_type suffix = this->GetSuffixIndex(this->NameRegex.match(2)); + unsigned int major = 0; + unsigned int minor = 0; + if(this->OpenBSD) + { + sscanf(this->NameRegex.match(3).c_str(), ".%u.%u", &major, &minor); + } if(this->BestPath.empty() || prefix < this->BestPrefix || - (prefix == this->BestPrefix && suffix < this->BestSuffix)) + (prefix == this->BestPrefix && suffix < this->BestSuffix) || + (prefix == this->BestPrefix && suffix == this->BestSuffix && + (major > this->BestMajor || + (major == this->BestMajor && minor > this->BestMinor)))) { this->BestPath = this->TestPath; this->BestPrefix = prefix; this->BestSuffix = suffix; + this->BestMajor = major; + this->BestMinor = minor; } } } |