Consolidate into two static libs - one with assertions and one without

This commit is contained in:
2025-09-05 11:22:04 -04:00
parent d04705624a
commit 72481be46d
6 changed files with 95 additions and 141 deletions

View File

@@ -103,31 +103,8 @@ add_custom_command(
add_custom_target(generate_json_tokens add_custom_target(generate_json_tokens
DEPENDS ${CMAKE_BINARY_DIR}/json_tokens.cpp) DEPENDS ${CMAKE_BINARY_DIR}/json_tokens.cpp)
set(SOURCES add_executable(weaseldb src/main.cpp)
src/main.cpp target_link_libraries(weaseldb weaseldb_sources)
src/config.cpp
src/connection.cpp
src/connection_registry.cpp
src/server.cpp
src/json_commit_request_parser.cpp
src/http_handler.cpp
src/api_url_parser.cpp
src/arena_allocator.cpp
src/format.cpp
src/metric.cpp
src/process_collector.cpp
${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_executable(weaseldb ${SOURCES})
add_dependencies(weaseldb generate_json_tokens)
target_link_libraries(
weaseldb
Threads::Threads
toml11::toml11
weaseljson
simdutf::simdutf
llhttp_static
perfetto)
enable_testing() enable_testing()
@@ -136,145 +113,125 @@ add_library(test_data STATIC benchmarks/test_data.cpp)
target_include_directories(test_data PUBLIC benchmarks) target_include_directories(test_data PUBLIC benchmarks)
target_link_libraries(test_data simdutf::simdutf) target_link_libraries(test_data simdutf::simdutf)
add_executable(test_arena_allocator tests/test_arena_allocator.cpp # Create doctest implementation library
src/arena_allocator.cpp src/format.cpp) add_library(doctest_impl STATIC doctest_impl.cpp)
target_link_libraries(test_arena_allocator doctest::doctest) target_link_libraries(doctest_impl PUBLIC doctest::doctest)
target_include_directories(test_arena_allocator PRIVATE src)
# Create nanobench implementation library
add_library(nanobench_impl STATIC nanobench_impl.cpp)
target_link_libraries(nanobench_impl PUBLIC nanobench)
# Define all source files in one place
set(WEASELDB_SOURCES
src/arena_allocator.cpp
src/format.cpp
src/metric.cpp
src/json_commit_request_parser.cpp
src/api_url_parser.cpp
src/server.cpp
src/connection.cpp
src/connection_registry.cpp
src/http_handler.cpp
src/config.cpp
src/process_collector.cpp
${CMAKE_BINARY_DIR}/json_tokens.cpp)
# Create library based on build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# In debug builds, use single library with assertions enabled
add_library(weaseldb_sources STATIC ${WEASELDB_SOURCES})
add_dependencies(weaseldb_sources generate_json_tokens)
target_include_directories(weaseldb_sources PUBLIC src)
target_link_libraries(
weaseldb_sources PUBLIC simdutf::simdutf weaseljson Threads::Threads
llhttp_static toml11::toml11 perfetto)
target_compile_options(weaseldb_sources PRIVATE -UNDEBUG)
# Alias for tests to use same target name
add_library(weaseldb_sources_debug ALIAS weaseldb_sources)
else()
# In release builds, create both variants
add_library(weaseldb_sources STATIC ${WEASELDB_SOURCES})
add_dependencies(weaseldb_sources generate_json_tokens)
target_include_directories(weaseldb_sources PUBLIC src)
target_link_libraries(
weaseldb_sources PUBLIC simdutf::simdutf weaseljson Threads::Threads
llhttp_static toml11::toml11 perfetto)
# Debug version with assertions enabled for tests
add_library(weaseldb_sources_debug STATIC ${WEASELDB_SOURCES})
add_dependencies(weaseldb_sources_debug generate_json_tokens)
target_include_directories(weaseldb_sources_debug PUBLIC src)
target_link_libraries(
weaseldb_sources_debug PUBLIC simdutf::simdutf weaseljson Threads::Threads
llhttp_static toml11::toml11 perfetto)
target_compile_options(weaseldb_sources_debug PRIVATE -UNDEBUG)
endif()
add_executable(test_arena_allocator tests/test_arena_allocator.cpp)
target_link_libraries(test_arena_allocator doctest_impl weaseldb_sources_debug)
target_compile_options(test_arena_allocator PRIVATE -UNDEBUG) target_compile_options(test_arena_allocator PRIVATE -UNDEBUG)
add_executable( add_executable(
test_commit_request test_commit_request
tests/test_commit_request.cpp src/json_commit_request_parser.cpp tests/test_commit_request.cpp tests/nlohmann_reference_parser.cpp
tests/nlohmann_reference_parser.cpp tests/parser_comparison.cpp tests/parser_comparison.cpp)
src/arena_allocator.cpp ${CMAKE_BINARY_DIR}/json_tokens.cpp) target_link_libraries(test_commit_request doctest_impl weaseldb_sources_debug
add_dependencies(test_commit_request generate_json_tokens) test_data nlohmann_json::nlohmann_json)
target_link_libraries(test_commit_request doctest::doctest weaseljson test_data target_include_directories(test_commit_request PRIVATE tests)
nlohmann_json::nlohmann_json simdutf::simdutf)
target_include_directories(test_commit_request PRIVATE src tests)
target_compile_options(test_commit_request PRIVATE -UNDEBUG) target_compile_options(test_commit_request PRIVATE -UNDEBUG)
add_executable( add_executable(test_http_handler tests/test_http_handler.cpp)
test_http_handler target_link_libraries(test_http_handler doctest_impl weaseldb_sources_debug)
tests/test_http_handler.cpp
src/http_handler.cpp
src/api_url_parser.cpp
src/server.cpp
src/config.cpp
src/json_commit_request_parser.cpp
src/arena_allocator.cpp
src/format.cpp
src/connection.cpp
src/connection_registry.cpp
src/metric.cpp
${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_dependencies(test_http_handler generate_json_tokens)
target_link_libraries(
test_http_handler
doctest::doctest
llhttp_static
Threads::Threads
toml11::toml11
perfetto
simdutf::simdutf
weaseljson)
target_include_directories(test_http_handler PRIVATE src)
target_compile_definitions(test_http_handler
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
target_compile_options(test_http_handler PRIVATE -UNDEBUG) target_compile_options(test_http_handler PRIVATE -UNDEBUG)
add_executable( add_executable(test_server_connection_return
test_server_connection_return tests/test_server_connection_return.cpp)
tests/test_server_connection_return.cpp target_link_libraries(test_server_connection_return doctest_impl
src/server.cpp weaseldb_sources_debug)
src/connection.cpp
src/connection_registry.cpp
src/arena_allocator.cpp
src/config.cpp
src/http_handler.cpp
src/api_url_parser.cpp
src/json_commit_request_parser.cpp
src/format.cpp
src/metric.cpp
${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_dependencies(test_server_connection_return generate_json_tokens)
target_link_libraries(
test_server_connection_return
doctest::doctest
llhttp_static
Threads::Threads
toml11::toml11
perfetto
weaseljson
simdutf::simdutf)
target_include_directories(test_server_connection_return PRIVATE src)
target_compile_definitions(test_server_connection_return
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
target_compile_options(test_server_connection_return PRIVATE -UNDEBUG) target_compile_options(test_server_connection_return PRIVATE -UNDEBUG)
# Metrics system test # Metrics system test
add_executable(test_metric tests/test_metric.cpp src/metric.cpp add_executable(test_metric tests/test_metric.cpp)
src/arena_allocator.cpp src/format.cpp) target_link_libraries(test_metric doctest_impl weaseldb_sources_debug)
target_link_libraries(test_metric doctest::doctest Threads::Threads
simdutf::simdutf weaseljson)
target_include_directories(test_metric PRIVATE src)
target_compile_options(test_metric PRIVATE -UNDEBUG) target_compile_options(test_metric PRIVATE -UNDEBUG)
# Register with CTest # Register with CTest
add_test(NAME metric_tests COMMAND test_metric) add_test(NAME metric_tests COMMAND test_metric)
add_executable(bench_arena_allocator benchmarks/bench_arena_allocator.cpp add_executable(bench_arena_allocator benchmarks/bench_arena_allocator.cpp)
src/arena_allocator.cpp) target_link_libraries(bench_arena_allocator nanobench_impl weaseldb_sources)
target_link_libraries(bench_arena_allocator nanobench)
target_include_directories(bench_arena_allocator PRIVATE src)
add_executable(bench_volatile_loop benchmarks/bench_volatile_loop.cpp) add_executable(bench_volatile_loop benchmarks/bench_volatile_loop.cpp)
target_link_libraries(bench_volatile_loop nanobench) target_link_libraries(bench_volatile_loop nanobench_impl)
add_executable( add_executable(bench_commit_request benchmarks/bench_commit_request.cpp)
bench_commit_request target_link_libraries(bench_commit_request nanobench_impl weaseldb_sources
benchmarks/bench_commit_request.cpp src/json_commit_request_parser.cpp test_data)
src/arena_allocator.cpp ${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_dependencies(bench_commit_request generate_json_tokens)
target_link_libraries(bench_commit_request nanobench weaseljson test_data
simdutf::simdutf)
target_include_directories(bench_commit_request PRIVATE src)
add_executable( add_executable(bench_parser_comparison benchmarks/bench_parser_comparison.cpp)
bench_parser_comparison target_link_libraries(bench_parser_comparison nanobench_impl weaseldb_sources
benchmarks/bench_parser_comparison.cpp src/json_commit_request_parser.cpp test_data nlohmann_json::nlohmann_json)
src/arena_allocator.cpp ${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_dependencies(bench_parser_comparison generate_json_tokens)
target_link_libraries(bench_parser_comparison nanobench weaseljson test_data
nlohmann_json::nlohmann_json simdutf::simdutf)
target_include_directories(bench_parser_comparison target_include_directories(bench_parser_comparison
PRIVATE src ${rapidjson_SOURCE_DIR}/include) PRIVATE ${rapidjson_SOURCE_DIR}/include)
add_executable(bench_thread_pipeline benchmarks/bench_thread_pipeline.cpp) add_executable(bench_thread_pipeline benchmarks/bench_thread_pipeline.cpp)
target_link_libraries(bench_thread_pipeline nanobench Threads::Threads) target_link_libraries(bench_thread_pipeline nanobench_impl Threads::Threads)
target_include_directories(bench_thread_pipeline PRIVATE src) target_include_directories(bench_thread_pipeline PRIVATE src)
add_executable(bench_format_comparison benchmarks/bench_format_comparison.cpp add_executable(bench_format_comparison benchmarks/bench_format_comparison.cpp)
src/arena_allocator.cpp src/format.cpp) target_link_libraries(bench_format_comparison nanobench_impl weaseldb_sources)
target_link_libraries(bench_format_comparison nanobench)
target_include_directories(bench_format_comparison PRIVATE src)
# Metrics system benchmark # Metrics system benchmark
add_executable(bench_metric benchmarks/bench_metric.cpp src/metric.cpp add_executable(bench_metric benchmarks/bench_metric.cpp)
src/arena_allocator.cpp src/format.cpp) target_link_libraries(bench_metric nanobench_impl weaseldb_sources)
target_link_libraries(bench_metric nanobench Threads::Threads simdutf::simdutf
weaseljson)
target_include_directories(bench_metric PRIVATE src)
# Register benchmark with CTest # Register benchmark with CTest
add_test(NAME metric_benchmarks COMMAND bench_metric) add_test(NAME metric_benchmarks COMMAND bench_metric)
# Debug tools # Debug tools
add_executable( add_executable(debug_arena tools/debug_arena.cpp)
debug_arena tools/debug_arena.cpp src/json_commit_request_parser.cpp target_link_libraries(debug_arena weaseldb_sources)
src/arena_allocator.cpp ${CMAKE_BINARY_DIR}/json_tokens.cpp)
add_dependencies(debug_arena generate_json_tokens)
target_link_libraries(debug_arena weaseljson simdutf::simdutf)
target_include_directories(debug_arena PRIVATE src)
# Load tester # Load tester
add_executable(load_tester tools/load_tester.cpp) add_executable(load_tester tools/load_tester.cpp)
@@ -291,11 +248,7 @@ add_test(NAME parser_comparison_benchmarks COMMAND bench_parser_comparison)
add_test(NAME thread_pipeline_benchmarks COMMAND bench_thread_pipeline) add_test(NAME thread_pipeline_benchmarks COMMAND bench_thread_pipeline)
add_test(NAME format_comparison_benchmarks COMMAND bench_format_comparison) add_test(NAME format_comparison_benchmarks COMMAND bench_format_comparison)
add_executable(test_api_url_parser tests/test_api_url_parser.cpp add_executable(test_api_url_parser tests/test_api_url_parser.cpp)
src/api_url_parser.cpp) target_link_libraries(test_api_url_parser doctest_impl weaseldb_sources_debug)
target_link_libraries(test_api_url_parser doctest::doctest)
target_include_directories(test_api_url_parser PRIVATE src)
target_compile_definitions(test_api_url_parser
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
target_compile_options(test_api_url_parser PRIVATE -UNDEBUG) target_compile_options(test_api_url_parser PRIVATE -UNDEBUG)
add_test(NAME api_url_parser_tests COMMAND test_api_url_parser) add_test(NAME api_url_parser_tests COMMAND test_api_url_parser)

2
doctest_impl.cpp Normal file
View File

@@ -0,0 +1,2 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

2
nanobench_impl.cpp Normal file
View File

@@ -0,0 +1,2 @@
#define ANKERL_NANOBENCH_IMPLEMENT
#include <nanobench.h>

View File

@@ -1,4 +1,3 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "arena_allocator.hpp" #include "arena_allocator.hpp"
#include "format.hpp" #include "format.hpp"
#include <cstring> #include <cstring>

View File

@@ -1,4 +1,3 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../benchmarks/test_data.hpp" #include "../benchmarks/test_data.hpp"
#include "parser_comparison.hpp" #include "parser_comparison.hpp"
#include <doctest/doctest.h> #include <doctest/doctest.h>

View File

@@ -1,4 +1,3 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h> #include <doctest/doctest.h>
#include "arena_allocator.hpp" #include "arena_allocator.hpp"