sled/CMakeLists.txt

199 lines
6.5 KiB
CMake
Raw Normal View History

2024-03-01 19:40:00 +08:00
cmake_minimum_required(VERSION 3.10)
2024-03-25 17:23:48 +08:00
project(
sled
VERSION 0.1.0
LANGUAGES C CXX)
2024-02-23 18:07:37 +08:00
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
2024-02-28 15:43:32 +08:00
option(SLED_BUILD_BENCHMARK "Build benchmark" OFF)
2024-03-01 14:50:55 +08:00
option(SLED_BUILD_TESTS "Build tests" OFF)
2024-03-22 21:24:11 +08:00
option(SLED_BUILD_FUZZ "Build fuzzer test" OFF)
2024-03-30 14:13:27 +08:00
option(SLED_LOCATION_PATH "" "sled/src/sled/system/location.cc")
2024-02-28 15:43:32 +08:00
2024-02-23 18:07:37 +08:00
set(BUILD_STATIC ON)
set(BUILD_RTTR_DYNAMIC OFF)
set(BUILD_UNIT_TESTS OFF)
set(BUILD_EXAMPLES OFF)
add_library(sled STATIC "")
2024-03-17 10:11:06 +08:00
add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL)
2024-03-27 23:16:26 +08:00
add_subdirectory(3party/asyncplusplus EXCLUDE_FROM_ALL)
2024-03-17 12:08:21 +08:00
# add_subdirectory(3party/cppuprofile EXCLUDE_FROM_ALL)
2024-03-27 23:16:26 +08:00
# add_subdirectory(3party/protobuf-3.21.12 EXCLUDE_FROM_ALL)
2024-03-25 17:23:48 +08:00
if(NOT TARGET marl)
2024-03-30 08:54:42 +08:00
add_subdirectory(3party/marl EXCLUDE_FROM_ALL)
2024-03-08 18:05:40 +08:00
endif()
2024-03-25 17:23:48 +08:00
if(NOT TARGET rpc_core)
2024-03-30 08:54:42 +08:00
add_subdirectory(3party/rpc_core EXCLUDE_FROM_ALL)
2024-03-07 10:10:16 +08:00
endif()
2024-03-25 17:23:48 +08:00
if(NOT TARGET fmt)
2024-03-30 08:54:42 +08:00
add_subdirectory(3party/fmt EXCLUDE_FROM_ALL)
2024-03-07 10:10:16 +08:00
endif()
2024-03-07 13:05:09 +08:00
2024-03-25 17:23:48 +08:00
if(SLED_LOCATION_PATH)
2024-03-30 08:54:42 +08:00
target_compile_definitions(
2024-03-25 17:23:48 +08:00
sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
2024-03-07 12:43:25 +08:00
endif()
2024-02-23 18:07:37 +08:00
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
2024-03-30 14:13:27 +08:00
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/inja
2024-03-25 17:23:48 +08:00
3party/rxcpp)
2024-02-23 18:07:37 +08:00
target_sources(
sled
2024-03-30 14:13:27 +08:00
PRIVATE src/sled/async/async.cc
2024-03-30 19:36:02 +08:00
src/sled/debugging/demangle.cc
2024-03-30 17:44:15 +08:00
src/sled/debugging/symbolize.cc
2024-03-30 14:13:27 +08:00
src/sled/filesystem/path.cc
src/sled/log/log.cc
src/sled/network/async_resolver.cc
src/sled/network/ip_address.cc
src/sled/network/null_socket_server.cc
src/sled/network/physical_socket_server.cc
src/sled/network/socket_address.cc
src/sled/network/socket_server.cc
src/sled/profiling/profiling.cc
src/sled/strings/base64.cc
src/sled/strings/utils.cc
src/sled/synchronization/event.cc
src/sled/synchronization/mutex.cc
src/sled/synchronization/sequence_checker.cc
src/sled/synchronization/thread_local.cc
src/sled/system/location.cc
src/sled/system/pid.cc
src/sled/system/thread.cc
src/sled/system/thread_pool.cc
src/sled/task_queue/pending_task_safety_flag.cc
src/sled/task_queue/task_queue_base.cc
src/sled/timer/task_queue_timeout.cc
src/sled/timer/timer.cc
src/sled/units/time_delta.cc
src/sled/units/timestamp.cc
src/sled/operations_chain.cc
src/sled/random.cc
src/sled/sigslot.cc
src/sled/status.cc
src/sled/system_time.cc
src/sled/time_utils.cc
src/sled/uri.cc)
2024-02-23 18:07:37 +08:00
# set(BUILD_RTTR_DYNAMIC OFF) set(BUILD_UNIT_TESTS OFF)
# set(BUILD_WITH_STATIC_RUNTIME_LIBS ON) set(BUILD_WITH_DOCUMENTATION OFF)
# add_subdirectory(3party/rttr EXCLUDE_FROM_ALL)
2024-03-17 12:08:21 +08:00
include(CheckCCompilerFlag)
check_c_compiler_flag("-Wl,--whole-archive" SUPPORT_COMPILE_WHOLE_ARCHIVE)
2024-03-25 17:23:48 +08:00
if(SUPPORT_COMPILE_WHOLE_ARCHIVE)
2024-03-30 08:54:42 +08:00
set(WHOLE_ARCHIVE_WRAPPER_START "-Wl,--whole-archive")
set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive")
2024-03-17 12:08:21 +08:00
endif()
2024-03-25 17:23:48 +08:00
target_link_libraries(
sled
2024-03-30 08:54:42 +08:00
PUBLIC rpc_core fmt marl Async++
# protobuf::libprotobuf ${WHOLE_ARCHIVE_WRAPPER_START}
2024-03-25 17:23:48 +08:00
tcmalloc_and_profiler_static
# ${WHOLE_ARCHIVE_WRAPPER_END}
2024-03-17 10:11:06 +08:00
)
2024-02-24 10:31:28 +08:00
2024-03-25 17:23:48 +08:00
# set fPIC
2024-03-17 12:08:21 +08:00
set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON)
2024-02-28 15:43:32 +08:00
if(SLED_BUILD_BENCHMARK)
2024-03-30 08:54:42 +08:00
if(NOT TARGET benchmark)
find_package(benchmark REQUIRED)
endif()
2024-03-25 17:23:48 +08:00
2024-03-30 08:54:42 +08:00
add_executable(
2024-03-25 17:23:48 +08:00
sled_benchmark
2024-03-30 14:13:27 +08:00
src/sled/random_bench.cc src/sled/strings/base64_bench.cc
src/sled/system/fiber/fiber_bench.cc src/sled/system/thread_pool_bench.cc
src/sled/system_time_bench.cc)
2024-03-30 08:54:42 +08:00
target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark
2024-02-28 15:43:32 +08:00
benchmark::benchmark_main)
endif(SLED_BUILD_BENCHMARK)
2024-03-01 14:50:55 +08:00
2024-03-30 17:44:15 +08:00
function(sled_add_test)
set(prefix SLED_TEST)
# set(options INC_DIRS LIBS)
set(one_value_keywords NAME)
set(multi_value_keywords SRCS INC_DIRS LIBS)
cmake_parse_arguments("${prefix}" "${options}" "${one_value_keywords}"
"${multi_value_keywords}" ${ARGN})
message(WARNING "SLED_TEST_NAME: ${SLED_TEST_NAME}")
message(WARNING "SLED_TEST_SRCS: ${SLED_TEST_SRCS}")
message(WARNING "SLED_TEST_LIBS: ${SLED_TEST_LIBS}")
add_executable(${SLED_TEST_NAME} ${SLED_TEST_SRCS})
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(EXTRA_FLAGS -Wthread-safety -g -fsanitize=address
-fno-omit-frame-pointer -fno-optimize-sibling-calls)
target_compile_options(${SLED_TEST_NAME} PRIVATE ${EXTRA_FLAGS})
target_link_options(${SLED_TEST_NAME} PRIVATE ${EXTRA_FLAGS})
endif()
target_include_directories(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_INC_DIRS})
target_link_libraries(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_LIBS}
GTest::gtest)
add_test(NAME ${SLED_TEST_NAME} COMMAND ${SLED_TEST_NAME})
endfunction()
2024-03-01 14:50:55 +08:00
if(SLED_BUILD_TESTS)
2024-03-30 08:54:42 +08:00
include(FetchContent)
FetchContent_Declare(
2024-03-25 17:23:48 +08:00
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
2024-03-30 08:54:42 +08:00
FetchContent_MakeAvailable(googletest)
2024-03-30 17:44:15 +08:00
sled_add_test(
NAME
sled_base_test
SRCS
2024-03-30 14:13:27 +08:00
src/sled/async/async_test.cc
src/sled/any_test.cc
src/sled/filesystem/path_test.cc
src/sled/futures/detail/just_test.cc
src/sled/log/fmt_test.cc
src/sled/synchronization/sequence_checker_test.cc
src/sled/cleanup_test.cc
src/sled/status_test.cc
src/sled/status_or_test.cc
src/sled/system/fiber/fiber_test.cc
src/sled/system/thread_pool_test.cc
src/sled/rx_test.cc
2024-03-30 17:44:15 +08:00
src/sled/uri_test.cc
LIBS
sled
GTest::gtest_main)
sled_add_test(
NAME
sled_strings_test
SRCS
src/sled/strings/utils_test.cc
src/sled/strings/base64_test.cc
LIBS
sled
GTest::gtest_main)
2024-03-30 08:54:42 +08:00
2024-03-30 17:44:15 +08:00
sled_add_test(NAME sled_symbolize_test SRCS
src/sled/debugging/symbolize_test.cc LIBS sled)
2024-03-01 14:50:55 +08:00
endif(SLED_BUILD_TESTS)
2024-03-22 21:24:11 +08:00
2024-03-25 17:23:48 +08:00
if(SLED_BUILD_FUZZ)
2024-03-22 21:24:11 +08:00
2024-03-30 08:54:42 +08:00
macro(add_fuzz_test name sources)
add_executable(${name} ${sources})
target_link_libraries(${name} PRIVATE sled)
target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address
2024-03-25 17:23:48 +08:00
-fsanitize-coverage=trace-cmp)
2024-03-30 08:54:42 +08:00
target_link_options(${name} PRIVATE -fsanitize=fuzzer,address
2024-03-25 17:23:48 +08:00
-fsanitize-coverage=trace-cmp)
2024-03-30 08:54:42 +08:00
endmacro()
2024-03-22 21:24:11 +08:00
2024-03-30 14:13:27 +08:00
add_fuzz_test(base64_fuzz src/sled/strings/base64_fuzz.cc)
2024-03-25 17:23:48 +08:00
endif(SLED_BUILD_FUZZ)