Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ option(QUIC_SKIP_CI_CHECKS "Disable CI specific build checks" OFF)
option(QUIC_TELEMETRY_ASSERTS "Enable telemetry asserts in release builds" OFF)
option(QUIC_USE_SYSTEM_LIBCRYPTO "Use system libcrypto if quictls TLS" OFF)
option(QUIC_USE_EXTERNAL_OPENSSL "Use external OpenSSL instead of building from submodules" OFF)
set(QUIC_OPENSSL_DIR "" CACHE PATH "Path to OpenSSL directory")
set(QUIC_OPENSSL_INCLUDE_DIR "" CACHE PATH "Path to OpenSSL include directory")
set(QUIC_OPENSSL_LIB_DIR "" CACHE PATH "Path to OpenSSL library directory")
option(QUIC_HIGH_RES_TIMERS "Configure the system to use high resolution timers" OFF)
Expand Down Expand Up @@ -772,20 +773,38 @@ if(QUIC_TLS_LIB STREQUAL "quictls" OR QUIC_TLS_LIB STREQUAL "openssl")
add_library(OpenSSLQuic INTERFACE)
if(QUIC_OPENSSL_INCLUDE_DIR AND QUIC_OPENSSL_LIB_DIR)
target_include_directories(OpenSSLQuic INTERFACE ${QUIC_OPENSSL_INCLUDE_DIR})
find_library(LIB_CRYPTO NAMES crypto libcrypto PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
if(BUILD_SHARED_LIBS)
find_library(LIB_CRYPTO NAMES crypto libcrypto PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
else()
find_library(LIB_CRYPTO NAMES "crypto${CMAKE_STATIC_LIBRARY_SUFFIX}" "libcrypto${CMAKE_STATIC_LIBRARY_SUFFIX}" PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
endif()
if(NOT LIB_CRYPTO)
message(FATAL_ERROR "libcrypto not found in ${QUIC_OPENSSL_LIB_DIR}")
endif()
find_library(LIB_SSL NAMES ssl libssl PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
if(BUILD_SHARED_LIBS)
find_library(LIB_SSL NAMES ssl libssl PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
else()
find_library(LIB_SSL NAMES "ssl${CMAKE_STATIC_LIBRARY_SUFFIX}" "libssl${CMAKE_STATIC_LIBRARY_SUFFIX}" PATHS ${QUIC_OPENSSL_LIB_DIR} NO_DEFAULT_PATH)
endif()
if(NOT LIB_SSL)
message(FATAL_ERROR "libssl not found in ${QUIC_OPENSSL_LIB_DIR}")
endif()
target_link_libraries(OpenSSLQuic INTERFACE ${LIB_SSL} ${LIB_CRYPTO})
elseif(QUIC_OPENSSL_INCLUDE_DIR OR QUIC_OPENSSL_LIB_DIR)
message(FATAL_ERROR "Both QUIC_OPENSSL_INCLUDE_DIR and QUIC_OPENSSL_LIB_DIR must be set to select custom OpenSSL version.")
else()
if(QUIC_OPENSSL_DIR)
set(OPENSSL_ROOT_DIR "${QUIC_OPENSSL_DIR}")
endif()
if(NOT BUILD_SHARED_LIBS)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
find_package(OpenSSL 3.5.0 REQUIRED)
target_link_libraries(OpenSSLQuic INTERFACE OpenSSL::SSL OpenSSL::Crypto)
# OpenSSL::SSL and OpenSSL::Crypto imported targets include their dependencies such as zstd.
# However, these dependencies will be linked in src/platform/CMakeLists.txt,
# so link only the main OpenSSL targets here to avoid duplication.
target_include_directories(OpenSSLQuic INTERFACE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(OpenSSLQuic INTERFACE ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
endif()
add_library(MsQuic::OpenSSL ALIAS OpenSSLQuic)
else()
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ find = []
# This feature enables quictls on windows, and has no effect on linux.
# This feature enables openssl on windows, and has no effect on linux.
openssl = []
openssl-external = []
quictls = []
static = ["src"]
preview-api = []
Expand Down
18 changes: 15 additions & 3 deletions scripts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ fn cmake_build() {
let target = env::var("TARGET").unwrap().replace("\\", "/");
let out_dir = env::var("OUT_DIR").unwrap().replace("\\", "/");
// The output directory for the native MsQuic library.
let libdir = "/lib";
let full_out_dir = [out_dir, libdir.to_string()].join("");
let quic_output_dir = Path::new(&full_out_dir);
let quic_output_dir = Path::new(&out_dir).join("artifacts");

// Builds the native MsQuic and installs it into $OUT_DIR.
let mut config = Config::new(".");
Expand All @@ -50,6 +48,20 @@ fn cmake_build() {
config.define("QUIC_TLS_LIB", "quictls");
} else if cfg!(feature = "openssl") {
config.define("QUIC_TLS_LIB", "openssl");
} else if cfg!(feature = "openssl-external") {
config
.define("QUIC_TLS_LIB", "openssl")
.define("QUIC_USE_EXTERNAL_OPENSSL", "on");
if let Ok(openssl_dir) = std::env::var("OPENSSL_DIR") {
config.define("QUIC_OPENSSL_DIR", openssl_dir);
} else {
if let Ok(openssl_include_dir) = std::env::var("OPENSSL_INCLUDE_DIR") {
config.define("QUIC_OPENSSL_INCLUDE_DIR", openssl_include_dir);
}
if let Ok(openssl_lib_dir) = std::env::var("OPENSSL_LIB_DIR") {
config.define("QUIC_OPENSSL_LIB_DIR", openssl_lib_dir);
}
}
} else if cfg!(windows) {
config.define("QUIC_TLS_LIB", "schannel");
} else {
Expand Down