1
0
Эх сурвалжийг харах

ENH: Added platform settings CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFFIXES to allow customized searching for libraries.

Brad King 20 жил өмнө
parent
commit
33587ce376

+ 3 - 0
Modules/CMakeGenericSystem.cmake

@@ -22,6 +22,9 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
   SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fPIC")   # -pic
 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
 
+SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
+
 SET (CMAKE_SKIP_RPATH "NO" CACHE BOOL
      "If set, runtime paths are not added when using shared libraries.")
 

+ 3 - 0
Modules/Platform/CYGWIN.cmake

@@ -6,3 +6,6 @@ SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "")
 SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
 SET(CMAKE_EXECUTABLE_SUFFIX ".exe")          # .exe
+
+SET(CMAKE_FIND_LIBRARY_PREFIXES "cyg" "lib")
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a")

+ 1 - 0
Modules/Platform/Darwin.cmake

@@ -6,6 +6,7 @@ SET(CMAKE_MODULE_EXISTS 1)
 SET(CMAKE_DL_LIBS "")
 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib")
 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle")
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
 
 IF("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$")
   SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS

+ 1 - 0
Modules/Platform/HP-UX.cmake

@@ -1,5 +1,6 @@
 SET(CMAKE_SHARED_LIBRARY_SUFFIX ".sl")          # .so
 SET(CMAKE_DL_LIBS "-ldld")
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".sl" ".so" ".a")
 
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")   # : or empty
 

+ 2 - 0
Modules/Platform/Windows-bcc32.cmake

@@ -16,6 +16,8 @@ SET(CMAKE_SHARED_BUILD_CXX_FLAGS "-tWR")
 SET(CMAKE_SHARED_BUILD_C_FLAGS "-tWR")
 SET(BORLAND 1)
 
+SET(CMAKE_FIND_LIBRARY_SUFFIXES "-bcc.lib" ".lib")
+
 # uncomment these out to debug makefiles
 #SET(CMAKE_START_TEMP_FILE "")
 #SET(CMAKE_END_TEMP_FILE "")

+ 5 - 0
Modules/Platform/Windows-gcc.cmake

@@ -15,3 +15,8 @@ SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")       # -rpath
 SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "")   # : or empty
 SET(CMAKE_LIBRARY_PATH_FLAG "-L")
 SET(CMAKE_LINK_LIBRARY_FLAG "-l")
+
+IF(MINGW)
+  SET(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+  SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a")
+ENDIF(MINGW)

+ 3 - 0
Modules/Platform/Windows.cmake

@@ -6,6 +6,9 @@ SET(CMAKE_EXECUTABLE_SUFFIX ".exe")          # .exe
 SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
 SET(CMAKE_DL_LIBS "")
 
+SET(CMAKE_FIND_LIBRARY_PREFIXES "")
+SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
+
 # for borland make long command lines are redirected to a file
 # with the following syntax, see Windows-bcc32.cmake for use
 IF(CMAKE_GENERATOR MATCHES "Borland")

+ 26 - 24
Source/cmMakefile.cxx

@@ -2310,17 +2310,16 @@ std::string cmMakefile::FindLibrary(const char* name,
     return cmSystemTools::CollapseFullPath(name);
     }
 
-  // Construct a list of possible suffixes.
-  const char* windows_suffixes[] = {".lib", 0};
-  const char* unix_suffixes[] = {".so", ".sl", ".dylib", ".a",
-                                 ".dll", ".dll.a", 0};
-  bool windowsLibs = false;
-  if(cmSystemTools::IsOn(this->GetDefinition("WIN32")) &&
-     !cmSystemTools::IsOn(this->GetDefinition("CYGWIN")) &&
-     !cmSystemTools::IsOn(this->GetDefinition("MINGW")))
-    {
-    windowsLibs = true;
-    }
+  // Get the list of possible prefixes and suffixes for libraries on
+  // this platform.
+  const char* prefixes_list =
+    this->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
+  const char* suffixes_list =
+    this->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
+  std::vector<std::string> prefixes;
+  std::vector<std::string> suffixes;
+  cmSystemTools::ExpandListArgument(prefixes_list, prefixes);
+  cmSystemTools::ExpandListArgument(suffixes_list, suffixes);
 
   std::string tryPath;
   for(std::vector<std::string>::const_iterator p = path.begin();
@@ -2343,21 +2342,24 @@ std::string cmMakefile::FindLibrary(const char* name,
       }
 
     // Try various library naming conventions.
-    const char* prefix = windowsLibs? "" : "lib";
-    const char** suffixes = windowsLibs? windows_suffixes : unix_suffixes;
-    for(const char** suffix = suffixes; *suffix; ++suffix)
+    for(std::vector<std::string>::iterator prefix = prefixes.begin();
+        prefix != prefixes.end(); ++prefix)
       {
-      tryPath = *p;
-      tryPath += "/";
-      tryPath += prefix;
-      tryPath += name;
-      tryPath += *suffix;
-      if(cmSystemTools::FileExists(tryPath.c_str())
-         && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
+      for(std::vector<std::string>::iterator suffix = suffixes.begin();
+          suffix != suffixes.end(); ++suffix)
         {
-        tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
-        cmSystemTools::ConvertToUnixSlashes(tryPath);
-        return tryPath;
+        tryPath = *p;
+        tryPath += "/";
+        tryPath += *prefix;
+        tryPath += name;
+        tryPath += *suffix;
+        if(cmSystemTools::FileExists(tryPath.c_str())
+           && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
+          {
+          tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
+          cmSystemTools::ConvertToUnixSlashes(tryPath);
+          return tryPath;
+          }
         }
       }
     }