[CMake] find_library first searches for static libraries

Nicolas Desprès nicolas.despres at gmail.com
Wed Jul 2 03:17:07 EDT 2008


On Wed, Jul 2, 2008 at 4:25 AM, Philip Lowman <philip at yhbt.com> wrote:
> On Tue, Jul 1, 2008 at 2:37 PM, Nicolas Desprès <nicolas.despres at gmail.com>
> wrote:
>>
>> Hi list,
>>
>> I'm looking for a way to say to find_library (cmake 2.6.0) that I
>> prefer static libraries rather than shared libraries. It seems that
>> there is no option to do. The only work around I found is the
>> following but it is not portable obviously.
>>
>> set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
>> find_library(OPENSSL_LIBRARY ssl)
>
> 2.6.0 checks the library names specified to find_library() as filenames
> first so you could do something like this to ensure that on a Unix build it
> would pick up the static library first:
>
> find_library(OPENSSL_LIBRARY libssl.a)
> find_library(OPENSSL_LIBRARY ssl)
> or
> find_library(OPENSSL_LIBRARY NAMES libssl.a ssl)
>

Thanks for your answer Philip, but this is still not portable and we
have to duplicate the code that cmake's author already wrote to
portably set CMAKE_FIND_LIBRARY_SUFFIXES.

> Unfortunately this only works for CMake code that you can control.  If one
> had to use a CMake module to add an external dependency your idea would seem
> to be the only viable option without modifying the module code itself.
>

Yes. If I want to rewrite OpenSSL module so that it could be used like this:

find_package(OpenSSL REQUIRED)
set(OPENSSL_USE_STATIC 1)
include(${OPENSSL_USE_FILE})

I will still have to do either your suggestion or mine but they
duplicate cmake's code.

Cheers,

-- 
Nicolas Desprès


More information about the CMake mailing list