From 64b0f0fdb6f8dd8a20d8e2ef8b517e664b02fab6 Mon Sep 17 00:00:00 2001 From: Jan Venekamp <1422460+jan2000@users.noreply.github.com> Date: Tue, 13 Aug 2024 20:30:21 +0200 Subject: [PATCH] cmake: add rustls --- CMake/Findrustls.cmake | 32 ++++++++++++++++++++++++++++++++ CMakeLists.txt | 16 ++++++++++++++++ lib/curl_config.h.cmake | 3 +++ 3 files changed, 51 insertions(+) create mode 100644 CMake/Findrustls.cmake diff --git a/CMake/Findrustls.cmake b/CMake/Findrustls.cmake new file mode 100644 index 00000000000000..359cb04cf6cba1 --- /dev/null +++ b/CMake/Findrustls.cmake @@ -0,0 +1,32 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) Daniel Stenberg, , et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at https://curl.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +# SPDX-License-Identifier: curl +# +########################################################################### +find_path(RUSTLS_INCLUDE_DIRS rustls.h) + +find_library(RUSTLS_LIBRARY rustls) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(rustls DEFAULT_MSG + RUSTLS_INCLUDE_DIRS RUSTLS_LIBRARY) + +mark_as_advanced(RUSTLS_INCLUDE_DIRS RUSTLS_LIBRARY) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee69fa238405ff..fcbfdbd7f01a58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,6 +457,7 @@ cmake_dependent_option(CURL_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF CURL_EN cmake_dependent_option(CURL_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) cmake_dependent_option(CURL_USE_WOLFSSL "Enable wolfSSL for SSL/TLS" OFF CURL_ENABLE_SSL OFF) cmake_dependent_option(CURL_USE_GNUTLS "Enable GnuTLS for SSL/TLS" OFF CURL_ENABLE_SSL OFF) +cmake_dependent_option(CURL_USE_RUSTLS "Enable rustls for SSL/TLS" OFF CURL_ENABLE_SSL OFF) set(_openssl_default ON) if(WIN32 OR CURL_USE_SECTRANSP OR CURL_USE_SCHANNEL OR CURL_USE_MBEDTLS OR CURL_USE_WOLFSSL) @@ -473,6 +474,7 @@ count_true(_enabled_ssl_options_count CURL_USE_BEARSSL CURL_USE_WOLFSSL CURL_USE_GNUTLS + CURL_USE_RUSTLS ) if(_enabled_ssl_options_count GREATER 1) set(CURL_WITH_MULTI_SSL ON) @@ -610,6 +612,19 @@ if(CURL_USE_GNUTLS) endif() endif() +if(CURL_USE_RUSTLS) + find_package(rustls REQUIRED) + set(_ssl_enabled ON) + set(USE_RUSTLS ON) + list(APPEND CURL_LIBS ${RUSTLS_LIBRARY}) + include_directories(${RUSTLS_INCLUDE_DIRS}) + + if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "rustls") + set(valid_default_ssl_backend TRUE) + endif() + set(curl_ca_bundle_supported TRUE) # TODO ? +endif() + if(CURL_DEFAULT_SSL_BACKEND AND NOT _valid_default_ssl_backend) message(FATAL_ERROR "CURL_DEFAULT_SSL_BACKEND '${CURL_DEFAULT_SSL_BACKEND}' not enabled.") endif() @@ -1860,6 +1875,7 @@ if(NOT CURL_DISABLE_INSTALL) _add_if("BearSSL" _ssl_enabled AND USE_BEARSSL) _add_if("wolfSSL" _ssl_enabled AND USE_WOLFSSL) _add_if("GnuTLS" _ssl_enabled AND USE_GNUTLS) + _add_if("rustls" _ssl_enabled AND USE_RUSTLS) if(_items) if(NOT CMAKE_VERSION VERSION_LESS 3.13) diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index aa89c600ddd48f..611e8dcffbd0c3 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -689,6 +689,9 @@ ${SIZEOF_TIME_T_CODE} /* if BearSSL is enabled */ #cmakedefine USE_BEARSSL 1 +/* if rustls is enabled */ +#cmakedefine USE_RUSTLS 1 + /* if wolfSSL is enabled */ #cmakedefine USE_WOLFSSL 1