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
231 changes: 88 additions & 143 deletions fizz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ endif()

project("fizz" VERSION ${PACKAGE_VERSION} LANGUAGES CXX C)

# Set for FetchContent to skip find_package(fizz)
set(fizz_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
CACHE INTERNAL "fizz source directory")

if (NOT DEFINED CPACK_GENERATOR)
set(CPACK_GENERATOR "RPM")
endif()
Expand Down Expand Up @@ -49,7 +53,10 @@ set(BIN_INSTALL_DIR bin CACHE STRING
set(CMAKE_INSTALL_DIR lib/cmake/fizz CACHE STRING
"The subdirectory where CMake package config files should be installed")

find_package(folly CONFIG REQUIRED)
# If folly is being built from source (FetchContent), skip find_package
if (NOT DEFINED folly_SOURCE_DIR)
find_package(folly CONFIG REQUIRED)
endif()
find_package(fmt CONFIG REQUIRED)

find_package(OpenSSL REQUIRED)
Expand Down Expand Up @@ -112,150 +119,89 @@ if(aegis_FOUND)
endif()

include(FizzOptions)
include(FizzSources)

configure_file(fizz-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/fizz/fizz-config.h)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/fizz/fizz-config.h DESTINATION ${INCLUDE_INSTALL_DIR}/fizz/)

set(FIZZ_HEADER_DIRS
backend
backend/liboqs
backend/openssl
backend/openssl/certificate
backend/openssl/crypto
backend/openssl/crypto/aead
backend/openssl/crypto/exchange
backend/openssl/crypto/signature
client
compression
crypto
crypto/aead
crypto/exchange
crypto/hpke
crypto/signature
crypto/openssl
experimental/crypto/exchange
experimental/ktls
experimental/util
extensions/clientpadding
extensions/delegatedcred
extensions/exportedauth
extensions/tokenbinding
protocol
protocol/clock
protocol/ech
record
server
util
tool
)

set(FIZZ_TEST_HEADER_DIRS
client/test
compression/test
crypto/aead/test
crypto/exchange/test
crypto/test
crypto/hpke/test
protocol/test
protocol/clock/test
protocol/ech/test
record/test
server/test
tool/test
util/test
test
)

