|
|
@@ -2,11 +2,15 @@
|
|
|
Build options:
|
|
|
* Standard BUILD_SHARED_LIBS is supported and sets HTTPLIB_SHARED default value.
|
|
|
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
|
|
|
+ * HTTPLIB_USE_WOLFSSL_IF_AVAILABLE (default off)
|
|
|
+ * HTTPLIB_USE_MBEDTLS_IF_AVAILABLE (default off)
|
|
|
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
|
|
|
* HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
|
|
|
* HTTPLIB_USE_ZSTD_IF_AVAILABLE (default on)
|
|
|
* HTTPLIB_BUILD_MODULES (default off)
|
|
|
* HTTPLIB_REQUIRE_OPENSSL (default off)
|
|
|
+ * HTTPLIB_REQUIRE_WOLFSSL (default off)
|
|
|
+ * HTTPLIB_REQUIRE_MBEDTLS (default off)
|
|
|
* HTTPLIB_REQUIRE_ZLIB (default off)
|
|
|
* HTTPLIB_REQUIRE_BROTLI (default off)
|
|
|
* HTTPLIB_REQUIRE_ZSTD (default off)
|
|
|
@@ -21,7 +25,7 @@
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
- After installation with Cmake, a find_package(httplib COMPONENTS OpenSSL ZLIB Brotli zstd) is available.
|
|
|
+ After installation with Cmake, a find_package(httplib COMPONENTS OpenSSL wolfssl MbedTLS ZLIB Brotli zstd) is available.
|
|
|
This creates a httplib::httplib target (if found and if listed components are supported).
|
|
|
It can be linked like so:
|
|
|
|
|
|
@@ -48,6 +52,8 @@
|
|
|
These variables are available after you run find_package(httplib)
|
|
|
* HTTPLIB_HEADER_PATH - this is the full path to the installed header (e.g. /usr/include/httplib.h).
|
|
|
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
|
|
|
+ * HTTPLIB_IS_USING_WOLFSSL - a bool for if wolfSSL support is enabled.
|
|
|
+ * HTTPLIB_IS_USING_MBEDTLS - a bool for if MbedTLS support is enabled.
|
|
|
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
|
|
|
* HTTPLIB_IS_USING_BROTLI - a bool for if Brotli support is enabled.
|
|
|
* HTTPLIB_IS_USING_ZSTD - a bool for if ZSTD support is enabled.
|
|
|
@@ -95,10 +101,14 @@ set(_HTTPLIB_OPENSSL_MIN_VER "3.0.0")
|
|
|
option(HTTPLIB_NO_EXCEPTIONS "Disable the use of C++ exceptions" OFF)
|
|
|
# Allow for a build to require OpenSSL to pass, instead of just being optional
|
|
|
option(HTTPLIB_REQUIRE_OPENSSL "Requires OpenSSL to be found & linked, or fails build." OFF)
|
|
|
+option(HTTPLIB_REQUIRE_WOLFSSL "Requires wolfSSL to be found & linked, or fails build." OFF)
|
|
|
+option(HTTPLIB_REQUIRE_MBEDTLS "Requires MbedTLS to be found & linked, or fails build." OFF)
|
|
|
option(HTTPLIB_REQUIRE_ZLIB "Requires ZLIB to be found & linked, or fails build." OFF)
|
|
|
# Allow for a build to casually enable OpenSSL/ZLIB support, but silently continue if not found.
|
|
|
# Make these options so their automatic use can be specifically disabled (as needed)
|
|
|
option(HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable HTTPS support." ON)
|
|
|
+option(HTTPLIB_USE_WOLFSSL_IF_AVAILABLE "Uses wolfSSL (if available) to enable HTTPS support." OFF)
|
|
|
+option(HTTPLIB_USE_MBEDTLS_IF_AVAILABLE "Uses MbedTLS (if available) to enable HTTPS support." OFF)
|
|
|
option(HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable Zlib compression support." ON)
|
|
|
# Lets you compile the program as a regular library instead of header-only
|
|
|
option(HTTPLIB_COMPILE "If ON, uses a Python script to split the header into a compilable header & source file (requires Python v3)." OFF)
|
|
|
@@ -120,6 +130,23 @@ else()
|
|
|
message(WARNING "HTTPLIB_BUILD_MODULES requires CMake 3.28 or later. Current version is ${CMAKE_VERSION}. Modules support has been disabled.")
|
|
|
endif()
|
|
|
endif()
|
|
|
+
|
|
|
+# Incompatibility between TLS libraries
|
|
|
+set(TLS_LIBRARIES_USED_TMP 0)
|
|
|
+
|
|
|
+foreach(tls_library OPENSSL WOLFSSL MBEDTLS)
|
|
|
+ set(TLS_REQUIRED ${HTTPLIB_REQUIRE_${tls_library}})
|
|
|
+ set(TLS_IF_AVAILABLE ${HTTPLIB_USE_${tls_library}_IF_AVAILABLE})
|
|
|
+
|
|
|
+ if(TLS_REQUIRED OR TLS_IF_AVAILABLE)
|
|
|
+ math(EXPR TLS_LIBRARIES_USED_TMP "${TLS_LIBRARIES_USED_TMP} + 1")
|
|
|
+ endif()
|
|
|
+endforeach()
|
|
|
+
|
|
|
+if(TLS_LIBRARIES_USED_TMP GREATER 1)
|
|
|
+ message(FATAL_ERROR "TLS libraries are mutually exclusive.")
|
|
|
+endif()
|
|
|
+
|
|
|
# Defaults to static library but respects standard BUILD_SHARED_LIBS if set
|
|
|
include(CMakeDependentOption)
|
|
|
cmake_dependent_option(HTTPLIB_SHARED "Build the library as a shared library instead of static. Has no effect if using header-only."
|
|
|
@@ -139,7 +166,7 @@ endif()
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
|
|
if(CMAKE_SYSTEM_VERSION)
|
|
|
if(${CMAKE_SYSTEM_VERSION} VERSION_LESS "10.0.0")
|
|
|
- message(SEND_ERROR "Windows ${CMAKE_SYSTEM_VERSION} or lower is not supported. Please use Windows 10 or later.")
|
|
|
+ message(WARNING "Windows ${CMAKE_SYSTEM_VERSION} or lower is not supported. Please use Windows 10 or later.")
|
|
|
endif()
|
|
|
else()
|
|
|
set(CMAKE_SYSTEM_VERSION "10.0.19041.0")
|
|
|
@@ -176,6 +203,22 @@ elseif(HTTPLIB_USE_OPENSSL_IF_AVAILABLE)
|
|
|
endif()
|
|
|
endif()
|
|
|
|
|
|
+if(HTTPLIB_REQUIRE_WOLFSSL)
|
|
|
+ find_package(wolfssl REQUIRED)
|
|
|
+ set(HTTPLIB_IS_USING_WOLFSSL TRUE)
|
|
|
+elseif(HTTPLIB_USE_WOLFSSL_IF_AVAILABLE)
|
|
|
+ find_package(wolfssl QUIET)
|
|
|
+ set(HTTPLIB_IS_USING_WOLFSSL ${wolfssl_FOUND})
|
|
|
+endif()
|
|
|
+
|
|
|
+if(HTTPLIB_REQUIRE_MBEDTLS)
|
|
|
+ find_package(MbedTLS REQUIRED)
|
|
|
+ set(HTTPLIB_IS_USING_MBEDTLS TRUE)
|
|
|
+elseif(HTTPLIB_USE_MBEDTLS_IF_AVAILABLE)
|
|
|
+ find_package(MbedTLS QUIET)
|
|
|
+ set(HTTPLIB_IS_USING_MBEDTLS ${MbedTLS_FOUND})
|
|
|
+endif()
|
|
|
+
|
|
|
if(HTTPLIB_REQUIRE_ZLIB)
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
set(HTTPLIB_IS_USING_ZLIB TRUE)
|
|
|
@@ -330,6 +373,8 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_ZSTD}>:zstd::libzstd>
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:OpenSSL::SSL>
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:OpenSSL::Crypto>
|
|
|
+ $<$<BOOL:${HTTPLIB_IS_USING_WOLFSSL}>:wolfssl::wolfssl>
|
|
|
+ $<$<BOOL:${HTTPLIB_IS_USING_MBEDTLS}>:MbedTLS::mbedtls>
|
|
|
)
|
|
|
|
|
|
# Set the definitions to enable optional features
|
|
|
@@ -339,6 +384,8 @@ target_compile_definitions(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_ZLIB}>:CPPHTTPLIB_ZLIB_SUPPORT>
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_ZSTD}>:CPPHTTPLIB_ZSTD_SUPPORT>
|
|
|
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:CPPHTTPLIB_OPENSSL_SUPPORT>
|
|
|
+ $<$<BOOL:${HTTPLIB_IS_USING_WOLFSSL}>:CPPHTTPLIB_WOLFSSL_SUPPORT>
|
|
|
+ $<$<BOOL:${HTTPLIB_IS_USING_MBEDTLS}>:CPPHTTPLIB_MBEDTLS_SUPPORT>
|
|
|
$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_DISABLE_MACOSX_AUTOMATIC_ROOT_CERTIFICATES}>>:CPPHTTPLIB_DISABLE_MACOSX_AUTOMATIC_ROOT_CERTIFICATES>
|
|
|
$<$<BOOL:${HTTPLIB_USE_NON_BLOCKING_GETADDRINFO}>:CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO>
|
|
|
)
|