[CMake] Finding dynamic libraries with major interface revision numbers (2)

Michael Hertling mhertling at online.de
Wed Apr 13 16:08:38 EDT 2011


On 04/13/2011 09:26 PM, Brad King wrote:
> On 04/13/2011 02:44 PM, Jean-Christophe Fillion-Robin wrote:
>> Is there a solution to find a library having a revision number ?
> 
> You can specify the actual library file name "libgfortran.so.3".

AFAIK, this is not sufficient because FIND_LIBRARY() only looks for
library files - specified literally or not - which end with a suffix
mentioned in FIND_LIBRARY_SUFFIXES. See the following CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(XYZ NONE)
SET(CMAKE_VERBOSE_MAKEFILE ON)
FILE(WRITE ${CMAKE_BINARY_DIR}/libxyz.so.3 "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so.3")
FIND_LIBRARY(XYZ libxyz.so.3 PATHS ${CMAKE_BINARY_DIR} NO_DEFAULT_PATH)
MESSAGE("XYZ: ${XYZ}")

First, ${CMAKE_BINARY_DIR}/libxyz.so.3 is found, but if you remove the
SET(CMAKE_FIND_LIBRARY_SUFFIXES ...) command and unset the XYZ cache
entry, you'll probably see libxyz.so.3 not being found anymore. It is
cmFindLibraryHelper::SetName() that implements this behaviour, if I'm
not mistaken. So, a possible workaround is to temporarily add ".so.3"
or whatever is desired to CMAKE_FIND_LIBRARY_SUFFIXES before calling
FIND_LIBRARY(), cf. [1].

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg35219.html


More information about the CMake mailing list