1# Locate OpenSSL library
2#
3# For Windows and MacOSX we bundle our own version, but for the
4# other platforms we should search for a system-wide installed
5# version.
6#
7# This module defines
8#  OPENSSL_LIBRARIES, Library path and libs
9#  OPENSSL_INCLUDE_DIR, where to find the ICU headers
10
11SET(_openssl_exploded ${CMAKE_BINARY_DIR}/tlm/deps/openssl.exploded)
12set(_openssl_libraries "ssl;libssl32;ssleay32;crypto;libeay32")
13
14if (WIN32 OR APPLE)
15    find_path(OPENSSL_INCLUDE_DIR openssl/ssl.h
16              HINTS ${_openssl_exploded}
17              PATH_SUFFIXES include
18              NO_CMAKE_PATH
19              NO_CMAKE_ENVIRONMENT_PATH)
20
21    string(STRIP ${OPENSSL_INCLUDE_DIR} OPENSSL_INCLUDE_DIR)
22    foreach(_mylib ${_openssl_libraries})
23        unset(_the_lib CACHE)
24        find_library(_the_lib
25                     NAMES ${_mylib}
26                     HINTS ${CMAKE_INSTALL_PREFIX}/lib
27                     NO_DEFAULT_PATH)
28        if (_the_lib)
29            list(APPEND OPENSSL_LIBRARIES ${_the_lib})
30        endif (_the_lib)
31    endforeach(_mylib)
32else (WIN32 OR APPLE)
33    find_path(OPENSSL_INCLUDE_DIR openssl/ssl.h
34              HINTS ENV OPENSSL_DIR
35              PATH_SUFFIXES include
36              PATHS
37                 /usr/local
38                 /opt/local
39                 /opt/csw
40                 /opt/openssl
41                 /opt)
42
43    foreach (_mylib ${_openssl_libraries})
44        unset(_the_lib CACHE)
45        find_library(_the_lib
46                     NAMES ${_mylib}
47                     HINTS ENV OPENSSL_DIR
48                     PATHS
49                         /usr/local
50                         /opt/local
51                         /opt/csw
52                         /opt/openssl
53                         /opt)
54        if (_the_lib)
55            list(APPEND OPENSSL_LIBRARIES ${_the_lib})
56        endif (_the_lib)
57    endforeach (_mylib)
58
59    if (OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPT_LIBRARY)
60        set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPT_LIBRARY})
61    endif (OPENSSL_SSL_LIBRARY AND OPENSSL_CRYPT_LIBRARY)
62endif (WIN32 OR APPLE)
63
64if (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIR)
65    message(STATUS "Found OpenSSL headers in ${OPENSSL_INCLUDE_DIR}")
66    message(STATUS "Using OpenSSL libraries: ${OPENSSL_LIBRARIES}")
67else (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIR)
68  message(FATAL_ERROR "Can't build Couchbase without openssl")
69endif (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIR)
70
71set(OPENSSL_FOUND true)
72mark_as_advanced(OPENSSL_FOUND OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES)
73