Explicitly find libcrypto static/shared libs, export the winner based on BUILD_SHARED_LIBS
#
# LibCrypto_FOUND System has libcrypto, include and library dirs found
# LibCrypto_INCLUDE_DIR The crypto include directories.
-# LibCrypto_LIBRARY The crypto library.
+# LibCrypto_LIBRARY The crypto library, depending on the value of BUILD_SHARED_LIBS.
+# LibCrypto_SHARED_LIBRARY The path to libcrypto.so
+# LibCrypto_STATIC_LIBRARY The path to libcrypto.a
+
find_path(LibCrypto_INCLUDE_DIR
NAMES openssl/crypto.h
HINTS
${CMAKE_PREFIX_PATH}/include
${CMAKE_INSTALL_PREFIX}/include
)
-
-if (BUILD_SHARED_LIBS)
- find_library(LibCrypto_LIBRARY
- NAMES libcrypto.so libcrypto.a
+find_library(LibCrypto_SHARED_LIBRARY
+ NAMES libcrypto.so
HINTS
${CMAKE_PREFIX_PATH}/build/crypto
${CMAKE_PREFIX_PATH}/build
@@ -34,9 +35,8 @@ if (BUILD_SHARED_LIBS)
${CMAKE_INSTALL_PREFIX}/lib64
${CMAKE_INSTALL_PREFIX}/lib
)
-else()
- find_library(LibCrypto_LIBRARY
- NAMES libcrypto.a libcrypto.so
+find_library(LibCrypto_STATIC_LIBRARY
+ NAMES libcrypto.a
HINTS
${CMAKE_PREFIX_PATH}/build/crypto
${CMAKE_PREFIX_PATH}/build
@@ -49,6 +49,11 @@ else()
${CMAKE_INSTALL_PREFIX}/lib64
${CMAKE_INSTALL_PREFIX}/lib
)
+
+if (BUILD_SHARED_LIBS)
+ set(LibCrypto_LIBRARY ${LibCrypto_SHARED_LIBRARY})
+else()
+ set(LibCrypto_LIBRARY ${LibCrypto_STATIC_LIBRARY})
endif()
@@ -62,10 +67,14 @@ mark_as_advanced(
LibCrypto_ROOT_DIR
LibCrypto_INCLUDE_DIR
LibCrypto_LIBRARY
+ LibCrypto_SHARED_LIBRARY
+ LibCrypto_STATIC_LIBRARY
)
if(LibCrypto_FOUND)
- message(STATUS "Libcrypto Include Dir: ${LibCrypto_INCLUDE_DIR}")
+ message(STATUS "LibCrypto Include Dir: ${LibCrypto_INCLUDE_DIR}")
+ message(STATUS "LibCrypto Shared Lib: ${LibCrypto_SHARED_LIBRARY}")
+ message(STATUS "LibCrypto Static Lib: ${LibCrypto_STATIC_LIBRARY}")
if (NOT TARGET LibCrypto::Crypto AND
(EXISTS "${LibCrypto_LIBRARY}")
)
