1 2if(OPENSSL_FOUND) 3 4 find_program(OPENSSL_EXECUTABLE openssl openssl.exe bin/openssl.exe 5 HINTS ${_OPENSSL_ROOT_HINTS} 6 PATH 7 /usr/bin/ 8 bin/ 9 DOC "Openssl executable") 10 11 mark_as_advanced(OPENSSL_EXECUTABLE) 12 13 # On Windows, we need to copy the OpenSSL dlls 14 # to the output directory. 15 # BUT only if non-static libs (referencing dlls) are used 16 # In this case 17 # ** we only want to find dlls that are compatible with the libs 18 # the assumption is that these are part of the same OpenSSL package 19 # and typically reside in the same or in a close by directory as the executable 20 # ** we do NOT want to find dlls in general dll directories such as C:\Windows\systemXX 21 # because these IN GENERAL are not compatible with the libs 22 if (WIN32 AND OPENSSL_VERSION) 23 set(OPENSSL_BIN_FOUND 0) 24 25 # we check for OpenSSL versioning, as described in https://wiki.openssl.org/index.php/Versioning 26 string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.(.*)$" REGEX_MATCH ${OPENSSL_VERSION}) 27 28 if (NOT ${REGEX_MATCH} EQUAL "") 29 30 message(DEBUG "Assuming OpenSSL release ${OPENSSL_VERSION} >= 1.1.0 for dll discovery") 31 32 # the regex matched - so we assume OpenSSL release >= 1.1 33 set(OVNR "${CMAKE_MATCH_1}") # OpenSSL version number 34 set(ORNR "${CMAKE_MATCH_2}") # OpenSSL release number 35 set(CRYPTO32_NAME "libcrypto-${OVNR}_${ORNR}.dll") 36 set(CRYPTO64_NAME "libcrypto-${OVNR}_${ORNR}-x64.dll") 37 message(VERBOSE "CRYPTO32_NAME=${CRYPTO32_NAME}") 38 message(VERBOSE "CRYPTO64_NAME=${CRYPTO64_NAME}") 39 set(SSL32_NAME "libssl-${OVNR}_${ORNR}.dll") 40 set(SSL64_NAME "libssl-${OVNR}_${ORNR}-x64.dll") 41 message(VERBOSE "SSL32_NAME=${SSL32_NAME}") 42 message(VERBOSE "SSL64_NAME=${SSL64_NAME}") 43 44 get_filename_component(OPENSSL_EXECUTABLE_PATH ${OPENSSL_EXECUTABLE} DIRECTORY) 45 message(VERBOSE "OPENSSL_EXECUTABLE_PATH=${OPENSSL_EXECUTABLE_PATH}") 46 set(OPENSSL_EXECUTABLE_BIN_PATH "") 47 string(REGEX MATCH "^(.*)/tools/openssl$" REGEX_MATCH ${OPENSSL_EXECUTABLE_PATH}) 48 message(DEBUG "REGEX_MATCH=\"${REGEX_MATCH}\"") 49 message(DEBUG "CMAKE_MATCH_1=\"${CMAKE_MATCH_1}\"") 50 if (NOT ${REGEX_MATCH} EQUAL "") 51 set(OPENSSL_EXECUTABLE_BIN_PATH "${CMAKE_MATCH_1}/bin") # bin path of this openssl variant 52 endif() 53 message(VERBOSE "OPENSSL_EXECUTABLE_BIN_PATH=${OPENSSL_EXECUTABLE_BIN_PATH}") 54 55 unset(LIBCRYPTO_BIN) # clear 56 unset(LIBCRYPTO_BIN CACHE) # clear as well, because otherwise find_file might use it 57 find_file(LIBCRYPTO_BIN 58 NO_DEFAULT_PATH 59 NAMES ${CRYPTO32_NAME} ${CRYPTO64_NAME} 60 PATHS ${OPENSSL_EXECUTABLE_PATH} ${OPENSSL_EXECUTABLE_BIN_PATH} 61 ) 62 message(VERBOSE "LIBCRYPTO_BIN=${LIBCRYPTO_BIN}") 63 64 unset(LIBSSL_BIN) # clear 65 unset(LIBSSL_BIN CACHE) # clear as well, because otherwise find_file might use it 66 find_file(LIBSSL_BIN 67 NO_DEFAULT_PATH 68 NAMES ${SSL32_NAME} ${SSL64_NAME} 69 PATHS ${OPENSSL_EXECUTABLE_PATH} ${OPENSSL_EXECUTABLE_BIN_PATH} 70 ) 71 message(VERBOSE "LIBSSL_BIN=${LIBSSL_BIN}") 72 73 else() # the version regex did not match 74 75 # as a fallback, we check for "old" OpenSSL library (used before OpenSSL 1.1.0) 76 77 find_file(LIBCRYPTO_BIN 78 NAMES 79 libeay32.dll 80 HINTS 81 ${_OPENSSL_ROOT_HINTS} 82 PATH_SUFFIXES 83 bin) 84 85 find_file(LIBSSL_BIN 86 NAMES 87 ssleay32.dll 88 HINTS 89 ${_OPENSSL_ROOT_HINTS} 90 PATH_SUFFIXES 91 bin) 92 93 endif() 94 95 if(LIBCRYPTO_BIN AND LIBSSL_BIN) 96 set(OPENSSL_BIN_FOUND 1) 97 endif() 98 99 endif(WIN32 AND OPENSSL_VERSION) 100 101endif(OPENSSL_FOUND) 102 103