I have a cmake c++ project that uses libCrypto++. I have FindCryptoPP.cmake module hosted here. Important parts are:
find_library(CryptoPP_LIBRARY
NAMES cryptopp
DOC "CryptoPP library"
NO_PACKAGE_ROOT_PATH
PATHS "/usr/lib/x86_64-linux-gnu/"
)
...
add_library(CryptoPP::CryptoPP UNKNOWN IMPORTED)
set_target_properties(CryptoPP::CryptoPP PROPERTIES
IMPORTED_LOCATION "${CryptoPP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CryptoPP_INCLUDE_DIR}")
And this works fine, finds static library file (*.a). Now I would like to create separate targets CryptoPP::CryptoPP-static and CryptoPP::CryptoPP-shared. Necessary files are installed (default ubuntu install):
- /usr/lib/x86_64-linux-gnu/libcryptopp.a
- /usr/lib/x86_64-linux-gnu/libcryptopp.so
I want to know how to tell find_library to search either static or shared version (preferably in portable way - I need all of Linux, Windows, MacOS) and specify the type created target.
Actually CMake's default is to search first for shared libraries and then for static libraries.
The key is the order of values in the
CMAKE_FIND_LIBRARY_SUFFIXES
global variable, which is e.g. set inCMakeGenericSystem.cmake
as part of CMake's compiler/platform detection of theproject()
command to:For a solution take a look at an existing find module like
FindBoost.cmake
:Here the
CMAKE_FIND_LIBRARY_SUFFIXES
variable is temporarily changed for thefind_library()
calls.Same should be applicable here. Just be aware the
find_library()
does cache its results if you want to do the same search twice.References