OpenSSL: Issue an error if OpenSSL is not found

When building with the built-in Curl, CMAKE_USE_OPENSSL is only set
to ON by default if an OpenSSL installation is detected. However, this
can cause the user to mistakenly build without OpenSSL support if
OpenSSL is not installed, because CMAKE_USE_OPENSSL is set to OFF in
that case. Always set CMAKE_USE_OPENSSL to ON by default on systems
where it could be available, skipping the initial detection, resulting
in an error when we try to use OpenSSL later on. Detect this error
and advise the user to either install OpenSSL or set CMAKE_USE_OPENSSL
to OFF.

Co-Authored-by: Brad King <brad.king@kitware.com>
This commit is contained in:
Kyle Edwards 2019-07-17 14:00:01 -04:00
parent e3bd5c5b66
commit dd3e476786
2 changed files with 7 additions and 5 deletions

View File

@ -429,10 +429,7 @@ macro (CMAKE_BUILD_UTILITIES)
set(_CMAKE_USE_OPENSSL_DEFAULT OFF)
if(NOT DEFINED CMAKE_USE_OPENSSL AND NOT WIN32 AND NOT APPLE
AND CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
find_package(OpenSSL QUIET)
if(OPENSSL_FOUND)
set(_CMAKE_USE_OPENSSL_DEFAULT ON)
endif()
set(_CMAKE_USE_OPENSSL_DEFAULT ON)
endif()
option(CMAKE_USE_OPENSSL "Use OpenSSL." ${_CMAKE_USE_OPENSSL_DEFAULT})
mark_as_advanced(CMAKE_USE_OPENSSL)

View File

@ -449,7 +449,12 @@ if(CMAKE_USE_SECTRANSP)
endif()
if(CMAKE_USE_OPENSSL)
find_package(OpenSSL REQUIRED)
find_package(OpenSSL)
if(NOT OpenSSL_FOUND)
message(FATAL_ERROR
"Could not find OpenSSL. Install an OpenSSL development package or "
"configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.")
endif()
set(SSL_ENABLED ON)
set(USE_OPENSSL ON)
set(HAVE_LIBCRYPTO ON)