diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index fc2b95d1a..1ea6e3601 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/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.") diff --git a/Modules/Platform/CYGWIN.cmake b/Modules/Platform/CYGWIN.cmake index 7fd66157c..cfd1fb080 100644 --- a/Modules/Platform/CYGWIN.cmake +++ b/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") diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 74caf0b5f..f6e59468c 100644 --- a/Modules/Platform/Darwin.cmake +++ b/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 diff --git a/Modules/Platform/HP-UX.cmake b/Modules/Platform/HP-UX.cmake index b2b9e03ef..6b31509b4 100644 --- a/Modules/Platform/HP-UX.cmake +++ b/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 diff --git a/Modules/Platform/Windows-bcc32.cmake b/Modules/Platform/Windows-bcc32.cmake index 72d86b768..f265c64b6 100644 --- a/Modules/Platform/Windows-bcc32.cmake +++ b/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 "") diff --git a/Modules/Platform/Windows-gcc.cmake b/Modules/Platform/Windows-gcc.cmake index 949cc5667..779d1e52e 100644 --- a/Modules/Platform/Windows-gcc.cmake +++ b/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) diff --git a/Modules/Platform/Windows.cmake b/Modules/Platform/Windows.cmake index 163d3f6c1..a79a48997 100644 --- a/Modules/Platform/Windows.cmake +++ b/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") diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 4eae62286..d8ba05a37 100644 --- a/Source/cmMakefile.cxx +++ b/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 prefixes; + std::vector suffixes; + cmSystemTools::ExpandListArgument(prefixes_list, prefixes); + cmSystemTools::ExpandListArgument(suffixes_list, suffixes); std::string tryPath; for(std::vector::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::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::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; + } } } }