sled/CMakeLists.txt

258 lines
9.4 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.1
2024-03-25 17:23:48 +08:00
LANGUAGES C CXX)
2024-02-23 18:07:37 +08:00
2024-04-10 22:45:16 +08:00
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
endif()
2024-04-07 10:42:12 +08:00
# set(CMAKE_C_FLAGS "-gdwarf-3 -gstrict-dwarf") set(CMAKE_CXX_FLAGS "-gdwarf-3
# -gstrict-dwarf")
2024-02-23 18:07:37 +08:00
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
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-04-13 10:14:57 +08:00
option(SLED_BUILD_PROTOC_PLUGIN "Build protoc plugin" OFF)
2024-04-24 15:50:15 +08:00
option(SLED_WITH_PROTOBUF "With Protobuf" ON)
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)
2024-03-30 23:40:17 +08:00
add_library(test_main STATIC src/sled/testing/test_main.cc)
2024-03-31 00:51:44 +08:00
add_library(benchmark_main STATIC src/sled/testing/benchmark_main.cc)
target_include_directories(test_main PUBLIC src/)
target_include_directories(benchmark_main PUBLIC src/)
2024-02-23 18:07:37 +08:00
add_library(sled STATIC "")
2024-04-29 21:45:37 +08:00
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL)
endif()
2024-02-23 18:07:37 +08:00
2024-05-15 16:47:26 +08:00
add_subdirectory(3party/asio EXCLUDE_FROM_ALL)
2024-03-31 19:44:27 +08:00
add_subdirectory(3party/minilua EXCLUDE_FROM_ALL)
2024-03-17 12:08:21 +08:00
# add_subdirectory(3party/cppuprofile EXCLUDE_FROM_ALL)
2024-04-24 15:50:15 +08:00
if(SLED_WITH_PROTOBUF)
add_subdirectory(3party/protobuf-3.21.12 EXCLUDE_FROM_ALL)
endif()
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-04-10 22:45:16 +08:00
target_include_directories(sled PUBLIC src/ 3party/eigen 3party/rxcpp
3party/nlohammn 3party/toml11)
2024-02-23 18:07:37 +08:00
target_sources(
sled
2024-04-30 23:35:36 +08:00
PRIVATE src/sled/config.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-04-04 11:17:43 +08:00
src/sled/event_bus/event_bus.cc
2024-04-16 00:33:19 +08:00
src/sled/futures/future.cc
src/sled/futures/internal/failure_handling.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
2024-04-04 11:17:43 +08:00
src/sled/operations_chain.cc
2024-03-30 14:13:27 +08:00
src/sled/profiling/profiling.cc
2024-04-04 11:17:43 +08:00
src/sled/random.cc
src/sled/sigslot.cc
src/sled/status.cc
2024-03-30 14:13:27 +08:00
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
2024-04-14 02:42:50 +08:00
src/sled/system/hot_reloader.cc
2024-03-30 14:13:27 +08:00
src/sled/system/pid.cc
src/sled/system/thread.cc
src/sled/system/thread_pool.cc
2024-04-04 11:17:43 +08:00
src/sled/system_time.cc
2024-03-30 14:13:27 +08:00
src/sled/task_queue/pending_task_safety_flag.cc
src/sled/task_queue/task_queue_base.cc
2024-03-31 00:51:44 +08:00
src/sled/testing/benchmark.cc
2024-04-04 11:17:43 +08:00
src/sled/testing/test.cc
2024-03-30 14:13:27 +08:00
src/sled/timer/task_queue_timeout.cc
src/sled/timer/timer.cc
2024-04-04 11:17:43 +08:00
src/sled/time_utils.cc
2024-03-30 14:13:27 +08:00
src/sled/units/time_delta.cc
src/sled/units/timestamp.cc
2024-05-15 19:51:27 +08:00
src/sled/uri.cc
src/sled/nonstd/pugixml/pugixml.cpp)
2024-03-17 12:08:21 +08:00
2024-03-25 17:23:48 +08:00
target_link_libraries(
sled
2024-05-15 16:48:48 +08:00
PUBLIC rpc_core fmt marl minilua asio
2024-04-13 10:14:57 +08:00
# protobuf::libprotoc
2024-04-24 15:50:15 +08:00
PRIVATE dl)
2024-04-29 21:45:37 +08:00
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
2024-04-30 18:08:41 +08:00
target_link_libraries(sled PUBLIC tcmalloc_and_profiler_static)
2024-04-29 21:45:37 +08:00
endif()
2024-04-29 22:07:03 +08:00
2024-04-24 15:50:15 +08:00
if(SLED_WITH_PROTOBUF)
target_link_libraries(sled PUBLIC protobuf::libprotobuf)
endif()
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-04-24 15:50:15 +08:00
if(SLED_WITH_PROTOBUF AND SLED_BUILD_PROTOC_PLUGIN)
2024-04-13 10:14:57 +08:00
add_subdirectory(src/protoc_gen_sled)
endif()
2024-02-28 15:43:32 +08:00
if(SLED_BUILD_BENCHMARK)
2024-03-31 00:51:44 +08:00
# if(NOT TARGET benchmark) find_package(mbenchmark 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
src/sled/event_bus/event_bus_bench.cc
2024-03-31 00:51:44 +08:00
src/sled/random_bench.cc
src/sled/strings/base64_bench.cc
# src/sled/system/fiber/fiber_bench.cc
src/sled/system/thread_bench.cc
src/sled/system/thread_pool_bench.cc
2024-03-31 15:22:51 +08:00
src/sled/system_time_bench.cc
src/sled/uri_bench.cc)
2024-03-31 00:51:44 +08:00
target_link_libraries(sled_benchmark PRIVATE sled benchmark_main)
target_compile_options(sled_benchmark PRIVATE -include
sled/testing/benchmark.h)
2024-02-28 15:43:32 +08:00
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)
2024-03-31 22:55:57 +08:00
set(options NO_MAIN)
2024-03-30 17:44:15 +08:00
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})
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)
2024-03-30 17:44:15 +08:00
target_compile_options(${SLED_TEST_NAME} PRIVATE ${EXTRA_FLAGS})
target_link_options(${SLED_TEST_NAME} PRIVATE ${EXTRA_FLAGS})
endif()
2024-03-30 23:40:17 +08:00
if(MSVC)
target_compile_options(${SLED_TEST_NAME} PRIVATE /FI"sled/testing/test.h")
else()
target_compile_options(${SLED_TEST_NAME} PRIVATE -include
sled/testing/test.h)
endif()
2024-03-30 17:44:15 +08:00
target_include_directories(${SLED_TEST_NAME} PRIVATE ${SLED_TEST_INC_DIRS})
2024-03-31 22:55:57 +08:00
target_link_libraries(
${SLED_TEST_NAME} PRIVATE ${SLED_TEST_LIBS} sled
$<IF:$<BOOL:${SLED_NO_MAIN}>,,test_main>)
2024-03-30 17:44:15 +08:00
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-31 15:22:51 +08:00
enable_testing()
2024-03-30 23:40:17 +08:00
# include(FetchContent) FetchContent_Declare( googletest URL
# https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
# ) FetchContent_MakeAvailable(googletest)
2024-03-30 17:44:15 +08:00
sled_add_test(
NAME
2024-03-30 20:17:55 +08:00
sled_all_tests
2024-03-30 17:44:15 +08:00
SRCS
2024-03-30 23:40:17 +08:00
src/sled/debugging/demangle_test.cc
2024-03-30 14:13:27 +08:00
src/sled/filesystem/path_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
2024-03-30 20:17:55 +08:00
src/sled/strings/utils_test.cc
src/sled/strings/base64_test.cc
2024-03-30 14:13:27 +08:00
src/sled/system/fiber/fiber_test.cc
src/sled/system/thread_pool_test.cc
src/sled/rx_test.cc
2024-03-31 22:55:57 +08:00
src/sled/uri_test.cc)
2024-03-30 17:44:15 +08:00
2024-04-30 23:35:36 +08:00
sled_add_test(NAME sled_thread_pool_test SRCS
src/sled/system/thread_pool_test.cc)
sled_add_test(NAME sled_event_bus_test SRCS
src/sled/event_bus/event_bus_test.cc)
2024-05-15 19:51:27 +08:00
sled_add_test(NAME sled_pugixml_test SRCS tests/pugixml_test.cc)
2024-03-31 22:55:57 +08:00
sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc)
2024-05-15 17:37:43 +08:00
sled_add_test(NAME sled_asio_test SRCS tests/asio_test.cc)
2024-03-31 22:55:57 +08:00
sled_add_test(NAME sled_move_on_copy_test SRCS
src/sled/utility/move_on_copy_test.cc)
sled_add_test(NAME sled_symbolize_test SRCS
src/sled/debugging/symbolize_test.cc NO_MAIN)
sled_add_test(NAME sled_sigslot_test SRCS src/sled/sigslot_test.cc)
2024-04-08 22:29:06 +08:00
sled_add_test(NAME sled_rpc_test SRCS src/sled/network/rpc_test.cc)
2024-04-09 08:30:14 +08:00
sled_add_test(NAME sled_string_view_test SRCS
src/sled/nonstd/string_view_test.cc)
2024-04-09 11:04:48 +08:00
sled_add_test(NAME sled_expected_test SRCS src/sled/nonstd/expected_test.cc)
2024-04-10 20:59:23 +08:00
sled_add_test(NAME sled_config_test SRCS src/sled/config_test.cc)
sled_add_test(NAME sled_ioc_test SRCS src/sled/ioc/ioc_test.cc)
2024-04-10 23:01:22 +08:00
sled_add_test(NAME sled_inja_test SRCS src/sled/nonstd/inja_test.cc)
2024-04-11 18:28:46 +08:00
sled_add_test(NAME sled_fsm_test SRCS src/sled/nonstd/fsm_test.cc)
2024-04-12 23:53:01 +08:00
sled_add_test(NAME sled_timestamp_test SRCS src/sled/units/timestamp_test.cc)
2024-05-01 12:50:42 +08:00
sled_add_test(NAME sled_future_test SRCS src/sled/futures/future_test.cc
src/sled/futures/when_all_test.cc)
2024-04-12 23:53:01 +08:00
sled_add_test(
NAME sled_cache_test SRCS src/sled/cache/lru_cache_test.cc
src/sled/cache/fifo_cache_test.cc src/sled/cache/expire_cache_test.cc)
2024-04-14 02:42:50 +08:00
add_library(hot_reloader_test_dynamic SHARED
src/sled/system/hot_reloader_test_dynamic.cc)
2024-04-30 09:44:13 +08:00
target_include_directories(hot_reloader_test_dynamic PRIVATE src/)
# target_link_libraries(hot_reloader_test_dynamic PRIVATE sled)
2024-04-14 02:42:50 +08:00
message(
STATUS "HOT_RELOADER_TEST_DYNAMIC_LOCATION ${hot_reloader_test_dynamic}")
get_target_property(HOT_RELOADER_TEST_DYNAMIC_LOCATION
hot_reloader_test_dynamic LINK_LIBRARIES)
sled_add_test(
NAME sled_hot_reloader_test SRCS src/sled/system/hot_reloader_test.cc LIBS
hot_reloader_test_dynamic)
target_compile_definitions(
sled_hot_reloader_test
PRIVATE "TEST_BIN_PATH=\"${HOT_RELOADER_TEST_DYNAMIC_LOCATION}\"")
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-31 15:01:37 +08:00
function(add_fuzz_test name sources)
2024-03-30 08:54:42 +08:00
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-31 15:01:37 +08:00
endfunction()
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-31 15:01:37 +08:00
add_fuzz_test(uri_fuzz src/sled/uri_fuzz.cc)
2024-03-25 17:23:48 +08:00
endif(SLED_BUILD_FUZZ)