Discussion:
[CMake] find_library first searches for static libraries
Nicolas Desprès
2008-07-01 18:37:38 UTC
Permalink
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)

If someone has a better solution, please fill free to tell me.

Thx in advance,
--
Nicolas Desprès
Philip Lowman
2008-07-02 02:25:32 UTC
Permalink
Post by Nicolas Desprès
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)

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.
--
Philip Lowman
Nicolas Desprès
2008-07-02 07:17:07 UTC
Permalink
Post by Philip Lowman
Post by Nicolas Desprès
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
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.
Post by Philip Lowman
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
Loading...