OpenSSL depends on system libraries.  When linking statically again
OpenSSL, the client target must also link those libraries.

This patch updates FindOpenSSL.cmake to include the necessary system
libs in the OpenSSL libraries variables and in the OpenSSL::Crypto and
OpenSSL::SSL target properties.

The dependencies:
Windows: crypt32
Unix: CMAKE_DL_LIBS
From 4c1332675ad6b8bce360285869b90d4302735d5b Mon Sep 17 00:00:00 2001
From: Alexander Lamaison <alexander.lamai...@gmail.com>
Date: Sun, 14 Aug 2016 18:45:46 +0100
Subject: [PATCH] FindOpenSSL: Link libraries needed for static OpenSSL.

OpenSSL depends on system libraries.  When linking statically again
OpenSSL, the client target must also link those libraries.

This patch updates FindOpenSSL.cmake to include the necessary system
libs in the OpenSSL libraries variables and in the OpenSSL::Crypto and
OpenSSL::SSL target properties.

The dependencies:
Windows: crypt32
Unix: CMAKE_DL_LIBS
---
 Modules/FindOpenSSL.cmake | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake
index 10b62ff..275d283 100644
--- a/Modules/FindOpenSSL.cmake
+++ b/Modules/FindOpenSSL.cmake
@@ -199,9 +199,9 @@ if(WIN32 AND NOT CYGWIN)
 
     mark_as_advanced(LIB_EAY_LIBRARY_DEBUG LIB_EAY_LIBRARY_RELEASE
                      SSL_EAY_LIBRARY_DEBUG SSL_EAY_LIBRARY_RELEASE)
-    set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} )
-    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} )
-    set(OPENSSL_LIBRARIES ${SSL_EAY_LIBRARY} ${LIB_EAY_LIBRARY} )
+    set(OPENSSL_SSL_LIBRARY ${SSL_EAY_LIBRARY} crypt32)
+    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY_LIBRARY} crypt32)
+    set(OPENSSL_LIBRARIES ${SSL_EAY_LIBRARY} ${LIB_EAY_LIBRARY} crypt32)
   elseif(MINGW)
     # same player, for MinGW
     set(LIB_EAY_NAMES crypto libeay32)
@@ -227,9 +227,9 @@ if(WIN32 AND NOT CYGWIN)
     )
 
     mark_as_advanced(SSL_EAY LIB_EAY)
-    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
-    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
-    set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
+    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} crypt32)
+    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} crypt32)
+    set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} crypt32)
     unset(LIB_EAY_NAMES)
     unset(SSL_EAY_NAMES)
   else()
@@ -257,9 +257,9 @@ if(WIN32 AND NOT CYGWIN)
     )
 
     mark_as_advanced(SSL_EAY LIB_EAY)
-    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} )
-    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} )
-    set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} )
+    set(OPENSSL_SSL_LIBRARY ${SSL_EAY} crypt32)
+    set(OPENSSL_CRYPTO_LIBRARY ${LIB_EAY} crypt32)
+    set(OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} crypt32)
   endif()
 else()
 
@@ -290,10 +290,10 @@ else()
   mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
 
   # compat defines
-  set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
-  set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
+  set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${CMAKE_DL_LIBS})
+  set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} ${CMAKE_DL_LIBS})
 
-  set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
+  set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${CMAKE_DL_LIBS})
 
 endif()
 
@@ -394,6 +394,13 @@ if(OPENSSL_FOUND)
     add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
     set_target_properties(OpenSSL::Crypto PROPERTIES
       INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
+    if(WIN32 AND NOT CYGWIN)
+      set_target_properties(OpenSSL::Crypto PROPERTIES
+        INTERFACE_LINK_LIBRARIES crypt32)
+    else()
+      set_target_properties(OpenSSL::Crypto PROPERTIES
+        INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS}")
+    endif()
     if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
       set_target_properties(OpenSSL::Crypto PROPERTIES
         IMPORTED_LINK_INTERFACE_LANGUAGES "C"
@@ -445,6 +452,12 @@ if(OPENSSL_FOUND)
       set_target_properties(OpenSSL::SSL PROPERTIES
         INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
     endif()
+    if(WIN32 AND NOT CYGWIN)
+      set_property(TARGET OpenSSL::SSL APPEND PROPERTY
+	INTERFACE_LINK_LIBRARIES crypt32)
+    else()
+      set_property(TARGET OpenSSL::SSL APPEND PROPERTY
+	INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS}")
   endif()
 endif()
 
-- 
2.9.2

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to