| ####################### | |
| # | |
| # Licensed to the Apache Software Foundation (ASF) under one or more contributor license | |
| # agreements. See the NOTICE file distributed with this work for additional information regarding | |
| # copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 | |
| # (the "License"); you may not use this file except in compliance with the License. You may obtain | |
| # a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software distributed under the License | |
| # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| # or implied. See the License for the specific language governing permissions and limitations under | |
| # the License. | |
| # | |
| ####################### | |
| # Adjust default RelWithDebInfo flags to be in line with "Release with Debug". | |
| # The default RelWithDebInfo uses -O2, but Release uses -O3. This difference can be astonishing to users | |
| set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") | |
| if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) | |
| message(FATAL_ERROR "In source builds are disabled. Use a preset, -B or run from a different directory") | |
| endif() | |
| cmake_minimum_required(VERSION 3.20..3.27) | |
| project(ats VERSION 11.0.0) | |
| set(TS_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) | |
| set(TS_VERSION_MINOR ${PROJECT_VERSION_MINOR}) | |
| set(TS_VERSION_MICRO ${PROJECT_VERSION_PATCH}) | |
| set(TS_VERSION_STRING ${TS_VERSION_MAJOR}.${TS_VERSION_MINOR}.${TS_VERSION_MICRO} CACHE STRING "The version string") | |
| math(EXPR TS_VERSION_NUMBER "${TS_VERSION_MAJOR} * 1000000 + ${TS_VERSION_MINOR} * 1000 + ${TS_VERSION_MICRO}") | |
| # We make this a cache entry so that it can be configured to different values | |
| # for testing purposes. For example, it can be used on CI to check compatibility | |
| # with a newer standard than what our codebase currently has to comply with. | |
| set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to compile with (default 20)") | |
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
| set(CMAKE_CXX_EXTENSIONS OFF) | |
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | |
| list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE -DATS_BUILD) | |
| # Setup default install directory | |
| if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) | |
| set(CMAKE_INSTALL_PREFIX /usr/local/trafficserver CACHE PATH "Default install path" FORCE) | |
| endif() | |
| include(layout) | |
| include(ClangTidy) | |
| if(CMAKE_BUILD_TYPE STREQUAL "Debug") | |
| add_compile_definitions(DEBUG _DEBUG) | |
| endif() | |
| # ATS uses "unix" for variable names. Make sure its not defined | |
| remove_definitions(-Dunix) | |
| # Gather some environment info | |
| string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} HOST_OS) | |
| set(BUILD_NUMBER "0" CACHE STRING "The build number") | |
| execute_process(COMMAND id -nu OUTPUT_VARIABLE BUILD_PERSON OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| execute_process(COMMAND id -ng OUTPUT_VARIABLE BUILD_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| execute_process(COMMAND uname -n OUTPUT_VARIABLE BUILD_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| # Detect git common directory (works for both regular repos and worktrees). | |
| if(EXISTS ${CMAKE_SOURCE_DIR}/.git) | |
| execute_process( | |
| COMMAND git rev-parse --git-common-dir | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| OUTPUT_VARIABLE GIT_COMMON_DIR OUTPUT_STRIP_TRAILING_WHITESPACE | |
| RESULT_VARIABLE GIT_RESULT ERROR_QUIET | |
| ) | |
| if(GIT_RESULT EQUAL 0 AND GIT_COMMON_DIR) | |
| # Convert to absolute path if relative. | |
| if(NOT IS_ABSOLUTE ${GIT_COMMON_DIR}) | |
| get_filename_component(GIT_COMMON_DIR "${CMAKE_SOURCE_DIR}/${GIT_COMMON_DIR}" ABSOLUTE) | |
| endif() | |
| message(STATUS "Git common directory: ${GIT_COMMON_DIR}") | |
| endif() | |
| endif() | |
| # Options | |
| include(AutoOptionHelpers) | |
| find_package(PkgConfig) | |
| auto_option(HWLOC FEATURE_VAR TS_USE_HWLOC PACKAGE_DEPENDS hwloc) | |
| auto_option(JEMALLOC FEATURE_VAR TS_HAS_JEMALLOC DEFAULT OFF PACKAGE_DEPENDS jemalloc) | |
| auto_option(MIMALLOC FEATURE_VAR TS_HAS_MIMALLOC DEFAULT OFF PACKAGE_DEPENDS mimalloc) | |
| auto_option(POSIX_CAP FEATURE_VAR TS_USE_POSIX_CAP PACKAGE_DEPENDS cap HEADER_DEPENDS "sys/prctl.h") | |
| auto_option(LUAJIT PACKAGE_DEPENDS luajit) | |
| auto_option(UNWIND FEATURE_VAR TS_USE_REMOTE_UNWINDING PACKAGE_DEPENDS unwind) | |
| option(ENABLE_ASAN "Use address sanitizer (default OFF)") | |
| option(ENABLE_TSAN "Use thread sanitizer (default OFF)") | |
| option(ENABLE_UBSAN "Use undefined behavior sanitizer (default OFF)") | |
| option(ENABLE_FUZZING "Enable fuzzing (default OFF)") | |
| option(ENABLE_FIPS "Enable fips compliance (default OFF)") | |
| option(ENABLE_EVENT_TRACKER "Enable event tracking (default OFF)") | |
| option(BUILD_REGRESSION_TESTING "Build regression tests (default ON)" ON) | |
| option(BUILD_EXPERIMENTAL_PLUGINS "Build the experimental plugins (default OFF)") | |
| set(DEFAULT_STACK_SIZE 1048576 CACHE STRING "Default stack size (default 1048576)") | |
| option(ENABLE_FAST_SDK "Use fast SDK APIs (default OFF)") | |
| option(ENABLE_MALLOC_ALLOCATOR "Use direct malloc allocator over freelist allocator (default OFF)") | |
| option(ENABLE_ALLOCATOR_METRICS "Enable metrics for Allocators (default OFF)") | |
| option(ENABLE_DOCS "Build docs (default OFF)") | |
| option(ENABLE_DOXYGEN "Build Doxygen API documentation (default OFF)") | |
| option(DOXYGEN_CHECK_ONLY "Have the doxygen target check documentation without generating HTML (default OFF)") | |
| option(ENABLE_DISK_FAILURE_TESTS "Build disk failure tests (enables AIO fault injection, default OFF)" OFF) | |
| if(ENABLE_DISK_FAILURE_TESTS) | |
| add_compile_definitions("AIO_FAULT_INJECTION") | |
| endif() | |
| option(ENABLE_URTEST "Set up Uranium tests (default OFF)") | |
| option(ENABLE_URTEST_UDS "Set up Uranium tests with curl using UDS (default OFF)") | |
| if(DEFINED ENABLE_AUTEST OR DEFINED ENABLE_AUTEST_UDS) | |
| message(FATAL_ERROR "ENABLE_AUTEST and ENABLE_AUTEST_UDS were removed; use ENABLE_URTEST and ENABLE_URTEST_UDS") | |
| endif() | |
| option(ENABLE_BENCHMARKS "Build benchmarks (default OFF)") | |
| option(EXTERNAL_YAML_CPP "Use external yaml-cpp (default OFF)") | |
| option(EXTERNAL_LIBSWOC "Use external libswoc (default OFF)") | |
| option(EXTERNAL_HWY "Use external highway (default OFF)") | |
| option(LINK_PLUGINS "Link core libraries to plugins (default OFF)") | |
| option(ENABLE_PROBES "Enable ATS SystemTap probes (default OFF)") | |
| option(ENABLE_VERIFY_PLUGINS "Enable plugin verification tests (default ON)" ON) | |
| option(ENABLE_THREAD_SAFETY_ANALYSIS "Enable Clang -Wthread-safety analysis (Clang only, default ON)" ON) | |
| option(THREAD_SAFETY_ANALYSIS_AS_ERROR "Treat thread-safety findings as errors; for CI gating (default OFF)") | |
| # Setup user | |
| # NOTE: this is the user trafficserver runs as | |
| set(WITH_USER nobody CACHE STRING "The system user (default nobody)") | |
| # NOTE: I can't tell that this is used at all besides being printed | |
| set(WITH_GROUP nobody CACHE STRING "The system group (default nobody, or specified user's group)") | |
| if(WITH_GROUP STREQUAL nobody) | |
| execute_process(COMMAND id -ng ${WITH_USER} OUTPUT_VARIABLE TS_PKGSYSGROUP OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| else() | |
| set(TS_PKGSYSGROUP ${WITH_GROUP}) | |
| endif() | |
| set(TS_PKGSYSUSER ${WITH_USER}) | |
| if(CMAKE_SYSTEM_NAME STREQUAL Linux) | |
| set(DEFAULT_POSIX_CAP ON) | |
| endif() | |
| option(ENABLE_POSIX_CAP "Use POSIX capabilities, turn OFF to use id switching. (default ON for Linux)" | |
| "${DEFAULT_POSIX_CAP}" | |
| ) | |
| option(ENABLE_PROFILER "Use gperftools profiler (default OFF)") | |
| set(ENABLE_TPROXY "AUTO" | |
| CACHE | |
| STRING | |
| "Use TPROXY to enable connection transparency. (default AUTO) | |
| 'AUTO' for local system default, | |
| 'NO', to disable, | |
| 'FORCE' to use built in default, | |
| 'X' where X is a number to use as the IP_TRANSPARENT sockopt, | |
| anything else to enable." | |
| ) | |
| option(ENABLE_QUICHE "Use quiche (default OFF)") | |
| option(ENABLE_HIGHWAY_DISPATCH | |
| "Use Google Highway runtime dispatch for SIMD kernels (default OFF; without it the scalar paths are used)" | |
| ) | |
| option(ENABLE_EXAMPLE "Build example directory (default OFF)") | |
| set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)") | |
| set(MAX_EVENT_THREADS 4096 CACHE STRING "Max number of event threads (default 4096)") | |
| set(MAX_THREADS_PER_TYPE 3072 CACHE STRING "Max number of threads per event type (default 3072)") | |
| set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)") | |
| option(ENABLE_CRIPTS "Build and install the Cripts library and headers (default OFF)") | |
| set(TS_USE_FAST_SDK ${ENABLE_FAST_SDK}) | |
| set(TS_MAX_NUMBER_EVENT_THREADS ${MAX_EVENT_THREADS}) | |
| set(TS_MAX_THREADS_IN_EACH_THREAD_TYPE ${MAX_THREADS_PER_TYPE}) | |
| # Check include files | |
| include(CheckIncludeFile) | |
| include(CheckIncludeFiles) | |
| include(CheckIncludeFileCXX) | |
| include(CheckSymbolExists) | |
| include(CheckTypeSize) | |
| include(CheckSourceCompiles) | |
| include(CheckStructHasMember) | |
| check_include_file(ifaddrs.h HAVE_IFADDRS_H) | |
| # Find libraries | |
| if(ENABLE_CRIPTS) | |
| # needed for cripts | |
| # however this might become a general requirement | |
| find_package(fmt 8.1 REQUIRED) | |
| set(TS_HAS_CRIPTS TRUE) | |
| endif() | |
| find_package(Backtrace) | |
| if(Backtrace_FOUND) | |
| set(TS_HAS_BACKTRACE TRUE) | |
| if(Backtrace_LIBRARIES) | |
| message(STATUS "Backtrace found (library ${Backtrace_LIBRARIES})") | |
| endif() | |
| endif() | |
| find_package(brotli) | |
| if(brotli_FOUND) | |
| set(HAVE_BROTLI_ENCODE_H TRUE) | |
| endif() | |
| find_package(LibLZMA) | |
| if(LibLZMA_FOUND) | |
| set(HAVE_LZMA_H TRUE) | |
| endif() | |
| pkg_check_modules(PCRE2 REQUIRED IMPORTED_TARGET libpcre2-8) | |
| include(CheckOpenSSLIsBoringSSL) | |
| include(CheckOpenSSLIsQuictls) | |
| include(CheckOpenSSLIsAwsLc) | |
| include(CheckOpenSSLHasQuicTlsCbs) | |
| include(CheckOpenSSLHasNativeQuic) | |
| include(CheckQuicheHasQmux) | |
| find_package(OpenSSL REQUIRED) | |
| check_openssl_is_boringssl(SSLLIB_IS_BORINGSSL BORINGSSL_VERSION "${OPENSSL_INCLUDE_DIR}") | |
| check_openssl_is_awslc(SSLLIB_IS_AWSLC AWSLC_VERSION "${OPENSSL_INCLUDE_DIR}") | |
| if(SSLLIB_IS_BORINGSSL) | |
| # The consensus is a commit newer than a1843d660b47116207877614af53defa767be46a | |
| # The commit that changes API_VERSION to 27 is actually a little bit older than the commit but still a reasonable commit | |
| set(min_bssl "27") | |
| if(BORINGSSL_VERSION VERSION_LESS "${min_bssl}") | |
| message(FATAL_ERROR "BoringSSL API version >= ${min_bssl} or another SSL library required") | |
| endif() | |
| elseif(SSLLIB_IS_AWSLC) | |
| set(min_assl "27") | |
| if(AWSLC_VERSION VERSION_LESS "${min_assl}") | |
| message(FATAL_ERROR "AWS-LC API version >= ${min_assl} or anonther SSL library required") | |
| endif() | |
| else() | |
| set(min_ossl "1.1.1") | |
| if(OPENSSL_VERSION VERSION_LESS "${min_ossl}") | |
| message(FATAL_ERROR "OpenSSL version >= ${min_ossl} or another SSL library required") | |
| endif() | |
| endif() | |
| check_openssl_is_quictls(SSLLIB_IS_QUICTLS "${OPENSSL_INCLUDE_DIR}") | |
| if(NOT SSLLIB_IS_BORINGSSL AND NOT SSLLIB_IS_AWSLC AND OPENSSL_VERSION VERSION_GREATER_EQUAL "3.0.0") | |
| set(SSLLIB_IS_AT_LEAST_OPENSSL3 TRUE) | |
| add_compile_definitions(OPENSSL_API_COMPAT=10002 OPENSSL_IS_AT_LEAST_OPENSSL3) | |
| endif() | |
| check_openssl_has_quic_tls_cbs(SSLLIB_HAS_QUIC_TLS_CBS "${OPENSSL_INCLUDE_DIR}") | |
| if(SSLLIB_HAS_QUIC_TLS_CBS AND NOT SSLLIB_IS_BORINGSSL AND NOT SSLLIB_IS_AWSLC AND NOT SSLLIB_IS_QUICTLS) | |
| set(TS_OPENSSL_QUIC_TLS_CBS_COMPAT TRUE) | |
| add_compile_definitions(TS_OPENSSL_QUIC_TLS_CBS_COMPAT) | |
| endif() | |
| check_openssl_has_native_quic(SSLLIB_HAS_NATIVE_QUIC "${OPENSSL_INCLUDE_DIR}") | |
| # OpenSSL's native QUIC is a capability of the mandatory OpenSSL dependency, not an optional | |
| # component to opt into -- same footing as SSLLIB_IS_BORINGSSL or SSLLIB_HAS_QUIC_TLS_CBS above. | |
| # It's mutually exclusive with quiche by construction: quiche requires BoringSSL or the TLS | |
| # callback compat shim, neither of which implements this upstream-OpenSSL-3.5+ API. | |
| set(TS_HAS_OPENSSL_QUIC FALSE) | |
| if(SSLLIB_HAS_NATIVE_QUIC | |
| AND NOT SSLLIB_IS_BORINGSSL | |
| AND NOT SSLLIB_IS_AWSLC AND NOT SSLLIB_IS_QUICTLS AND NOT ENABLE_QUICHE | |
| ) | |
| set(TS_HAS_OPENSSL_QUIC TRUE) | |
| endif() | |
| if(ENABLE_PROFILER) | |
| find_package(profiler REQUIRED) | |
| set(TS_HAS_PROFILER ${profiler_FOUND}) | |
| endif() | |
| if(TS_HAS_JEMALLOC AND TS_HAS_MIMALLOC) | |
| message(FATAL_ERROR "Cannot build with both jemalloc and mimalloc.") | |
| endif() | |
| if(TS_HAS_JEMALLOC) | |
| link_libraries(jemalloc::jemalloc) | |
| elseif(TS_HAS_MIMALLOC) | |
| link_libraries(mimalloc) | |
| endif() | |
| if(ENABLE_QUICHE) | |
| if(TS_OPENSSL_QUIC_TLS_CBS_COMPAT) | |
| set(quiche_USE_STATIC TRUE) | |
| endif() | |
| find_package(quiche REQUIRED) | |
| set(TS_HAS_QUICHE ${quiche_FOUND}) | |
| if(NOT SSLLIB_IS_BORINGSSL AND NOT SSLLIB_IS_QUICTLS AND NOT TS_OPENSSL_QUIC_TLS_CBS_COMPAT) | |
| message( | |
| FATAL_ERROR "Use of BoringSSL, OPENSSL/QUICTLS, or OpenSSL QUIC TLS callbacks is required if quiche is used." | |
| ) | |
| endif() | |
| if(SSLLIB_IS_QUICTLS) | |
| # Until we get quictls support integrated with quiche, we just print this message. | |
| # Once the above that is done, then we can just validate the version. | |
| message( | |
| "WARNING - Using quictls requires using a special version of quiche. Make sure quictls is supported in quiche." | |
| ) | |
| elseif(TS_OPENSSL_QUIC_TLS_CBS_COMPAT) | |
| message(STATUS "Using OpenSSL QUIC TLS callbacks compatibility for quiche") | |
| endif() | |
| check_quiche_has_qmux(TS_QUICHE_HAS_QMUX) | |
| endif() | |
| # A QUIC backend supplies the protocol implementation; the transport options | |
| # below decide how QUIC streams are actually carried on the wire. At least one | |
| # transport must be enabled for QUIC to be reachable. | |
| if(TS_HAS_OPENSSL_QUIC OR TS_HAS_QUICHE) | |
| set(TS_HAS_QUIC_BACKEND TRUE) | |
| else() | |
| set(TS_HAS_QUIC_BACKEND FALSE) | |
| endif() | |
| auto_option( | |
| QUIC | |
| DESCRIPTION | |
| "Carry QUIC over UDP (default AUTO: on when a QUIC backend is available)" | |
| FEATURE_VAR | |
| TS_USE_QUIC | |
| VAR_DEPENDS | |
| TS_HAS_QUIC_BACKEND | |
| ) | |
| if(TS_USE_QUIC) | |
| if(TS_HAS_OPENSSL_QUIC) | |
| message(STATUS "Using OpenSSL native QUIC") | |
| elseif(TS_HAS_QUICHE) | |
| message(STATUS "Using quiche for QUIC transport") | |
| endif() | |
| endif() | |
| auto_option( | |
| QMUX | |
| DESCRIPTION | |
| "Carry QUIC over TLS/TCP as QMux (default AUTO: on when quiche has qmux support)" | |
| FEATURE_VAR | |
| TS_USE_QMUX | |
| VAR_DEPENDS | |
| TS_HAS_QUICHE | |
| TS_QUICHE_HAS_QMUX | |
| ) | |
| if(TS_HAS_QUIC_BACKEND AND NOT TS_USE_QUIC AND NOT TS_USE_QMUX) | |
| message(WARNING "A QUIC backend is enabled but neither UDP QUIC nor QMux is, so QUIC will not be served.") | |
| endif() | |
| find_package(maxminddb) # Header_rewrite experimental/maxmind_acl | |
| if(ENABLE_ASAN) | |
| if(ENABLE_JEMALLOC OR ENABLE_MIMALLOC) | |
| message(FATAL_ERROR "ENABLE_JEMALLOC and ENABLE_MIMALLOC are not compatible with asan builds") | |
| endif() | |
| add_compile_options(-g -fsanitize=address -fno-omit-frame-pointer) | |
| add_link_options(-g -fsanitize=address) | |
| elseif(ENABLE_TSAN) | |
| if(ENABLE_JEMALLOC OR ENABLE_MIMALLOC) | |
| message(FATAL_ERROR "ENABLE_JEMALLOC and ENABLE_MIMALLOC are not compatible with tsan builds") | |
| endif() | |
| add_compile_options(-g -fsanitize=thread -fno-omit-frame-pointer) | |
| add_link_options(-g -fsanitize=thread) | |
| endif() | |
| # UndefinedBehaviorSanitizer. Deliberately not part of the either/or chain above: | |
| # UBSan instruments arithmetic, shifts, and type loads rather than replacing the | |
| # allocator or the thread runtime, so it composes with either of them as well as | |
| # standing on its own: asan gives -fsanitize=address,undefined and tsan gives | |
| # -fsanitize=thread,undefined. Only the asan pairing has a preset, since that is | |
| # the combination developers ask for, but the option itself does not restrict it. | |
| # | |
| # vptr is excluded. It needs a matching type_info at every polymorphic access, and | |
| # a plugin loaded with dlopen does not reliably share type identity with the main | |
| # image, so the check reports the plugin boundary rather than a real bug. | |
| # | |
| # Findings recover, so a single run reports every distinct site instead of stopping | |
| # at the first. That is the default for most checks, but which checks recover by | |
| # default varies between compilers, so ask for it explicitly rather than inherit it. | |
| # A few checks cannot recover by construction (unreachable, return) and still abort. | |
| # Set UBSAN_OPTIONS=halt_on_error=1 at runtime to stop on the first finding, which | |
| # is what a gating job would want. | |
| if(ENABLE_UBSAN) | |
| # This can fail two ways: the toolchain does not know -fsanitize=undefined at all, | |
| # or it knows the flag but cannot link the runtime library, which some distributions | |
| # package separately from the compiler. Without the check the second case surfaces as | |
| # a bare "cannot find libubsan.so" from the linker after compiling hundreds of | |
| # objects, so establish it here and let the message cover both. | |
| include(CheckLinkerFlag) | |
| check_linker_flag(CXX -fsanitize=undefined HAS_UBSAN_SUPPORT) | |
| if(NOT HAS_UBSAN_SUPPORT) | |
| message( | |
| FATAL_ERROR | |
| "ENABLE_UBSAN was requested, but this toolchain cannot link -fsanitize=undefined. Either the compiler does not support the flag, or it does and the sanitizer runtime is missing. GCC ships that runtime in a package separate from the compiler on most distributions, under a name that varies by distribution." | |
| ) | |
| endif() | |
| add_compile_options(-g -fsanitize=undefined -fno-sanitize=vptr -fsanitize-recover=undefined -fno-omit-frame-pointer) | |
| # Only -fsanitize=undefined matters at link time, to pull in the runtime. The vptr | |
| # and recover flags are compile time instrumentation controls and do nothing here. | |
| add_link_options(-g -fsanitize=undefined) | |
| endif() | |
| # Clang Thread Safety Analysis. The TS_* annotations (tsutil/ts_thread_safety.h) | |
| # compile to nothing on GCC, and the flag is Clang-only on purpose (GCC does not | |
| # know -Wthread-safety and would itself error if passed it), so this whole block | |
| # is a no-op for GCC builds. | |
| # | |
| # On Clang it is on by default but only a WARNING: -Wno-error=thread-safety keeps | |
| # it a warning even in builds that otherwise use -Werror, so an in-progress | |
| # annotation never blocks a developer's build. CI sets | |
| # THREAD_SAFETY_ANALYSIS_AS_ERROR=ON to promote findings to errors and gate | |
| # merges. | |
| # | |
| # Skip FreeBSD: its libc annotates the pthread primitives themselves, so | |
| # -Wthread-safety there flags ATS's existing hand-rolled mutex wrappers | |
| # (tscore/ink_mutex.h, ink_rwlock, ...) tree-wide, not just newly-annotated code. | |
| # Enabling it on FreeBSD needs those legacy wrappers made analysis-clean first. | |
| # Elsewhere the platform leaves the pthread primitives un-annotated, so only | |
| # annotated code is analyzed and this stays quiet until a real violation. | |
| if(ENABLE_THREAD_SAFETY_ANALYSIS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") | |
| add_compile_options(-Wthread-safety) | |
| if(THREAD_SAFETY_ANALYSIS_AS_ERROR) | |
| add_compile_options(-Werror=thread-safety) | |
| else() | |
| add_compile_options(-Wno-error=thread-safety) | |
| endif() | |
| endif() | |
| if(ENABLE_PROBES) | |
| add_compile_options("-DENABLE_SYSTEMTAP_PROBES") | |
| endif() | |
| set(TS_USE_MALLOC_ALLOCATOR ${ENABLE_MALLOC_ALLOCATOR}) | |
| set(TS_USE_ALLOCATOR_METRICS ${ENABLE_ALLOCATOR_METRICS}) | |
| find_package(ZLIB REQUIRED) | |
| # 1.4.0 stabilized the advanced one-shot API (ZSTD_compress2 et al.) used by | |
| # the RAM cache; plugins/compress already requires the same floor for | |
| # ZSTD_compressStream2, so this is not specific to the cache. | |
| find_package(ZSTD 1.4.0) | |
| set(HAVE_ZSTD_H ${ZSTD_FOUND}) | |
| # cmake/FindZSTD.cmake creates the zstd::zstd target this tree links against, | |
| # but with CMAKE_FIND_PACKAGE_PREFER_CONFIG the lookup can resolve through | |
| # zstd's own config package instead: on a case-insensitive filesystem the | |
| # ZSTDConfig.cmake CMake searches for matches the zstdConfig.cmake that zstd | |
| # installs. That package exports zstd::libzstd_shared/_static, so alias | |
| # whichever it gave us or the four targets linking zstd::zstd fail at generate | |
| # time. | |
| if(ZSTD_FOUND AND NOT TARGET zstd::zstd) | |
| foreach(_zstd_target zstd::libzstd_shared zstd::libzstd_static zstd::libzstd) | |
| if(TARGET ${_zstd_target}) | |
| add_library(zstd_zstd INTERFACE) | |
| target_link_libraries(zstd_zstd INTERFACE ${_zstd_target}) | |
| add_library(zstd::zstd ALIAS zstd_zstd) | |
| break() | |
| endif() | |
| endforeach() | |
| unset(_zstd_target) | |
| if(NOT TARGET zstd::zstd) | |
| message(WARNING "zstd found but it exports no target this build can use; building without zstd") | |
| set(HAVE_ZSTD_H FALSE) | |
| endif() | |
| endif() | |
| # 1.7.0 (r129) introduced the current compression API, including | |
| # LZ4_compress_default(), which the RAM cache uses; 1.7.5 is the floor for | |
| # LZ4_versionString(), which traffic_layout reports. | |
| find_package(LZ4 1.7.5) | |
| set(HAVE_LZ4_H ${LZ4_FOUND}) | |
| # ncurses is used in traffic_top | |
| find_package(Curses) | |
| set(HAVE_CURSES_H ${CURSES_HAVE_CURSES_H}) | |
| set(HAVE_NCURSES_H ${CURSES_HAVE_NCURSES_H}) | |
| set(HAVE_NCURSES_CURSES_H ${CURSES_HAVE_NCURSES_CURSES_H}) | |
| set(HAVE_NCURSES_NCURSES_H ${CURSES_HAVE_NCURSES_NCURSES_H}) | |
| # find yaml-cpp if requested | |
| if(EXTERNAL_YAML_CPP) | |
| message(STATUS "Looking for external yaml-cpp") | |
| find_package(yaml-cpp "0.8.0" REQUIRED) | |
| set(YAMLCPP_LIB_VERSION ${yaml-cpp_VERSION}) | |
| find_package_message(yaml-cpp "Found yaml-cpp: ${yaml-cpp_CONFIG} (found version \"${yaml-cpp_VERSION}\")" | |
| "${yaml-cpp_CONFIG}" | |
| ) | |
| endif() | |
| if(EXTERNAL_LIBSWOC) | |
| message(STATUS "Looking for external libswoc") | |
| find_package(libswoc REQUIRED) | |
| endif() | |
| if(ENABLE_HIGHWAY_DISPATCH) | |
| if(EXTERNAL_HWY) | |
| message(STATUS "Looking for external highway") | |
| find_package(HWY "1.4.0" CONFIG REQUIRED) | |
| set(TS_HAS_HIGHWAY_DISPATCH ${HWY_FOUND}) | |
| else() | |
| set(TS_HAS_HIGHWAY_DISPATCH 1) | |
| endif() | |
| endif() | |
| include(Check128BitCas) | |
| include(ConfigureTransparentProxy) | |
| # Find ccache | |
| include(find_ccache) | |
| # Check for IO faculties | |
| set(CMAKE_REQUIRED_FLAGS -fPIC) | |
| check_symbol_exists(IN6_IS_ADDR_UNSPECIFIED "netinet/in.h" TS_HAS_IN6_IS_ADDR_UNSPECIFIED) | |
| check_symbol_exists(IP_TOS "netinet/ip.h" TS_HAS_IP_TOS) | |
| check_symbol_exists(SO_MARK "sys/socket.h" TS_HAS_SO_MARK) | |
| check_symbol_exists(SO_PEERCRED "sys/socket.h" TS_HAS_SO_PEERCRED) | |
| if(TS_NO_USE_TLS13) | |
| set(TS_USE_TLS13 FALSE CACHE) | |
| endif() | |
| check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) | |
| check_symbol_exists(epoll_create "sys/epoll.h" TS_USE_EPOLL) | |
| check_symbol_exists(kqueue "sys/event.h" TS_USE_KQUEUE) | |
| set(CMAKE_REQUIRED_LIBRARIES uring) | |
| check_symbol_exists(io_uring_queue_init "liburing.h" HAVE_IOURING) | |
| unset(CMAKE_REQUIRED_LIBRARIES) | |
| check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) | |
| check_symbol_exists(getpeereid unistd.h HAVE_GETPEEREID) | |
| check_symbol_exists(getpeerucred unistd.h HAVE_GETPEERUCRED) | |
| check_symbol_exists(getresuid unistd.h HAVE_GETRESUID) | |
| check_symbol_exists(getresgid unistd.h HAVE_GETRESGID) | |
| check_symbol_exists(malloc_usable_size "malloc.h;malloc_np.h" HAVE_MALLOC_USABLE_SIZE) | |
| check_symbol_exists(mcheck_pedantic mcheck.h HAVE_MCHECK_PEDANTIC) | |
| check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE) | |
| check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) | |
| check_symbol_exists(posix_madvise sys/mman.h HAVE_POSIX_MADVISE) | |
| # On glibc < 2.34 shm_open/shm_unlink live in librt, which ATS does not link, so the cache shm feature is compiled out | |
| # there. This is a link test, so it fails exactly on those platforms. | |
| check_symbol_exists(shm_open sys/mman.h HAVE_SHM_OPEN) | |
| check_symbol_exists(accept4 sys/socket.h HAVE_ACCEPT4) | |
| check_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD) | |
| check_symbol_exists(sysconf unistd.h HAVE_SYSCONF) | |
| check_symbol_exists(recvmmsg sys/socket.h HAVE_RECVMMSG) | |
| check_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG) | |
| check_symbol_exists(strlcat string.h HAVE_STRLCAT) | |
| check_symbol_exists(strlcpy string.h HAVE_STRLCPY) | |
| check_symbol_exists(strsignal string.h HAVE_STRSIGNAL) | |
| check_symbol_exists(sysinfo sys/sysinfo.h HAVE_SYSINFO) | |
| check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL) | |
| # Test for Processing Unit support in hwloc | |
| if(TS_USE_HWLOC) | |
| list(APPEND CMAKE_REQUIRED_INCLUDES ${hwloc_INCLUDE_DIRS}) | |
| check_source_compiles( | |
| C | |
| "#include <hwloc.h> | |
| int main() { return HWLOC_OBJ_PU; }" | |
| HAVE_HWLOC_OBJ_PU | |
| ) | |
| list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${hwloc_INCLUDE_DIRS}) | |
| endif() | |
| check_symbol_exists(SO_TXTIME "sys/socket.h" SO_TXTIME_FOUND) | |
| set(CMAKE_EXTRA_INCLUDE_FILES "linux/net_tstamp.h") | |
| check_type_size("struct sock_txtime" STRUCT_SOCK_TXTIME_FOUND) | |
| unset(CMAKE_EXTRA_INCLUDE_FILES) | |
| if(SO_TXTIME_FOUND AND STRUCT_SOCK_TXTIME_FOUND) | |
| set(HAVE_SO_TXTIME TRUE) | |
| endif() | |
| option(USE_IOURING "Use experimental io_uring (linux only)" 0) | |
| if(HAVE_IOURING AND USE_IOURING) | |
| message(STATUS "Using io_uring") | |
| set(TS_USE_LINUX_IO_URING 1) | |
| endif(HAVE_IOURING AND USE_IOURING) | |
| option(ENABLE_CACHE_SHM "Host the cache directory in POSIX shared memory for fast restart" 1) | |
| if(HAVE_SHM_OPEN AND ENABLE_CACHE_SHM) | |
| set(TS_USE_CACHE_SHM 1) | |
| endif(HAVE_SHM_OPEN AND ENABLE_CACHE_SHM) | |
| list(APPEND CMAKE_REQUIRED_LIBRARIES pthread) | |
| check_symbol_exists(pthread_getname_np pthread.h HAVE_PTHREAD_GETNAME_NP) | |
| check_symbol_exists(pthread_get_name_np pthread.h HAVE_PTHREAD_GET_NAME_NP) | |
| check_source_compiles( | |
| C | |
| "#include <pthread.h> | |
| void main() { pthread_setname_np(\"name\"); }" | |
| HAVE_PTHREAD_SETNAME_NP_1 | |
| ) | |
| check_source_compiles( | |
| C | |
| "#include <pthread.h> | |
| void main() { pthread_setname_np(0, \"name\"); }" | |
| HAVE_PTHREAD_SETNAME_NP_2 | |
| ) | |
| check_source_compiles( | |
| C | |
| "#include <pthread.h> | |
| void main() { pthread_set_name_np(\"name\"); }" | |
| HAVE_PTHREAD_SET_NAME_NP_1 | |
| ) | |
| check_source_compiles( | |
| C | |
| "#include <pthread.h> | |
| void main() { pthread_set_name_np(0, \"name\"); }" | |
| HAVE_PTHREAD_SET_NAME_NP_2 | |
| ) | |
| list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES pthread) | |
| # Check ssl functionality | |
| list(APPEND CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) | |
| list(APPEND CMAKE_REQUIRED_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) | |
| check_symbol_exists(BIO_meth_new "openssl/bio.h" HAVE_BIO_METH_NEW) | |
| check_symbol_exists(BIO_set_data "openssl/bio.h" HAVE_BIO_SET_DATA) | |
| check_symbol_exists(BIO_get_data "openssl/bio.h" HAVE_BIO_GET_DATA) | |
| check_symbol_exists(BIO_get_shutdown "openssl/bio.h" HAVE_BIO_GET_SHUTDOWN) | |
| check_symbol_exists(BIO_get_ex_new_index "openssl/bio.h" HAVE_BIO_GET_EX_NEW_INDEX) | |
| check_symbol_exists(BIO_get_ex_data "openssl/bio.h" HAVE_BIO_GET_EX_DATA) | |
| check_symbol_exists(BIO_set_ex_data "openssl/bio.h" HAVE_BIO_SET_EX_DATA) | |
| check_symbol_exists(BIO_meth_get_ctrl "openssl/bio.h" HAVE_BIO_METH_GET_CTRL) | |
| check_symbol_exists(BIO_meth_get_create "openssl/bio.h" HAVE_BIO_METH_GET_CREATE) | |
| check_symbol_exists(BIO_meth_get_destroy "openssl/bio.h" HAVE_BIO_METH_GET_DESTROY) | |
| check_symbol_exists(CRYPTO_set_ex_data "openssl/bio.h" HAVE_CRYPTO_SET_EX_DATA) | |
| check_symbol_exists(DH_get_2048_256 "openssl/dh.h" TS_USE_GET_DH_2048_256) | |
| check_symbol_exists(OPENSSL_NO_TLS_3 "openssl/ssl.h" TS_NO_USE_TLS12) | |
| check_symbol_exists(SSL_CTX_set_client_hello_cb "openssl/ssl.h" HAVE_SSL_CTX_SET_CLIENT_HELLO_CB) | |
| check_symbol_exists(SSL_CTX_set_select_certificate_cb "openssl/ssl.h" HAVE_SSL_CTX_SET_SELECT_CERTIFICATE_CB) | |
| check_symbol_exists(SSL_CTX_set1_server_cert_type "openssl/ssl.h" HAVE_SSL_CTX_SET1_SERVER_CERT_TYPE) | |
| check_symbol_exists(SSL_CREDENTIAL_new_raw_public_key "openssl/ssl.h" HAVE_SSL_CREDENTIAL_NEW_RAW_PUBLIC_KEY) | |
| check_symbol_exists(SSL_set1_verify_cert_store "openssl/ssl.h" TS_HAS_VERIFY_CERT_STORE) | |
| check_symbol_exists(SSL_get_shared_curve "openssl/ssl.h" HAVE_SSL_GET_SHARED_CURVE) | |
| check_symbol_exists(SSL_get_curve_name "openssl/ssl.h" HAVE_SSL_GET_CURVE_NAME) | |
| check_symbol_exists(SSL_get0_group_name "openssl/ssl.h" HAVE_SSL_GET0_GROUP_NAME) | |
| check_symbol_exists(SSL_get_negotiated_group "openssl/ssl.h" HAVE_SSL_GET_NEGOTIATED_GROUP) | |
| check_symbol_exists(SSL_CTX_get0_implemented_groups "openssl/ssl.h" HAVE_SSL_CTX_GET0_IMPLEMENTED_GROUPS) | |
| check_symbol_exists(SSL_get_group_id "openssl/ssl.h" HAVE_SSL_GET_GROUP_ID) | |
| check_symbol_exists(SSL_get_group_name "openssl/ssl.h" HAVE_SSL_GET_GROUP_NAME) | |
| check_symbol_exists(SSL_group_to_name "openssl/ssl.h" HAVE_SSL_GROUP_TO_NAME) | |
| check_symbol_exists(SSL_get_sigalgs "openssl/ssl.h" HAVE_SSL_GET_SIGALGS) | |
| check_symbol_exists(SSL_get_shared_sigalgs "openssl/ssl.h" HAVE_SSL_GET_SHARED_SIGALGS) | |
| check_symbol_exists(SSL_get0_peer_verify_algorithms "openssl/ssl.h" HAVE_SSL_GET0_PEER_VERIFY_ALGORITHMS) | |
| check_symbol_exists(SSL_get_signature_algorithm_used "openssl/ssl.h" HAVE_SSL_GET_SIGNATURE_ALGORITHM_USED) | |
| check_cxx_source_compiles( | |
| "#include <openssl/ssl.h> | |
| int main() { | |
| SSL *ssl = nullptr; | |
| int digest = 0; | |
| int type = 0; | |
| return SSL_get_signature_nid(ssl, &digest) + SSL_get_signature_type_nid(ssl, &type); | |
| }" | |
| HAVE_SSL_GET_LOCAL_SIGNATURE_NIDS | |
| ) | |
| check_symbol_exists(SSL_set_max_early_data "openssl/ssl.h" HAVE_SSL_SET_MAX_EARLY_DATA) | |
| check_symbol_exists(SSL_read_early_data "openssl/ssl.h" HAVE_SSL_READ_EARLY_DATA) | |
| check_symbol_exists(SSL_write_early_data "openssl/ssl.h" HAVE_SSL_WRITE_EARLY_DATA) | |
| check_symbol_exists(SSL_in_early_data "openssl/ssl.h" HAVE_SSL_IN_EARLY_DATA) | |
| check_symbol_exists(SSL_error_description "openssl/ssl.h" HAVE_SSL_ERROR_DESCRIPTION) | |
| check_symbol_exists(SSL_CTX_set_ciphersuites "openssl/ssl.h" TS_USE_TLS_SET_CIPHERSUITES) | |
| check_symbol_exists(SSL_CTX_set_keylog_callback "openssl/ssl.h" TS_HAS_TLS_KEYLOGGING) | |
| check_symbol_exists(SSL_CTX_set_tlsext_ticket_key_cb "openssl/ssl.h" HAVE_SSL_CTX_SET_TLSEXT_TICKET_KEY_CB) | |
| check_symbol_exists(SSL_CTX_add_cert_compression_alg "openssl/ssl.h" HAVE_SSL_CTX_ADD_CERT_COMPRESSION_ALG) | |
| check_symbol_exists(SSL_CTX_set1_cert_comp_preference "openssl/ssl.h" HAVE_SSL_CTX_SET1_CERT_COMP_PREFERENCE) | |
| check_symbol_exists(SSL_get_all_async_fds openssl/ssl.h TS_USE_TLS_ASYNC) | |
| check_symbol_exists(OSSL_PARAM_construct_end "openssl/params.h" HAVE_OSSL_PARAM_CONSTRUCT_END) | |
| check_symbol_exists(TLS1_3_VERSION "openssl/ssl.h" TS_USE_TLS13) | |
| check_symbol_exists(MD5_Init "openssl/md5.h" HAVE_MD5_INIT) | |
| check_symbol_exists(sysctlbyname "sys/sysctl.h" HAVE_SYSCTLBYNAME) | |
| if(SSLLIB_IS_AT_LEAST_OPENSSL3) | |
| check_symbol_exists(SSL_CTX_set_tlsext_ticket_key_evp_cb "openssl/ssl.h" TS_HAS_TLS_SESSION_TICKET) | |
| else() | |
| check_symbol_exists(SSL_CTX_set_tlsext_ticket_key_cb "openssl/ssl.h" TS_HAS_TLS_SESSION_TICKET) | |
| endif() | |
| unset(CMAKE_REQUIRED_FLAGS) | |
| if(HAVE_SSL_CTX_SET_CLIENT_HELLO_CB OR HAVE_SSL_CTX_SET_SELECT_CERTIFICATE_CB) | |
| set(TS_USE_HELLO_CB TRUE) | |
| else() | |
| set(TS_USE_HELLO_CB FALSE) | |
| endif() | |
| if(HAVE_SSL_CTX_SET1_SERVER_CERT_TYPE OR HAVE_SSL_CREDENTIAL_NEW_RAW_PUBLIC_KEY) | |
| set(TS_USE_RPK TRUE) | |
| else() | |
| set(TS_USE_RPK FALSE) | |
| endif() | |
| if(HAVE_SSL_SET_MAX_EARLY_DATA OR HAVE_SSL_READ_EARL_DATA OR HAVE_SSL_WRITE_EARLY_DATA OR HAVE_SSL_IN_EARLY_DATA) | |
| set(TS_HAS_TLS_EARLY_DATA TRUE) | |
| else() | |
| set(TS_HAS_TLS_EARLY_DATA FALSE) | |
| endif() | |
| check_source_compiles( | |
| C | |
| "#include <openssl/ssl.h> | |
| int main() { int x = SSL_CTRL_GET_EXTRA_CHAIN_CERTS; return 0; }" | |
| HAVE_NATIVE_DUAL_CERT_SUPPORT | |
| ) | |
| check_source_compiles( | |
| C | |
| "#include <openssl/ex_data.h> | |
| int main() { CRYPTO_EX_unused x; return 0; }" | |
| HAVE_CRYPTO_EX_UNUSED | |
| ) | |
| check_cxx_source_compiles( | |
| "#include <openssl/crypto.h> | |
| #if __has_include(<openssl/ex_data.h>) | |
| #include <openssl/ex_data.h> | |
| #endif | |
| int main() { | |
| CRYPTO_EX_dup *cb = [] (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, void **from_d, int idx, long argl, void *argp) -> int { return 0; }; | |
| return 0; | |
| }" | |
| HAVE_CRYPTO_EX_DUP_TYPE1 | |
| ) | |
| if(SSLLIB_IS_BORINGSSL OR SSLLIB_IS_AWSLC) | |
| check_cxx_source_compiles( | |
| "#include <openssl/asn1.h> | |
| namespace bssl { | |
| DECLARE_ASN1_ITEM(GENERAL_NAME) | |
| }; | |
| int main() { | |
| if (&bssl::GENERAL_NAME_it == reinterpret_cast<void *>(0x01)) { | |
| return 1; | |
| } | |
| return 0; | |
| }" | |
| HAVE_GENERAL_NAME_IN_BSSL_NAMESPACE | |
| ) | |
| else() | |
| # This probe is only meaningful for BoringSSL-family libraries. Force it off | |
| # for OpenSSL so a stale cache or macro shape change can't enable bssl:: code. | |
| set(HAVE_GENERAL_NAME_IN_BSSL_NAMESPACE FALSE CACHE INTERNAL "GENERAL_NAME lives in the bssl namespace" FORCE) | |
| endif() | |
| # Prevent unrelated feature probes from inheriting the OpenSSL dependencies. | |
| list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) | |
| list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) | |
| set(CMAKE_EXTRA_INCLUDE_FILES netinet/in.h netinet/tcp.h) | |
| check_type_size("struct tcp_info" STRUCT_TCP_INFO) | |
| unset(CMAKE_EXTRA_INCLUDE_FILES) | |
| # Since Linux 2.6.12 | |
| check_struct_has_member("struct tcp_info" tcpi_total_retrans "linux/tcp.h" HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS) | |
| # Since Linux 4.6 | |
| check_struct_has_member("struct tcp_info" tcpi_data_segs_out "linux/tcp.h" HAVE_STRUCT_TCP_INFO_TCPI_DATA_SEGS_OUT) | |
| # Since FreeBSD 6 | |
| check_struct_has_member("struct tcp_info" __tcpi_retrans "netinet/tcp.h" HAVE_STRUCT_TCP_INFO___TCPI_RETRANS) | |
| check_struct_has_member("struct sockaddr" sa_len "netinet/in.h" HAVE_STRUCT_SOCKADDR_SA_LEN) | |
| check_struct_has_member("struct sockaddr_in" sin_len "netinet/in.h" HAVE_STRUCT_SOCKADDR_IN_SIN_LEN) | |
| check_struct_has_member("struct sockaddr_in6" sin6_len "netinet/in.h" HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN) | |
| check_struct_has_member("struct sockaddr_un" sun_len "sys/un.h" HAVE_STRUCT_SOCKADDR_UN_SUN_LEN) | |
| check_struct_has_member("struct stat" st_mtimespec "sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) | |
| check_struct_has_member("struct stat" st_mtim "sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) | |
| check_struct_has_member("struct mptcp_info" mptcpi_subflows "linux/mptcp.h" HAVE_STRUCT_MPTCP_INFO_SUBFLOWS) | |
| # find resolv library if available | |
| find_package(resolv) | |
| if(ENABLE_DOCS OR ENABLE_URTEST) | |
| find_package(Python3 REQUIRED) | |
| find_program(UV uv REQUIRED) | |
| find_program(NETCAT_PROGRAM nc REQUIRED) | |
| endif() | |
| if(ENABLE_DOCS) | |
| find_package(Java COMPONENTS Runtime REQUIRED) | |
| find_program(GRAPHVIZ_DOT dot REQUIRED) | |
| endif() | |
| if(ENABLE_URTEST) | |
| # Default the sandbox to /tmp to keep paths short. Unix domain socket paths | |
| # are limited to 108 characters and deep build directories (e.g. in home | |
| # directories) can exceed this limit, causing confusing test failures. A hash | |
| # of CMAKE_BINARY_DIR provides per-build isolation while keeping the path | |
| # deterministic across runs. | |
| string(MD5 _build_dir_hash "${CMAKE_BINARY_DIR}") | |
| string(SUBSTRING "${_build_dir_hash}" 0 8 _build_dir_hash) | |
| set(URTEST_SANDBOX "/tmp/urtest_${_build_dir_hash}" | |
| CACHE STRING "Location for Uranium test output (default /tmp/urtest_<hash>)" | |
| ) | |
| set(URTEST_OPTIONS "" CACHE STRING "Additional options for Uranium tests (default \"\")") | |
| if(DEFINED AUTEST_SANDBOX OR DEFINED AUTEST_OPTIONS OR DEFINED PYTEST_OPTIONS) | |
| message( | |
| FATAL_ERROR | |
| "AUTEST_SANDBOX, AUTEST_OPTIONS, and PYTEST_OPTIONS were removed; use URTEST_SANDBOX and URTEST_OPTIONS" | |
| ) | |
| endif() | |
| file(READ "${CMAKE_SOURCE_DIR}/tests/proxy-verifier-version.txt" PROXY_VERIFIER_VERSION) | |
| string(STRIP "${PROXY_VERIFIER_VERSION}" PROXY_VERIFIER_VERSION) | |
| file(READ "${CMAKE_SOURCE_DIR}/tests/proxy-verifier-checksum.txt" PROXY_VERIFIER_SHA1) | |
| string(STRIP "${PROXY_VERIFIER_SHA1}" PROXY_VERIFIER_SHA1) | |
| set(PROXY_VERIFIER_HASH "SHA1=${PROXY_VERIFIER_SHA1}") | |
| include(proxy-verifier) | |
| endif() | |
| include(CTest) | |
| set(TS_HAS_TESTS ${BUILD_REGRESSION_TESTING}) | |
| message(STATUS "Configuring for ${HOST_OS}") | |
| if(HOST_OS STREQUAL "linux") | |
| set(CMAKE_THREAD_LIBS_INIT "-lpthread") | |
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") | |
| set(CMAKE_HAVE_THREADS_LIBRARY 1) | |
| set(CMAKE_USE_WIN32_THREADS_INIT 0) | |
| set(CMAKE_USE_PTHREADS_INIT 1) | |
| set(THREADS_PREFER_PTHREAD_FLAG ON) | |
| link_libraries(dl) | |
| endif(HOST_OS STREQUAL "linux") | |
| if(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang) | |
| set(CMAKE_MACOSX_RPATH 1) | |
| endif() | |
| if(HOST_OS STREQUAL "freebsd") | |
| set(CMAKE_THREAD_LIBS_INIT "-lpthread") | |
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") | |
| set(CMAKE_HAVE_THREADS_LIBRARY 1) | |
| set(CMAKE_USE_WIN32_THREADS_INIT 0) | |
| set(CMAKE_USE_PTHREADS_INIT 1) | |
| set(THREADS_PREFER_PTHREAD_FLAG ON) | |
| endif() | |
| # Set the rpath for installed binaries | |
| set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64") | |
| set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) | |
| add_compile_definitions(${HOST_OS} PACKAGE_NAME="Apache Traffic Server" PACKAGE_VERSION="${TS_VERSION_STRING}") | |
| add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>) | |
| # Enable fuzzing | |
| if(ENABLE_FUZZING) | |
| if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") | |
| message(FATAL_ERROR "Fuzzing is only supported with clang") | |
| endif() | |
| endif() | |
| set(TS_ENABLE_FIPS ${ENABLE_FIPS}) | |
| if(ENABLE_EVENT_TRACKER) | |
| add_compile_definitions(ENABLE_EVENT_TRACKER) | |
| endif() | |
| # Common includes for everyone | |
| include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include) | |
| add_subdirectory(lib) | |
| # Keep this after lib because lib is made up of third party libraries, so if | |
| # there are warnings, we can't do anything about it. | |
| # Note: -DCMAKE_COMPILE_WARNING_AS_ERROR=ON will turn warnings into errors. | |
| add_compile_options(-pipe -Wall -Wextra) | |
| add_compile_options( | |
| "$<$<COMPILE_LANGUAGE:CXX>:-Wno-noexcept-type;-Wsuggest-override;-Wno-vla-extension;-fno-strict-aliasing>" | |
| ) | |
| add_compile_options("$<$<CXX_COMPILER_ID:GNU>:-Wno-format-truncation>") | |
| if(NOT EXTERNAL_YAML_CPP) | |
| include(subproject_version) | |
| subproject_version(YAML_CPP YAMLCPP_LIB_VERSION) | |
| endif() | |
| set(rel_cachedir var/trafficserver) | |
| if(EXISTS "${PROJECT_SOURCE_DIR}/include/ink_autoconf.h") | |
| message(STATUS "Autoconf build detected in source tree. Removing autoconf headers.") | |
| endif() | |
| set(CMAKE_HOST "${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}") | |
| # In-tree autoconf configuration causes duplicate definitions of some symbols | |
| # in generated headers. If the files don't exist, no error is emitted. | |
| file(REMOVE "${PROJECT_SOURCE_DIR}/include/tscore/ink_config.h") | |
| file(REMOVE "${PROJECT_SOURCE_DIR}/include/ts/apidefs.h") | |
| file(REMOVE "${PROJECT_SOURCE_DIR}/include/ink_autoconf.h") | |
| configure_file(configs/storage.yaml.default.in configs/storage.yaml.default) | |
| configure_file(configs/records.yaml.default.in configs/records.yaml.default) | |
| configure_file(include/tscore/ink_config.h.cmake.in include/tscore/ink_config.h) | |
| configure_file(include/ts/apidefs.h.in include/ts/apidefs.h) | |
| add_subdirectory(src/tscpp/api) | |
| add_subdirectory(src/tsutil) | |
| add_subdirectory(src/config) | |
| add_subdirectory(src/tscore) | |
| add_subdirectory(src/records) | |
| add_subdirectory(src/iocore) | |
| add_subdirectory(src/proxy) | |
| add_subdirectory(src/shared) | |
| add_subdirectory(src/mgmt/config) | |
| add_subdirectory(src/mgmt/rpc) | |
| add_subdirectory(src/api) | |
| add_subdirectory(src/traffic_crashlog) | |
| add_subdirectory(src/traffic_server) | |
| add_subdirectory(src/traffic_ctl) | |
| add_subdirectory(src/traffic_layout) | |
| add_subdirectory(src/traffic_cache_tool) | |
| add_subdirectory(src/traffic_logcat) | |
| add_subdirectory(src/traffic_logstats) | |
| if(CURSES_FOUND) | |
| add_subdirectory(src/traffic_top) | |
| endif() | |
| add_subdirectory(src/traffic_via) | |
| if(ENABLE_CRIPTS) | |
| add_subdirectory(src/cripts) | |
| endif() | |
| if(ENABLE_URTEST) | |
| add_subdirectory(tests) | |
| endif() | |
| if(ENABLE_FUZZING) | |
| add_subdirectory(tests/fuzzing) | |
| endif() | |
| # set up auto options for experimental plugins | |
| # This must be done before setting up the stable plugins | |
| # because they check whether the experimental plugins | |
| # already found ImageMagick, but not the other way around. | |
| # Doing these in the other order may add ImageMagick::Magick++ | |
| # twice which is an error. | |
| include(ExperimentalPlugins) | |
| # This also adds any experimental plugins that have been enabled. | |
| add_subdirectory(plugins) | |
| add_subdirectory(configs) | |
| if(ENABLE_EXAMPLE) | |
| add_subdirectory(example) | |
| endif() | |
| # add any extra subdirectories to the build here | |
| add_subdirectory(ext) | |
| if(ENABLE_DOCS) | |
| set(DOC_LANG en CACHE STRING "Document language option") | |
| add_subdirectory(doc) | |
| endif() | |
| if(ENABLE_DOXYGEN) | |
| include(cmake/Doxygen.cmake) | |
| endif() | |
| add_subdirectory(rc) | |
| if(ENABLE_BENCHMARKS) | |
| message(STATUS "Building benchmarks in tools/benchmark") | |
| add_subdirectory(tools/benchmark) | |
| endif() | |
| add_custom_target( | |
| clang-format-install | |
| COMMAND ${CMAKE_SOURCE_DIR}/tools/clang-format.sh --install | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| BYPRODUCTS ${GIT_COMMON_DIR}/fmt/.clang-format-installed | |
| COMMENT "Installing clang-format" | |
| VERBATIM | |
| ) | |
| function(add_clang_format_target target) | |
| add_custom_target( | |
| clang-format-${target} ${CMAKE_SOURCE_DIR}/tools/clang-format.sh ${CMAKE_SOURCE_DIR}/${target} | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| COMMENT "Checking clang-format for ${target}" | |
| VERBATIM | |
| ) | |
| add_dependencies(clang-format-${target} clang-format-install) | |
| list(APPEND CLANG_FORMAT_TARGETS clang-format-${target}) | |
| set(CLANG_FORMAT_TARGETS ${CLANG_FORMAT_TARGETS} PARENT_SCOPE) | |
| endfunction(add_clang_format_target) | |
| add_clang_format_target(src) | |
| add_clang_format_target(example) | |
| add_clang_format_target(include) | |
| add_clang_format_target(plugins) | |
| add_clang_format_target(tools) | |
| add_clang_format_target(tests) | |
| add_custom_target( | |
| clang-format | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| COMMENT "formatting all C++ files" | |
| DEPENDS ${CLANG_FORMAT_TARGETS} | |
| VERBATIM | |
| ) | |
| add_custom_target( | |
| ruff ${CMAKE_SOURCE_DIR}/tools/ruff.sh ${CMAKE_SOURCE_DIR} | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| COMMENT "formatting Python files" | |
| VERBATIM | |
| ) | |
| add_custom_target( | |
| cmakefmt ${CMAKE_SOURCE_DIR}/tools/cmakefmt.sh ${CMAKE_SOURCE_DIR} | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| COMMENT "formatting CMakeLists.txt files" | |
| VERBATIM | |
| ) | |
| add_custom_target( | |
| whitespace-format ${CMAKE_SOURCE_DIR}/tools/whitespace-format.sh | |
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |
| COMMENT "fixing whitespace issues (trailing whitespace, DOS line endings)" | |
| VERBATIM | |
| ) | |
| # Add a format target that runs all the formatters. | |
| add_custom_target(format DEPENDS clang-format ruff cmakefmt whitespace-format COMMENT "formatting all files") | |
| # Install pre-commit hook if this is a git repository (including worktrees). | |
| if(GIT_COMMON_DIR) | |
| set(PRE_COMMIT_HOOK "${GIT_COMMON_DIR}/hooks/pre-commit") | |
| file(TIMESTAMP ${PRE_COMMIT_HOOK} PRE_COMMIT_BEFORE) | |
| configure_file(${CMAKE_SOURCE_DIR}/tools/git/pre-commit ${PRE_COMMIT_HOOK} COPYONLY) | |
| file(TIMESTAMP ${PRE_COMMIT_HOOK} PRE_COMMIT_AFTER) | |
| if(NOT PRE_COMMIT_BEFORE STREQUAL PRE_COMMIT_AFTER) | |
| message(STATUS "Installing github hook") | |
| endif() | |
| endif() | |
| # Add a target to run the rat tool. If java isn't installed this will fail, but its not normally run | |
| add_custom_target( | |
| rat | |
| COMMENT "Running Apache RAT" | |
| COMMAND | |
| java -jar ${CMAKE_SOURCE_DIR}/ci/apache-rat-0.17.jar --input-exclude-file ${CMAKE_SOURCE_DIR}/ci/rat-exclude.txt | |
| --input-include-file ${CMAKE_SOURCE_DIR}/ci/rat-include.txt -- ${CMAKE_SOURCE_DIR} | |
| ) | |
| # Create an empty directories for ATS runtime | |
| install(DIRECTORY DESTINATION ${CMAKE_INSTALL_LOGDIR}) | |
| install(DIRECTORY DESTINATION ${CMAKE_INSTALL_RUNSTATEDIR}) | |
| install(DIRECTORY DESTINATION ${CMAKE_INSTALL_CACHEDIR}) | |
| install(CODE "set(OWNER_USER ${TS_PKGSYSUSER})") | |
| install(CODE "set(OWNER_GROUP ${TS_PKGSYSGROUP})") | |
| install(CODE | |
| "set(CHOWN_DIRS ${CMAKE_INSTALL_FULL_LOGDIR} ${CMAKE_INSTALL_FULL_RUNSTATEDIR} ${CMAKE_INSTALL_FULL_CACHEDIR})" | |
| ) | |
| install(SCRIPT cmake/post_install.cmake) | |
| # Generate pkg-config and cmake config files | |
| configure_file(ts.pc.in ts.pc @ONLY) | |
| configure_file(Findtsapi.cmake.in Findtsapi.cmake @ONLY) | |
| install(FILES "${PROJECT_BINARY_DIR}/ts.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) | |
| install(FILES "${PROJECT_BINARY_DIR}/Findtsapi.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) | |
| # Release Targets | |
| set(DISTTMP /tmp/asf-dist) | |
| set(DISTFILENAME trafficserver-${TS_VERSION_STRING}) | |
| add_custom_target( | |
| asf-distdir | |
| COMMENT "Create distribution tarball for ASF" | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND rm -rf ${DISTTMP} && mkdir /tmp/asf-dist | |
| COMMAND git archive --format=tar --prefix=${DISTFILENAME}/ HEAD | tar -C ${DISTTMP} -xf - | |
| COMMAND rm -rf ${DISTTMP}/${DISTFILENAME}/ci | |
| COMMAND grep -v img.shields.io ${DISTTMP}/${DISTFILENAME}/README.md > ${DISTTMP}/${DISTFILENAME}/README.md.clean | |
| COMMAND mv ${DISTTMP}/${DISTFILENAME}/README.md.clean ${DISTTMP}/${DISTFILENAME}/README.md | |
| ) | |
| add_custom_target( | |
| asf-dist | |
| COMMENT "Create distribution tarball for ASF release" | |
| DEPENDS asf-distdir | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND tar -C ${DISTTMP} -c ${DISTFILENAME} | bzip2 -9 -c > ${DISTFILENAME}.tar.bz2 | |
| COMMAND rm -rf ${DISTTMP} | |
| ) | |
| add_custom_target( | |
| asf-dist-rc | |
| COMMENT "Create distribution tarball for ASF release candidate" | |
| DEPENDS asf-distdir | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND tar -C ${DISTTMP} -c ${DISTFILENAME} | bzip2 -9 -c > ${DISTFILENAME}-rc$ENV{RC}.tar.bz2 | |
| COMMAND rm -rf ${DISTTMP} | |
| ) | |
| add_custom_target( | |
| asf-dist-sign | |
| COMMENT "Create and sign distribution tarball for ASF release" | |
| DEPENDS asf-dist | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND shasum -a512 -b ${DISTFILENAME}.tar.bz2 > ${DISTFILENAME}.tar.bz2.sha512 | |
| COMMAND gpg --armor --output ${DISTFILENAME}.tar.bz2.asc --detach-sig ${DISTFILENAME}.tar.bz2 | |
| ) | |
| add_custom_target( | |
| asf-dist-sign-rc | |
| COMMENT "Create and sign distribution tarball for ASF release candidate" | |
| DEPENDS asf-dist-rc | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND shasum -a512 -b ${DISTFILENAME}-rc$ENV{RC}.tar.bz2 > ${DISTFILENAME}-rc$ENV{RC}.tar.bz2.sha512 | |
| COMMAND gpg --armor --output ${DISTFILENAME}-rc$ENV{RC}.tar.bz2.asc --detach-sig ${DISTFILENAME}-rc$ENV{RC}.tar.bz2 | |
| ) | |
| add_custom_target( | |
| release | |
| COMMENT "Create release" | |
| DEPENDS asf-dist-sign | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND git tag -fs -m "Release ${TS_VERSION_STRING}" ${TS_VERSION_STRING} | |
| ) | |
| add_custom_target( | |
| rel-candidate | |
| COMMENT "Create release candidate" | |
| DEPENDS asf-dist-sign-rc | |
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
| COMMAND git tag -fs -m "Release Candidate ${TS_VERSION_STRING}-rc$ENV{RC}" ${TS_VERSION_STRING}-rc$ENV{RC} | |
| ) | |
| # Display build summary | |
| include(CMakePrintHelpers) | |
| message(STATUS "Build Summary:") | |
| cmake_print_variables(CMAKE_HOST) | |
| cmake_print_variables(CMAKE_SYSTEM_NAME) | |
| cmake_print_variables(CMAKE_SYSTEM_VERSION) | |
| cmake_print_variables(CMAKE_SYSTEM_PROCESSOR) | |
| cmake_print_variables(CMAKE_GENERATOR) | |
| cmake_print_variables(CMAKE_BUILD_TYPE) | |
| cmake_print_variables(CMAKE_INSTALL_PREFIX) | |
| cmake_print_variables(CMAKE_CXX_COMPILER) | |
| cmake_print_variables(CMAKE_C_COMPILER) | |
| cmake_print_variables(CMAKE_CXX_FLAGS) | |
| cmake_print_variables(CMAKE_C_FLAGS) | |
| cmake_print_variables(BUILD_PERSON) | |
| cmake_print_variables(BUILD_GROUP) | |
| cmake_print_variables(TS_PKGSYSUSER) | |
| cmake_print_variables(TS_PKGSYSGROUP) | |
| cmake_print_variables(BUILD_MACHINE) | |
| cmake_print_variables(DEFAULT_STACK_SIZE) | |
| cmake_print_variables(CMAKE_INSTALL_RPATH) | |
| if(DEFINED DOC_LANG) | |
| cmake_print_variables(DOC_LANG) | |
| endif(DEFINED DOC_LANG) | |
| print_auto_options_summary() |