Skip to content
Merged
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
37 changes: 25 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ execute_process(COMMAND id -ng OUTPUT_VARIABLE BUILD_GROUP OUTPUT_STRIP_TRAILING
execute_process(COMMAND uname -n OUTPUT_VARIABLE BUILD_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE)

# Options
include(AutoOptionHelpers)
auto_option(HWLOC FEATURE_VAR TS_USE_HWLOC PACKAGE_DEPENDS hwloc)
auto_option(JEMALLOC
FEATURE_VAR TS_HAS_JEMALLOC
PACKAGE_DEPENDS jemalloc
DEFAULT OFF
)
auto_option(MIMALLOC
FEATURE_VAR TS_HAS_MIMALLOC
PACKAGE_DEPENDS mimalloc
DEFAULT OFF
)
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(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_JEMALLOC "Use jemalloc (default OFF)")
option(ENABLE_LUAJIT "Use LuaJIT (default OFF)")
option(ENABLE_MIMALLOC "Use mimalloc (default OFF)")
option(ENABLE_DOCS "Build docs (default OFF)")
option(ENABLE_DISK_FAILURE_TESTS "Build disk failure tests (enables AIO fault injection, default OFF)" OFF)
if(ENABLE_DISK_FAILURE_TESTS)
Expand Down Expand Up @@ -102,7 +114,7 @@ set(ENABLE_TPROXY
anything else to enable."
)
option(ENABLE_QUICHE "Use quiche (default OFF)")
option(ENABLE_UNWIND "Use libunwind if found on system (default ON)" ON)

option(ENABLE_WCCP "Use WCCP v2 (default OFF)")
option(ENABLE_EXAMPLE "Build example directory (default OFF)")
set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)")
Expand All @@ -120,7 +132,6 @@ set(MAX_THREADS_PER_TYPE
)
set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)")
set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)")
option(TS_USE_HWLOC "Use hwloc (default OFF)")
option(ENABLE_CRIPTS "Build and install the Cripts library and headers (default OFF)")

set(TS_USE_FAST_SDK ${ENABLE_FAST_SDK})
Expand Down Expand Up @@ -177,10 +188,6 @@ if(brotli_FOUND)
set(HAVE_BROTLI_ENCODE_H TRUE)
endif()

if(ENABLE_LUAJIT)
find_package(LuaJIT REQUIRED)
endif()

if(ENABLE_POSIX_CAP)
find_package(cap REQUIRED)
set(TS_USE_POSIX_CAP ${cap_FOUND})
Expand Down Expand Up @@ -222,9 +229,14 @@ if(ENABLE_PROFILER)
set(TS_HAS_PROFILER ${profiler_FOUND})
endif()

find_package(TSMallocReplacement QUIET MODULE)
if(TSMallocReplacement_FOUND)
link_libraries(ts::TSMallocReplacement)
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)
elseif(TS_HAS_MIMALLOC)
link_libraries(mimalloc)
endif()

if(ENABLE_UNWIND)
Expand Down Expand Up @@ -530,3 +542,4 @@ cmake_print_variables(TS_PKGSYSGROUP)
cmake_print_variables(BUILD_MACHINE)
cmake_print_variables(DEFAULT_STACK_SIZE)
cmake_print_variables(CMAKE_INSTALL_RPATH)
print_auto_options_summary()
157 changes: 157 additions & 0 deletions cmake/AutoOptionHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#######################
#
# 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.
#
#######################

set(GLOBAL_AUTO_OPTION_VARS "")

function(_REGISTER_AUTO_OPTION _NAME _FEATURE_VAR _DESCRIPTION _DEFAULT)
add_custom_target(${_NAME}_target)
set_target_properties(${_NAME}_target
PROPERTIES
AUTO_OPTION_FEATURE_VAR ${_FEATURE_VAR}
)

set(${_NAME} ${_DEFAULT} CACHE STRING "${_DESCRIPTION}")
set_property(CACHE ${_NAME} PROPERTY STRINGS AUTO ON OFF)

set(LOCAL_AUTO_OPTION_VARS ${GLOBAL_AUTO_OPTION_VARS})
list(APPEND LOCAL_AUTO_OPTION_VARS "${_NAME}")
set(GLOBAL_AUTO_OPTION_VARS ${LOCAL_AUTO_OPTION_VARS} PARENT_SCOPE)
endfunction()

macro(_CHECK_PACKAGE_DEPENDS _OPTION_VAR _PACKAGE_DEPENDS _FEATURE_VAR)
if(${${_OPTION_VAR}} STREQUAL AUTO)
set(STRICTNESS QUIET)
else()
set(STRICTNESS REQUIRED)
endif()