foreach(dir ${FIZZ_HEADER_DIRS})
file(GLOB_RECURSE headers ${dir}/*.h)
set(FIZZ_HEADERS
${FIZZ_HEADERS}
${headers})
endforeach()

foreach(dir ${FIZZ_TEST_HEADER_DIRS})
file(GLOB_RECURSE headers ${dir}/*.h)
set(FIZZ_TEST_HEADERS
${FIZZ_TEST_HEADERS}
${headers})
endforeach()


add_library(fizz
${FIZZ_LIBRARY_SOURCES}
)

if (BUILD_SHARED_LIBS)
set_target_properties(fizz
PROPERTIES VERSION ${PACKAGE_VERSION})
endif()

get_filename_component(FIZZ_BASE_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE)

target_include_directories(
fizz
PUBLIC
include(FizzFunctions)

# Set the generated directory for FetchContent compatibility
set(FIZZ_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)

configure_file(fizz-config.h.in ${FIZZ_GENERATED_DIR}/fizz/fizz-config.h)
install(FILES ${FIZZ_GENERATED_DIR}/fizz/fizz-config.h
DESTINATION ${INCLUDE_INSTALL_DIR}/fizz/)

# Collect all headers via recursive glob (like folly does)
file(GLOB_RECURSE FIZZ_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
# Filter out test, facebook, and other non-public directories
list(FILTER FIZZ_HEADERS EXCLUDE REGEX "/test/")
list(FILTER FIZZ_HEADERS EXCLUDE REGEX "/facebook/")
list(FILTER FIZZ_HEADERS EXCLUDE REGEX "/buck_config/")
list(FILTER FIZZ_HEADERS EXCLUDE REGEX "/build/")

# Collect test headers separately
file(GLOB_RECURSE FIZZ_TEST_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
list(FILTER FIZZ_TEST_HEADERS INCLUDE REGEX "/test/")
list(FILTER FIZZ_TEST_HEADERS EXCLUDE REGEX "/facebook/")

# =============================================================================
# Configuration interface library (matches //fizz:config BUCK target)
# =============================================================================
get_filename_component(FIZZ_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. ABSOLUTE)

add_library(fizz_config INTERFACE)
target_include_directories(fizz_config
INTERFACE
$<BUILD_INTERFACE:${FIZZ_BASE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>
$<BUILD_INTERFACE:${FIZZ_GENERATED_DIR}>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
${FOLLY_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${sodium_INCLUDE_DIR}
${ZSTD_INCLUDE_DIR}
PRIVATE
${GLOG_INCLUDE_DIRS}
${FIZZ_INCLUDE_DIRECTORIES}
)


target_link_libraries(fizz
PUBLIC
${FOLLY_LIBRARIES}
${OPENSSL_LIBRARIES}
sodium
Threads::Threads
ZLIB::ZLIB
${ZSTD_LIBRARY}
PRIVATE
${GLOG_LIBRARIES}
${GFLAGS_LIBRARIES}
${FIZZ_LINK_LIBRARIES}
${CMAKE_DL_LIBS}
${LIBRT_LIBRARIES})

if (liboqs_FOUND)
target_link_libraries(fizz PRIVATE OQS::oqs)
endif()

if (aegis_FOUND)
target_link_libraries(fizz PRIVATE aegis::aegis)
endif()

if ($FIZZ_SHINY_DEPENDENCIES)
add_dependencies(fizz ${FIZZ_SHINY_DEPENDENCIES})
endif()

if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
# Work around C1128: number of sections exceeded object file format limit.
target_compile_options(fizz PUBLIC /bigobj)
endif()
install(TARGETS fizz_config EXPORT fizz-exports)
add_library(fizz::fizz_config ALIAS fizz_config)

# =============================================================================
# Build granular libraries from subdirectory CMakeLists.txt files
# Sources are compiled ONCE via OBJECT libraries, then reused for both
# granular .a files and the monolithic libfizz.a
# =============================================================================

# Order matters - dependencies must be added first
add_subdirectory(util)
add_subdirectory(protocol/clock)
add_subdirectory(protocol/ech)
add_subdirectory(record)
add_subdirectory(crypto)
add_subdirectory(crypto/aead)
add_subdirectory(crypto/exchange)
add_subdirectory(crypto/hpke)
add_subdirectory(protocol)
add_subdirectory(compression)
add_subdirectory(backend)
add_subdirectory(client)
add_subdirectory(server)
add_subdirectory(extensions/clientpadding)
add_subdirectory(extensions/delegatedcred)
add_subdirectory(extensions/exportedauth)
add_subdirectory(extensions/tokenbinding)
add_subdirectory(experimental/batcher)
add_subdirectory(experimental/client)
add_subdirectory(experimental/crypto)
add_subdirectory(experimental/ktls)
add_subdirectory(experimental/protocol)
add_subdirectory(experimental/server)
add_subdirectory(experimental/util)

# =============================================================================
# Create monolithic fizz library and resolve deferred dependencies
# =============================================================================
fizz_create_monolithic_library()
fizz_resolve_deferred_dependencies()

install(
TARGETS fizz
EXPORT fizz-exports
DESTINATION ${LIB_INSTALL_DIR}
)

# We unfortunately cannot install fizz's headers with the install()
# statement above. install(TARGETS) appears to only support installing
# PUBLIC_HEADER in a flat include directory, and not a deeper tree.
foreach(dir ${FIZZ_HEADER_DIRS})
get_filename_component(PARENT_DIR "/${dir}" DIRECTORY)
install(DIRECTORY ${dir} DESTINATION "${INCLUDE_INSTALL_DIR}/fizz${PARENT_DIR}"
FILES_MATCHING PATTERN "*.h"
PATTERN "test" EXCLUDE)
endforeach()
# Install headers preserving directory structure (using recursive glob like folly)
fizz_install_headers(fizz ${CMAKE_CURRENT_SOURCE_DIR} ${FIZZ_HEADERS})

# Install CMake package configuration files for fizz
include(CMakePackageConfigHelpers)
Expand Down Expand Up @@ -299,6 +245,11 @@ add_library(fizz_test_support
target_link_libraries(fizz_test_support
PUBLIC
fizz
Folly::folly_init_init
Folly::folly_testing_test_util
Folly::folly_executors_manual_executor
Folly::folly_io_async_scoped_event_base_thread
Folly::folly_detail_base64_detail_base64_api
)

# export fizz headers and targets for unit tests utils
Expand All @@ -310,14 +261,8 @@ install(
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
)

foreach(dir ${FIZZ_TEST_HEADER_DIRS})
get_filename_component(PARENT_DIR "/${dir}" DIRECTORY)
install(
DIRECTORY ${dir}
DESTINATION "${FIZZ_TEST_INSTALL_PREFIX}/include/fizz${PARENT_DIR}"
FILES_MATCHING PATTERN "*.h"
)
endforeach()
# Install test headers using recursive glob
fizz_install_headers(fizz ${CMAKE_CURRENT_SOURCE_DIR} ${FIZZ_TEST_HEADERS})

macro(add_gtest test_source test_name)
add_executable(${test_name} ${test_source} test/CMakeTestMain.cpp)
Expand Down
88 changes: 88 additions & 0 deletions fizz/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# NOTE: This file is manually maintained due to conditional libaegis/liboqs logic.

fizz_add_library(fizz_backend_libaegis
SRCS libaegis/AEGISCipher.cpp
EXPORTED_DEPS
fizz_config
fizz_crypto_aead_aead
fizz_crypto_aead_cryptoutil
fizz_crypto_crypto
Folly::folly_lang_checked_math
)
if (FIZZ_HAVE_LIBAEGIS)
if(BUILD_SHARED_LIBS)
target_link_libraries(fizz_backend_libaegis INTERFACE aegis::aegis)
else()
target_link_libraries(fizz_backend_libaegis PUBLIC aegis::aegis)
endif()
target_link_libraries(fizz_backend_libaegis_obj PUBLIC aegis::aegis)
endif()

fizz_add_library(fizz_backend_liboqs
SRCS liboqs/OQSKeyExchange.cpp
EXPORTED_DEPS
fizz_config
fizz_crypto_crypto
fizz_crypto_exchange_key_exchange
Folly::folly_memory
)
if (FIZZ_HAVE_OQS)
if(BUILD_SHARED_LIBS)
target_link_libraries(fizz_backend_liboqs INTERFACE OQS::oqs)
else()
target_link_libraries(fizz_backend_liboqs PUBLIC OQS::oqs)
endif()
target_link_libraries(fizz_backend_liboqs_obj PUBLIC OQS::oqs)
endif()

fizz_add_library(fizz_backend_openssl
SRCS
openssl/certificate/CertUtils.cpp
openssl/crypto/OpenSSLKeyUtils.cpp
openssl/crypto/Sha.cpp
openssl/crypto/aead/OpenSSLEVPCipher.cpp
openssl/crypto/exchange/OpenSSLKeyExchange.cpp
openssl/crypto/signature/Signature.cpp
EXPORTED_DEPS
fizz_compression_certificate_compressor
fizz_config
fizz_crypto_aead_aead
fizz_crypto_aead_cryptoutil
fizz_crypto_aead_iobuf
fizz_crypto_crypto
fizz_crypto_exchange_key_exchange
fizz_crypto_hasher
fizz_crypto_hkdf
fizz_protocol_certificate
fizz_record_record
Folly::folly_conv
Folly::folly_io_async_ssl_openssl_transport_certificate
Folly::folly_io_iobuf
Folly::folly_lang_assume
Folly::folly_lang_bits
Folly::folly_lang_checked_math
Folly::folly_memory
Folly::folly_portability_openssl
Folly::folly_range
Folly::folly_ssl_openssl_cert_utils
Folly::folly_ssl_openssl_hash
Folly::folly_ssl_openssl_ptr_types
Folly::folly_string
)

fizz_add_library(fizz_backend_libsodium
SRCS libsodium/crypto/exchange/X25519.cpp
EXPORTED_DEPS
fizz_crypto_crypto
fizz_crypto_exchange_key_exchange
Folly::folly_conv
Folly::folly_io_iobuf
Folly::folly_optional
Folly::folly_range
)
Loading
Loading