-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
188 lines (162 loc) · 6.63 KB
/
CMakeLists.txt
File metadata and controls
188 lines (162 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
cmake_minimum_required(VERSION 3.20)
# XGBoost inference has been moved to P25 (Market Maker) for lower latency
# P24 now focuses solely on PCIe reception and Disruptor publishing
# Expected latency improvement: ~300µs -> ~5µs
project(OrderGateway C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Project 24: Order Gateway
# PCIe Input + Disruptor Output (XGBoost moved to P25)
message(STATUS "==============================================")
message(STATUS " Project 24: Order Gateway")
message(STATUS " PCIe + Disruptor (low-latency passthrough)")
message(STATUS "==============================================")
# Add vcpkg installed directory to CMAKE_PREFIX_PATH if it exists
# BUT: Skip vcpkg when cross-compiling (e.g., with Buildroot toolchain)
# vcpkg libraries are built with host compiler and won't work with cross-compiler
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross-compiling detected - skipping vcpkg (use Buildroot packages instead)")
# Explicitly remove vcpkg paths to prevent CMake from finding host-built libraries
list(REMOVE_ITEM CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux/share")
# Also remove from CMAKE_FIND_ROOT_PATH if set
list(REMOVE_ITEM CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux")
elseif(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux/share")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/x64-linux/share")
message(STATUS "Added vcpkg_installed to CMAKE_PREFIX_PATH")
endif()
# Required packages
find_package(Threads REQUIRED)
# spdlog - use system library when cross-compiling, FetchContent otherwise
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross-compiling: using system spdlog with external fmt")
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)
# Tell spdlog to use external fmt (Buildroot configuration)
add_compile_definitions(SPDLOG_FMT_EXTERNAL)
else()
# Native build: use FetchContent with bundled fmt to avoid system fmt version conflicts
message(STATUS "Native build: using FetchContent spdlog with bundled fmt")
include(FetchContent)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.14.1
GIT_SHALLOW TRUE
)
set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE) # Use bundled fmt
set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE) # Static/header-only
FetchContent_MakeAvailable(spdlog)
endif()
# nlohmann_json - try find_package first, fallback to FetchContent
find_package(nlohmann_json CONFIG QUIET)
if(NOT nlohmann_json_FOUND)
message(STATUS "nlohmann_json not found, fetching from GitHub...")
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(nlohmann_json)
endif()
# Set default build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
message(STATUS "CMAKE_BUILD_TYPE not set, defaulting to Release")
endif()
# Generate compile_commands.json for IntelliSense
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Include directories
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/../common)
# Source files (PCIe + Disruptor passthrough)
set(SOURCES
src/main.cpp
src/order_gateway.cpp
src/pcie_listener_v2.cpp
)
# Assembly optimization files (x86-64 BSWAP + AVX2)
set(ASM_SOURCES
src/asm/bbo_parser_asm.S
)
# Enable assembly language support
enable_language(ASM)
# Executable
add_executable(order_gateway ${SOURCES} ${ASM_SOURCES})
# Link libraries
if(CMAKE_CROSSCOMPILING)
# Cross-compile: use system spdlog with external fmt
target_link_libraries(order_gateway PRIVATE
spdlog::spdlog
fmt::fmt
nlohmann_json::nlohmann_json
Threads::Threads
)
else()
# Native: spdlog_header_only with bundled fmt
target_link_libraries(order_gateway PRIVATE
spdlog::spdlog_header_only
nlohmann_json::nlohmann_json
Threads::Threads
)
endif()
# Ensure libstdc++ is linked (required for C++ ABI functions)
# This is especially important when cross-compiling
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(order_gateway PRIVATE stdc++fs) # C++17 filesystem
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross-compiling: ensuring libstdc++ is linked from Buildroot toolchain")
endif()
endif()
# Linux-specific optimizations
if(UNIX AND NOT APPLE)
target_compile_options(order_gateway PRIVATE -march=native -O3)
endif()
# Installation
install(TARGETS order_gateway DESTINATION bin)
# =============================================================================
# Benchmark target (optional - requires Google Benchmark)
# =============================================================================
find_package(benchmark QUIET)
if(benchmark_FOUND)
message(STATUS "Google Benchmark found - building bbo_benchmark")
add_executable(bbo_benchmark
benchmark/bbo_benchmark.cpp
${ASM_SOURCES}
)
target_include_directories(bbo_benchmark PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(bbo_benchmark PRIVATE
benchmark::benchmark
Threads::Threads
)
target_compile_options(bbo_benchmark PRIVATE -march=native -O3)
# Add benchmark to install
install(TARGETS bbo_benchmark DESTINATION bin)
else()
message(STATUS "Google Benchmark not found - skipping bbo_benchmark")
message(STATUS " Install with: sudo apt install libbenchmark-dev")
endif()
# Standalone assembly test (no external dependencies)
add_executable(bbo_test
benchmark/bbo_test.cpp
${ASM_SOURCES}
)
target_include_directories(bbo_test PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_options(bbo_test PRIVATE -march=native -O3)
# Ring buffer benchmark (demonstrates V2 listener improvements)
add_executable(ring_buffer_benchmark
benchmark/ring_buffer_benchmark.cpp
)
target_include_directories(ring_buffer_benchmark PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(ring_buffer_benchmark PRIVATE Threads::Threads)
target_compile_options(ring_buffer_benchmark PRIVATE -march=native -O3)
install(TARGETS ring_buffer_benchmark DESTINATION bin)
# Print build information
message(STATUS "")
message(STATUS "Build configuration:")
message(STATUS " CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS " CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message(STATUS " CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
message(STATUS " Mode: Low-latency passthrough (XGBoost inference moved to P25)")
message(STATUS "")