From 1c50b16eedf8ecbf2578e63336a2b552a89814fe Mon Sep 17 00:00:00 2001 From: freshthinking Date: Sat, 23 Aug 2025 15:45:11 -0500 Subject: [PATCH 1/2] Enable ASAN and clang-tidy options --- .clang-tidy | 3 +++ .gitignore | 3 +++ CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++ README.md | 20 +++++++++++++++- docs/README.md | 3 +++ src/CMakeLists.txt | 9 +++++++ src/core/logger.h | 12 ++++++++++ src/engine/matching_engine.h | 8 +++++++ src/exchanges/cme/adapter.h | 8 +++++++ src/exchanges/eurex/adapter.h | 8 +++++++ src/exchanges/ice/adapter.h | 8 +++++++ src/sim/main.cpp | 6 +++++ tests/CMakeLists.txt | 1 + 13 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 .clang-tidy create mode 100644 CMakeLists.txt create mode 100644 docs/README.md create mode 100644 src/CMakeLists.txt create mode 100644 src/core/logger.h create mode 100644 src/engine/matching_engine.h create mode 100644 src/exchanges/cme/adapter.h create mode 100644 src/exchanges/eurex/adapter.h create mode 100644 src/exchanges/ice/adapter.h create mode 100644 src/sim/main.cpp create mode 100644 tests/CMakeLists.txt diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..ab2e266 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,3 @@ +Checks: '-*,bugprone-*,performance-*,modernize-*' +WarningsAsErrors: '' +HeaderFilterRegex: 'src/.*' diff --git a/.gitignore b/.gitignore index d4fb281..be640a8 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ # debug information files *.dwo + +# Build directories +/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e14ff1a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.25) +project(ExchangeSimulator VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +option(ENABLE_ASAN "Enable AddressSanitizer" OFF) +if(ENABLE_ASAN) + if(MSVC) + add_compile_options(/fsanitize=address) + add_link_options(/fsanitize=address) + else() + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address) + endif() +endif() + +option(ENABLE_CLANG_TIDY "Enable clang-tidy analysis" OFF) +if(ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXE NAMES clang-tidy) + if(CLANG_TIDY_EXE) + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE}) + else() + message(WARNING "clang-tidy requested but executable not found") + endif() +endif() + +include(FetchContent) +FetchContent_Declare( + spdlog + GIT_REPOSITORY https://github.com/gabime/spdlog.git + GIT_TAG v1.12.0 +) +FetchContent_MakeAvailable(spdlog) + +add_subdirectory(src) + +# Tests +option(BUILD_TESTING "Build tests" ON) +if(BUILD_TESTING) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/README.md b/README.md index c5dc79d..32a984e 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# ExchangeSimulator \ No newline at end of file +# ExchangeSimulator + +A cross-platform exchange matching engine simulator written in modern C++23. + +## Building + +```bash +cmake -S . -B build +cmake --build build +``` + +Pass optional flags to enable developer tooling: + +```bash +cmake -S . -B build -DENABLE_ASAN=ON # AddressSanitizer +cmake -S . -B build -DENABLE_CLANG_TIDY=ON # clang-tidy analysis +``` + +Requires the [spdlog](https://github.com/gabime/spdlog) library to be available to the build system. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..5fac8ba --- /dev/null +++ b/docs/README.md @@ -0,0 +1,3 @@ +# ExchangeSimulator Documentation + +Documentation will be added here. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4e8c188 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(core INTERFACE) +target_include_directories(core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/core) +target_link_libraries(core INTERFACE spdlog::spdlog) + +add_library(engine INTERFACE) +target_include_directories(engine INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/engine) + +add_executable(exchange_simulator sim/main.cpp) +target_link_libraries(exchange_simulator PRIVATE core engine) diff --git a/src/core/logger.h b/src/core/logger.h new file mode 100644 index 0000000..c729086 --- /dev/null +++ b/src/core/logger.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +namespace es { + +inline void info(std::string_view msg) { + spdlog::info("{}", msg); +} + +} // namespace es diff --git a/src/engine/matching_engine.h b/src/engine/matching_engine.h new file mode 100644 index 0000000..96532f7 --- /dev/null +++ b/src/engine/matching_engine.h @@ -0,0 +1,8 @@ +#pragma once + +namespace es { +class MatchingEngine { +public: + void run(); +}; +} diff --git a/src/exchanges/cme/adapter.h b/src/exchanges/cme/adapter.h new file mode 100644 index 0000000..6a79734 --- /dev/null +++ b/src/exchanges/cme/adapter.h @@ -0,0 +1,8 @@ +#pragma once + +namespace es::cme { +class Adapter { +public: + void connect(); +}; +} diff --git a/src/exchanges/eurex/adapter.h b/src/exchanges/eurex/adapter.h new file mode 100644 index 0000000..905d98e --- /dev/null +++ b/src/exchanges/eurex/adapter.h @@ -0,0 +1,8 @@ +#pragma once + +namespace es::eurex { +class Adapter { +public: + void connect(); +}; +} diff --git a/src/exchanges/ice/adapter.h b/src/exchanges/ice/adapter.h new file mode 100644 index 0000000..ab551a3 --- /dev/null +++ b/src/exchanges/ice/adapter.h @@ -0,0 +1,8 @@ +#pragma once + +namespace es::ice { +class Adapter { +public: + void connect(); +}; +} diff --git a/src/sim/main.cpp b/src/sim/main.cpp new file mode 100644 index 0000000..d8d3f33 --- /dev/null +++ b/src/sim/main.cpp @@ -0,0 +1,6 @@ +#include "core/logger.h" + +int main() { + es::info("ExchangeSimulator skeleton"); + return 0; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..b7aa1da --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +# Placeholder for future tests From 24d26329a1f04fbcddafe895d5db7f8038116360 Mon Sep 17 00:00:00 2001 From: kzhdev Date: Sat, 23 Aug 2025 18:47:18 -0500 Subject: [PATCH 2/2] init commit --- CMakeLists.txt | 1 + src/CMakeLists.txt | 5 +++-- src/core/logger.h | 9 ++++++--- src/sim/main.cpp | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e14ff1a..3ce8cf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ FetchContent_Declare( GIT_TAG v1.12.0 ) FetchContent_MakeAvailable(spdlog) +add_definitions(-DSPDLOG_USE_STD_FORMAT -DSPDLOG_USE_STD_FORMAT_HO) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e8c188..fe6c49e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,10 @@ add_library(core INTERFACE) target_include_directories(core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/core) -target_link_libraries(core INTERFACE spdlog::spdlog) +target_link_libraries(core INTERFACE spdlog::spdlog_header_only) add_library(engine INTERFACE) target_include_directories(engine INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/engine) add_executable(exchange_simulator sim/main.cpp) -target_link_libraries(exchange_simulator PRIVATE core engine) +target_link_libraries(exchange_simulator PRIVATE core engine spdlog::spdlog_header_only) +target_include_directories(exchange_simulator PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/core/logger.h b/src/core/logger.h index c729086..c5f8354 100644 --- a/src/core/logger.h +++ b/src/core/logger.h @@ -5,8 +5,11 @@ namespace es { -inline void info(std::string_view msg) { - spdlog::info("{}", msg); -} +#define LOG_INFO(...) SPDLOG_INFO(__VA_ARGS__) +#define LOG_WARN(...) SPDLOG_WARN(__VA_ARGS__) +#define LOG_ERROR(...) SPDLOG_ERROR(__VA_ARGS__) +#define LOG_DEBUG(...) SPDLOG_DEBUG(__VA_ARGS__) +#define LOG_TRACE(...) SPDLOG_TRACE(__VA_ARGS__) +#define LOG_CRITICAL(...) SPDLOG_CRITICAL(__VA_ARGS__) } // namespace es diff --git a/src/sim/main.cpp b/src/sim/main.cpp index d8d3f33..ca3ece1 100644 --- a/src/sim/main.cpp +++ b/src/sim/main.cpp @@ -1,6 +1,6 @@ -#include "core/logger.h" +#include int main() { - es::info("ExchangeSimulator skeleton"); + SPDLOG_INFO("ExchangeSimulator skeleton"); return 0; }