Bug #61619 ssl.cmake file is broken when using custom OpenSSL build
Submitted: 23 Jun 2011 20:18 Modified: 30 Aug 2012 14:02
Reporter: Quanah Gibson-Mount Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.5.13, 5.5.16 OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D2 (Serious)

[23 Jun 2011 20:18] Quanah Gibson-Mount
Description:
If you have OpenSSL installed in a custom path, for example:

/opt/zimbra/opensssl-1.0.0d

and you set CMAKE to use "system" OpenSSL and point CMAKE to your location:

/usr/bin/cmake . -DCMAKE_PREFIX_PATH=/opt/zimbra/openssl-1.0.0d -DWITH_SSL=system

CMAKE will fail with the following error:

-- Found OpenSSL: /opt/zimbra/openssl-1.0.0d/lib/libssl.so
-- Looking for SHA512_DIGEST_LENGTH
-- Looking for SHA512_DIGEST_LENGTH - not found.
CMake Error at cmake/ssl.cmake:83 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Use WITH_SSL=bundled to
  enable SSL support
Call Stack (most recent call first):
  CMakeLists.txt:248 (MYSQL_CHECK_SSL)

This is because the check for SHA512_DIGEST_LENGTH fails to tell gcc where to find the OpenSSL Header files that were found by FindOpenSSL.cmake.  Instead, ssl.cmake blindly assumes the headers are in the existing system headers path, and only updates the header location *after* this test.

How to repeat:
Follow the above

Suggested fix:
Fix the SHA512_DIGEST_LENGTH to add the headers location found by FindOpenSSL.cmake before running the check.
[17 Jul 2011 12:10] Valeriy Kravchuk
Verified with current mysql-5.5 on Mac OS X:

macbook-pro:mysql-5.5-work openxs$ cmake . -DCMAKE_PREFIX_PATH=/opt/local/var/macports/software/openssl/1.0.0d_0 -DWITH_SSL=system
-- MySQL 5.5.16
-- Found OpenSSL: /usr/lib/libssl.dylib;/usr/lib/libcrypto.dylib
-- Looking for SHA512_DIGEST_LENGTH
-- Looking for SHA512_DIGEST_LENGTH - not found.
CMake Error at cmake/ssl.cmake:83 (MESSAGE):
  Cannot find appropriate system libraries for SSL.  Use WITH_SSL=bundled to
  enable SSL support
Call Stack (most recent call first):
  CMakeLists.txt:255 (MYSQL_CHECK_SSL)

-- Performing Test HAVE_VISIBILITY_HIDDEN
-- Performing Test HAVE_VISIBILITY_HIDDEN - Success
-- C warning options: -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wdeclaration-after-statement
-- C++ warning options: -Wall -Wextra -Wunused -Wwrite-strings -Wno-strict-aliasing -Werror -Wno-unused-parameter -Woverloaded-virtual
-- Configuring incomplete, errors occurred!
[27 Oct 2011 8:58] Partha Dutta
I'm facing the same problem. Good news is I have found a potential solution. It compiles, but not tested yet. You will need to patch cmake/ssl.cmake:

--- mysql-5.5.17/cmake/ssl.cmake.orig      2011-10-27 00:44:11.000000000 -0700
+++ mysql-5.5.17/cmake/ssl.cmake   2011-10-27 00:44:52.000000000 -0700
@@ -64,11 +64,14 @@
     MYSQL_USE_BUNDLED_SSL()
   ELSEIF(WITH_SSL STREQUAL "system" OR WITH_SSL STREQUAL "yes")
     # Check for system library
-    SET(OPENSSL_FIND_QUIETLY TRUE)
+    #SET(OPENSSL_FIND_QUIETLY TRUE)
     INCLUDE(FindOpenSSL)
+    MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
+    MESSAGE(STATUS "OPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}")
     FIND_LIBRARY(CRYPTO_LIBRARY crypto)
     MARK_AS_ADVANCED(CRYPTO_LIBRARY)
     INCLUDE(CheckSymbolExists)
+    SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
     CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h"
                         HAVE_SHA512_DIGEST_LENGTH)
     IF(OPENSSL_FOUND AND CRYPTO_LIBRARY AND HAVE_SHA512_DIGEST_LENGTH)

And add the following options when running cmake to configure : -DCMAKE_INCLUDE_PATH=XXXX -DCMAKE_LIBRARY_PATH=XXX
[30 Aug 2012 14:02] Paul Dubois
Noted in 5.6.7, 5.7.0 changelogs.

The WITH_SSL option for CMake now accepts a path_name value that
indicates the path name to the OpenSSL installation to use. This can
be useful instead of a value of system when the CMake code detects an
older or incorrect installed OpenSSL version. (Another permitted way 
to do the same thing is to set the CMAKE_PREFIX_PATH option to
path_name.)
[5 Sep 2012 13:22] Paul Dubois
Noted in 5.6.8 changelog.

On Windows, many MySQL executables depend on the libeay32.dll and
ssleay32.dll SSL libraries at runtime. To ensure that the proper
versions of these libraries are found, the install process copies
them into the same directory as the executables.