1
# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; version 2 of the License.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16
# We support different versions of SSL:
17
# - "bundled" uses source code in <source dir>/extra/yassl
18
# - "system" (typically) uses headers/libraries in /usr/lib and /usr/lib64
19
# - a custom installation of openssl can be used like this
20
# - cmake -DCMAKE_PREFIX_PATH=</path/to/custom/openssl> -DWITH_SSL="system"
22
# - cmake -DWITH_SSL=</path/to/custom/openssl>
24
# The default value for WITH_SSL is "bundled"
25
# set in cmake/build_configurations/feature_set.cmake
27
# For custom build/install of openssl, see the accompanying README and
28
# INSTALL* files. When building with gcc, you must build the shared libraries
29
# (in addition to the static ones):
30
# ./config --prefix=</path/to/custom/openssl> --shared; make; make install
31
# On some platforms (mac) you need to choose 32/64 bit architecture.
32
# Build/Install of openssl on windows is slightly different: you need to run
33
# perl and nmake. You might also need to
34
# 'set path=</path/to/custom/openssl>\bin;%PATH%
35
# in order to find the .dll files at runtime.
37
SET(WITH_SSL_DOC "bundled (use yassl)")
39
"${WITH_SSL_DOC}, yes (prefer os library if present, otherwise use bundled)")
41
"${WITH_SSL_DOC}, system (use os library)")
43
"${WITH_SSL_DOC}, </path/to/custom/installation>")
45
MACRO (CHANGE_SSL_SETTINGS string)
46
SET(WITH_SSL ${string} CACHE STRING ${WITH_SSL_DOC} FORCE)
49
MACRO (MYSQL_USE_BUNDLED_SSL)
51
${CMAKE_SOURCE_DIR}/extra/yassl/include
52
${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/include
54
SET(SSL_LIBRARIES yassl taocrypt)
55
SET(SSL_INCLUDE_DIRS ${INC_DIRS})
56
SET(SSL_INTERNAL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/mySTL)
57
SET(SSL_DEFINES "-DHAVE_YASSL -DYASSL_PREFIX -DHAVE_OPENSSL -DMULTI_THREADED")
58
CHANGE_SSL_SETTINGS("bundled")
59
ADD_SUBDIRECTORY(extra/yassl)
60
ADD_SUBDIRECTORY(extra/yassl/taocrypt)
61
GET_TARGET_PROPERTY(src yassl SOURCES)
63
SET(SSL_SOURCES ${SSL_SOURCES} ${CMAKE_SOURCE_DIR}/extra/yassl/${file})
65
GET_TARGET_PROPERTY(src taocrypt SOURCES)
67
SET(SSL_SOURCES ${SSL_SOURCES}
68
${CMAKE_SOURCE_DIR}/extra/yassl/taocrypt/${file})
74
# Provides the following configure options:
75
# WITH_SSL=[yes|bundled|system|<path/to/custom/installation>]
76
MACRO (MYSQL_CHECK_SSL)
79
CHANGE_SSL_SETTINGS("bundled")
83
# See if WITH_SSL is of the form </path/to/custom/installation>
84
FILE(GLOB WITH_SSL_HEADER ${WITH_SSL}/include/openssl/ssl.h)
86
SET(WITH_SSL_PATH ${WITH_SSL} CACHE PATH "path to custom SSL installation")
89
IF(WITH_SSL STREQUAL "bundled")
90
MYSQL_USE_BUNDLED_SSL()
91
# Reset some variables, in case we switch from /path/to/ssl to "bundled".
94
UNSET(WITH_SSL_PATH CACHE)
97
UNSET(OPENSSL_ROOT_DIR)
98
UNSET(OPENSSL_ROOT_DIR CACHE)
100
IF (OPENSSL_INCLUDE_DIR)
101
UNSET(OPENSSL_INCLUDE_DIR)
102
UNSET(OPENSSL_INCLUDE_DIR CACHE)
104
IF (WIN32 AND OPENSSL_APPLINK_C)
105
UNSET(OPENSSL_APPLINK_C)
106
UNSET(OPENSSL_APPLINK_C CACHE)
109
UNSET(OPENSSL_LIBRARY)
110
UNSET(OPENSSL_LIBRARY CACHE)
113
UNSET(CRYPTO_LIBRARY)
114
UNSET(CRYPTO_LIBRARY CACHE)
116
ELSEIF(WITH_SSL STREQUAL "system" OR
117
WITH_SSL STREQUAL "yes" OR
120
# First search in WITH_SSL_PATH.
121
FIND_PATH(OPENSSL_ROOT_DIR
122
NAMES include/openssl/ssl.h
124
NO_CMAKE_ENVIRONMENT_PATH
125
HINTS ${WITH_SSL_PATH}
127
# Then search in standard places (if not found above).
128
FIND_PATH(OPENSSL_ROOT_DIR
129
NAMES include/openssl/ssl.h
132
FIND_PATH(OPENSSL_INCLUDE_DIR
134
HINTS ${OPENSSL_ROOT_DIR}/include
138
FIND_FILE(OPENSSL_APPLINK_C
139
NAMES openssl/applink.c
140
HINTS ${OPENSSL_ROOT_DIR}/include
142
MESSAGE(STATUS "OPENSSL_APPLINK_C ${OPENSSL_APPLINK_C}")
145
# On mac this list is <.dylib;.so;.a>
146
# We prefer static libraries, so we revert it here.
148
LIST(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
149
MESSAGE(STATUS "suffixes <${CMAKE_FIND_LIBRARY_SUFFIXES}>")
151
FIND_LIBRARY(OPENSSL_LIBRARY
152
NAMES ssl ssleay32 ssleay32MD
153
HINTS ${OPENSSL_ROOT_DIR}/lib)
154
FIND_LIBRARY(CRYPTO_LIBRARY
155
NAMES crypto libeay32
156
HINTS ${OPENSSL_ROOT_DIR}/lib)
158
LIST(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES)
161
# Verify version number. Version information looks like:
162
# #define OPENSSL_VERSION_NUMBER 0x1000103fL
163
# Encoded as MNNFFPPS: major minor fix patch status
164
FILE(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h"
165
OPENSSL_VERSION_NUMBER
166
REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x[0-9].*"
169
"^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9]).*$" "\\1"
170
OPENSSL_MAJOR_VERSION "${OPENSSL_VERSION_NUMBER}"
173
IF(OPENSSL_INCLUDE_DIR AND
176
OPENSSL_MAJOR_VERSION STREQUAL "1"
178
SET(OPENSSL_FOUND TRUE)
180
SET(OPENSSL_FOUND FALSE)
183
# If we are invoked with -DWITH_SSL=/path/to/custom/openssl
184
# and we have found static libraries, then link them statically
185
# into our executables and libraries.
186
# Adding IMPORTED_LOCATION allows MERGE_STATIC_LIBS
187
# to get LOCATION and do correct dependency analysis.
188
SET(MY_CRYPTO_LIBRARY "${CRYPTO_LIBRARY}")
189
SET(MY_OPENSSL_LIBRARY "${OPENSSL_LIBRARY}")
191
GET_FILENAME_COMPONENT(CRYPTO_EXT "${CRYPTO_LIBRARY}" EXT)
192
GET_FILENAME_COMPONENT(OPENSSL_EXT "${OPENSSL_LIBRARY}" EXT)
193
IF (CRYPTO_EXT STREQUAL ".a")
194
SET(MY_CRYPTO_LIBRARY imported_crypto)
195
ADD_LIBRARY(imported_crypto STATIC IMPORTED)
196
SET_TARGET_PROPERTIES(imported_crypto
197
PROPERTIES IMPORTED_LOCATION "${CRYPTO_LIBRARY}")
199
IF (OPENSSL_EXT STREQUAL ".a")
200
SET(MY_OPENSSL_LIBRARY imported_openssl)
201
ADD_LIBRARY(imported_openssl STATIC IMPORTED)
202
SET_TARGET_PROPERTIES(imported_openssl
203
PROPERTIES IMPORTED_LOCATION "${OPENSSL_LIBRARY}")
207
MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
208
MESSAGE(STATUS "OPENSSL_LIBRARY = ${OPENSSL_LIBRARY}")
209
MESSAGE(STATUS "CRYPTO_LIBRARY = ${CRYPTO_LIBRARY}")
210
MESSAGE(STATUS "OPENSSL_MAJOR_VERSION = ${OPENSSL_MAJOR_VERSION}")
212
INCLUDE(CheckSymbolExists)
213
SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
214
CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h"
215
HAVE_SHA512_DIGEST_LENGTH)
216
IF(OPENSSL_FOUND AND HAVE_SHA512_DIGEST_LENGTH)
218
SET(SSL_LIBRARIES ${MY_OPENSSL_LIBRARY} ${MY_CRYPTO_LIBRARY})
219
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
220
SET(SSL_LIBRARIES ${SSL_LIBRARIES} ${LIBSOCKET})
222
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
223
SET(SSL_LIBRARIES ${SSL_LIBRARIES} ${LIBDL})
225
MESSAGE(STATUS "SSL_LIBRARIES = ${SSL_LIBRARIES}")
226
SET(SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
227
SET(SSL_INTERNAL_INCLUDE_DIRS "")
228
SET(SSL_DEFINES "-DHAVE_OPENSSL")
230
IF(WITH_SSL STREQUAL "system")
231
MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support")
233
MYSQL_USE_BUNDLED_SSL()
237
"Wrong option for WITH_SSL. Valid values are : "${WITH_SSL_DOC})
242
# Many executables will depend on libeay32.dll and ssleay32.dll at runtime.
243
# In order to ensure we find the right version(s), we copy them into
244
# the same directory as the executables.
245
# NOTE: Using dlls will likely crash in malloc/free,
246
# see INSTALL.W32 which comes with the openssl sources.
247
# So we should be linking static versions of the libraries.
248
MACRO (COPY_OPENSSL_DLLS target_name)
249
IF (WIN32 AND WITH_SSL_PATH)
250
GET_FILENAME_COMPONENT(CRYPTO_NAME "${CRYPTO_LIBRARY}" NAME_WE)
251
GET_FILENAME_COMPONENT(OPENSSL_NAME "${OPENSSL_LIBRARY}" NAME_WE)
252
FILE(GLOB HAVE_CRYPTO_DLL "${WITH_SSL_PATH}/bin/${CRYPTO_NAME}.dll")
253
FILE(GLOB HAVE_OPENSSL_DLL "${WITH_SSL_PATH}/bin/${OPENSSL_NAME}.dll")
254
IF (HAVE_CRYPTO_DLL AND HAVE_OPENSSL_DLL)
255
ADD_CUSTOM_COMMAND(OUTPUT ${target_name}
256
COMMAND ${CMAKE_COMMAND} -E copy_if_different
257
"${WITH_SSL_PATH}/bin/${CRYPTO_NAME}.dll"
258
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CRYPTO_NAME}.dll"
259
COMMAND ${CMAKE_COMMAND} -E copy_if_different
260
"${WITH_SSL_PATH}/bin/${OPENSSL_NAME}.dll"
261
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${OPENSSL_NAME}.dll"
263
ADD_CUSTOM_TARGET(${target_name} ALL)