diff options
author | Brad King <brad.king@kitware.com> | 2008-09-22 11:08:17 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-09-22 11:08:17 -0400 |
commit | 434a99bbeb6ddb063a17b7065eaddf90b0157c65 (patch) | |
tree | 93d0303a08c515fd3217d41a8132b99a2c7d926b | |
parent | 6b851669204adb55490df124a62ffb15f2da4630 (diff) | |
download | cmake-434a99bbeb6ddb063a17b7065eaddf90b0157c65.tar.gz |
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.
-rw-r--r-- | Modules/Platform/OpenBSD.cmake | 1 | ||||
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmake.cxx | 7 |
3 files changed, 38 insertions, 2 deletions
diff --git a/Modules/Platform/OpenBSD.cmake b/Modules/Platform/OpenBSD.cmake index cbdcb7dae8..422227be28 100644 --- a/Modules/Platform/OpenBSD.cmake +++ b/Modules/Platform/OpenBSD.cmake @@ -1,2 +1,3 @@ SET(CMAKE_DL_LIBS "") +SET_PROPERTY(GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1) INCLUDE(Platform/UnixPaths) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 228ea18d10..b81a5bfe1a 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; } } } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index b053fb56d3..bf62aa9643 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3327,6 +3327,13 @@ void cmake::DefineProperties(cmake *cm) "directories called lib in the search path when building 64-bit " "binaries."); cm->DefineProperty + ("FIND_LIBRARY_USE_OPENBSD_VERSIONING", cmProperty::GLOBAL, + "Whether FIND_LIBRARY should find OpenBSD-style shared libraries.", + "This property is a boolean specifying whether the FIND_LIBRARY " + "command should find shared libraries with OpenBSD-style versioned " + "extension: \".so.<major>.<minor>\". " + "The property is set to true on OpenBSD and false on other platforms."); + cm->DefineProperty ("ENABLED_FEATURES", cmProperty::GLOBAL, "List of features which are enabled during the CMake run.", "List of features which are enabled during the CMake run. Be default " |