foreach(PACKAGE_NAME ${_PACKAGE_DEPENDS})
find_package(${PACKAGE_NAME} ${STRICTNESS})
if(NOT ${PACKAGE_NAME}_FOUND)
set(_FEATURE_VAR FALSE)
endif()
endforeach()
endmacro()

# auto_option(<feature_name>
# [DESCRIPTION <description>]
# [DEFAULT <default>]
# [FEATURE_VAR <feature_var>]
# [PACKAGE_DEPENDS <package_one> <package_two> ...]
# )
#
# This macro registers a new auto option and sets its corresponding feature
# variable based on the requirements. The option it creates will be named
# ENABLE_<feature_name>, and the default feature variable will be
# USE_<feature_name>.
#
# It is necessary to have separate variables for the option and the feature
# because the option may be AUTO, but the feature must be enabled or not.
# It is expected that the option will have one of the values ON, OFF, or AUTO,
# and the feature will have one of the values TRUE, or FALSE.
#
# Behavior of the option is as follows:
# - The option is falsey: the feature variable will be FALSE.
# - The option is AUTO: if all requirements are satisfied, the
# feature variable will be TRUE, otherwise FALSE.
# - The option is truthy: if all requirements are satisfied, the
# feature variable will be TRUE, otherwise a fatal error is produced.
#
# DESCRIPTION is the description that will go with the cache entry for the
# option. If not provided, it will be empty.
#
# DEFAULT is the default value of the option. Permitted values are OFF, FALSE, 0
# ON, TRUE, 1, AUTO. If no default is provided, AUTO is the default.
#
# FEATURE_VAR is the variable that will represent whether the feature should be
# used, given the value of the option and whether the requirements for the
# feature are satisfied. By default, it is USE_<feature_name>.
#
# PACKAGE_DEPENDS is a list of packages that are required for the feature.
macro(auto_option _FEATURE_NAME)
cmake_parse_arguments(ARG
""
"DESCRIPTION;DEFAULT;FEATURE_VAR"
"PACKAGE_DEPENDS"
${ARGN}
)

set(OPTION_VAR "ENABLE_${_FEATURE_NAME}")
if(ARG_FEATURE_VAR)
set(FEATURE_VAR ${ARG_FEATURE_VAR})
else()
set(FEATURE_VAR "USE_${_FEATURE_NAME}")
endif()

if(NOT ARG_DEFAULT)
set(DEFAULT AUTO)
elseif(ARG_DEFAULT MATCHES "(ON)|(AUTO)|(TRUE)|(1)")
set(DEFAULT ${ARG_DEFAULT})
else()
message(FATAL_ERROR "Invalid auto_option default ${ARG_DEFAULT}")
endif()

_register_auto_option(${OPTION_VAR} ${FEATURE_VAR} "${ARG_DESCRIPTION}" "${DEFAULT}")

if(${${OPTION_VAR}})
set(${FEATURE_VAR} TRUE)
_check_package_depends(${OPTION_VAR} "${ARG_PACKAGE_DEPENDS}" ${FEATURE_VAR})
else()
set(${FEATURE_VAR} FALSE)
endif()
endmacro()

# Prints a colorized summary of one auto option.
function(PRINT_AUTO_OPTION _NAME)
string(ASCII 27 ESC)
set(COLOR_RED "${ESC}[31m")
set(COLOR_GREEN "${ESC}[32m")
set(COLOR_RESET "${ESC}[m")

set(OPTION_VALUE ${${_NAME}})

get_target_property(FEATURE "${_NAME}_target" AUTO_OPTION_FEATURE_VAR)
set(FEATURE_VALUE ${${FEATURE}})

set(RESET ${COLOR_RESET})
if(FEATURE_VALUE)
if(OPTION_VALUE)
set(COLOR ${COLOR_GREEN})
else()
message(WARNING "${FEATURE} truthy but ${_NAME} isn't!")
set(COLOR ${COLOR_RED})
endif()
else()
if(OPTION_VALUE)
set(COLOR ${COLOR_RED})
else()
set(RESET "")
endif()
endif()

message(STATUS "${FEATURE}: ${COLOR}${FEATURE_VALUE}${RESET} (${OPTION_VALUE})")
endfunction()

# Prints out a colorized summary of all auto options.
function(PRINT_AUTO_OPTIONS_SUMMARY)
message(STATUS "")
message(STATUS "-------- AUTO OPTIONS SUMMARY --------")
foreach(OPTION_NAME ${GLOBAL_AUTO_OPTION_VARS})
print_auto_option(${OPTION_NAME})
endforeach()
message(STATUS "")
endfunction()
76 changes: 0 additions & 76 deletions cmake/FindTSMallocReplacement.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if(NOT OPENSSL_IS_BORINGSSL)
add_subdirectory(ja3_fingerprint)
endif()

if(ENABLE_LUAJIT)
if(USE_LUAJIT)
add_subdirectory(lua)
endif()

Expand Down