[cmake-developers] Finding versioned libraries

Eric Noulard eric.noulard at gmail.com
Wed Feb 15 10:00:02 EST 2012


2012/2/15 Rolf Eike Beer <eike at sf-mail.de>:
>> 2012/2/15 Rolf Eike Beer <eike at sf-mail.de>:
>>> Hi,
>>>
>>> as I found out today this construct doesn't work:
>>>
>>> find_library(MYLIB libfoo.so.2)
>>>
>>> This is because find_library will only try to access the whole path if
>>> the
>>> given name matches PREFIX.*SUFFIX, which is obviously not the case here.
>>> My
>>> simple approach on fixing this would be to also allow
>>> PREFIX.*SUFFIX\..*:
>>
>> [...]
>>> @@ -358,9 +358,17 @@ bool
>>> cmFindLibraryHelper::HasValidSuffix(std::string const& name)
>>
>> [...]
>>> Any objections?
>>
>> If the user does not trust find_library for checking proper extension
>> then:
>>    1) He could modify/append CMAKE_FIND_LIBRARY_SUFFIXES
>>        in this case:
>>           list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.2")
>>        should work.
>>
>>    2) He could use find_file
>>
>> Now if we consider this is a bug,
>> then with your modification "HasValidSuffix" is ill-named since it is more
>> like
>> "ContainsValidSuffix" or "MatchesValidSuffix".
>>
>> With this modification one could now find a not-properly-installed
>> library (missing links) without noticing it.
>
> Yes, but only if he explicitely specifies the correct name. It's not that
> find_library will now find libfoo.so.2 now when you do find_library(VAR
> foo).

Yes you are right I missed that, sorry.

>> What is your purpose here, do you want to ensure that you find a
>> particular version of a lib?
>
> FindPerlLibs.cmake queries perl for the perl library name, which is e.g.
> "libperl.so.5.12.4" on my machine. And find_library is not able to find a
> library given that name, even if it is perfectly valid. With this
> modification is is able to get that.

Ok but then may be having a way to specify
a regex in CMAKE_FIND_LIBRARY_SUFFIXES would be better.

Or may be just way to tell you need to find RAW name.
find_library(MYLIB libfoo.so.2 RAW)

That said your fix seems to be backward compatible and working for
your purpose so, asking for more doesn't seems reasonable..

Sorry.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org



More information about the cmake-developers mailing list