Merge pull request #25883 from CrystalP/fix-slowscan
[xbmc.git] / cmake / modules / FindOpenSSL.cmake
blob08902878eb9e7baf51dea80b169b9c4ba331a476
1 # FindOpenSSL
2 # -----------
3 # Finds the Openssl libraries
5 # This will define the following target:
7 #   ${APP_NAME_LC}::OpenSSL - Alias of OpenSSL::SSL target
8 #   OpenSSL::SSL - standard Openssl SSL target from system find package
9 #   OpenSSL::Crypto - standard Openssl Crypto target from system find package
11 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
13   # We do this dance to utilise cmake system FindOpenssl. Saves us dealing with it
14   set(_temp_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
15   unset(CMAKE_MODULE_PATH)
17   if(OpenSSL_FIND_REQUIRED)
18     set(REQ "REQUIRED")
19   endif()
21   # Only aim for static libs on windows or depends builds
22   if(KODI_DEPENDSBUILD OR (WIN32 OR WINDOWS_STORE))
23     set(OPENSSL_USE_STATIC_LIBS ON)
24     set(OPENSSL_ROOT_DIR ${DEPENDS_PATH})
25   endif()
27   find_package(OpenSSL ${REQ})
28   unset(OPENSSL_USE_STATIC_LIBS)
30   # Back to our normal module paths
31   set(CMAKE_MODULE_PATH ${_temp_CMAKE_MODULE_PATH})
33   if(OPENSSL_FOUND)
34     add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS OpenSSL::SSL)
36     # Add Crypto as a link library to easily propagate both targets to our custom target
37     set_target_properties(OpenSSL::SSL PROPERTIES
38                                        INTERFACE_LINK_LIBRARIES "OpenSSL::Crypto")
39   else()
40     if(OpenSSL_FIND_REQUIRED)
41       message(FATAL_ERROR "OpenSSL libraries were not found.")
42     endif()
43   endif()
44 endif()