-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
121 lines (104 loc) · 4.56 KB
/
CMakeLists.txt
File metadata and controls
121 lines (104 loc) · 4.56 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
cmake_minimum_required(VERSION 3.20)
project(forex_backtest_engine VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# vcpkg toolchain が設定されていれば自動的に有効になる
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "vcpkg toolchain")
endif()
# Homebrew prefix (Apple Silicon: /opt/homebrew, Intel: /usr/local)
if(APPLE)
if(EXISTS /opt/homebrew)
set(HOMEBREW_PREFIX /opt/homebrew)
else()
set(HOMEBREW_PREFIX /usr/local)
endif()
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_PREFIX})
endif()
# -----------------------------------------------------------------------
# コンパイルオプション
# -----------------------------------------------------------------------
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "")
add_compile_options(
-O3
-march=native # CPU固有命令(NEON/AVX等)を有効化
-ffast-math # FP再順序・融合を許可
-funroll-loops # ループ展開
-fomit-frame-pointer # フレームポインタ省略
)
# LTO (Link Time Optimization)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
message(STATUS "Release build: -O3 -march=native -ffast-math -flto enabled")
else()
add_compile_options(-O2 -Wall -Wextra)
endif()
endif()
# fast_csv_loader は fast-math 不要(整数パーサ中心)なのでターゲット個別で制御可能
# -----------------------------------------------------------------------
# 依存パッケージ
# -----------------------------------------------------------------------
find_package(nlohmann_json REQUIRED)
# tomlplusplus: vcpkg版 → Homebrew版 → 同梱ヘッダー の順でフォールバック
find_package(tomlplusplus CONFIG QUIET)
if(NOT tomlplusplus_FOUND)
# Homebrew の toml11 または手動配置した toml++ を使用
if(EXISTS ${CMAKE_SOURCE_DIR}/external/tomlplusplus/toml.hpp)
add_library(tomlplusplus_header INTERFACE)
target_include_directories(tomlplusplus_header INTERFACE
${CMAKE_SOURCE_DIR}/external/tomlplusplus)
add_library(tomlplusplus::tomlplusplus ALIAS tomlplusplus_header)
message(STATUS "tomlplusplus: using bundled header")
else()
message(FATAL_ERROR "tomlplusplus not found. Run: mkdir -p external/tomlplusplus && curl -L https://raw.githubusercontent.com/marzer/tomlplusplus/master/toml.hpp -o external/tomlplusplus/toml.hpp")
endif()
endif()
# ONNX Runtime はオプション
find_package(onnxruntime CONFIG QUIET)
# -----------------------------------------------------------------------
# コアライブラリ(実行ファイルとテストで共有)
# -----------------------------------------------------------------------
set(CORE_SOURCES
src/data/csv_loader.cpp
src/data/fast_csv_loader.cpp # mmap高速CSVパーサ
src/broker/simulator.cpp
src/engine/simd_broker.cpp # NEON SIMD SL/TP判定
src/ml/onnx_inferencer.cpp
src/engine/thread_pool.cpp
src/engine/backtest_engine.cpp
src/report/stats.cpp
src/validation/walk_forward.cpp
strategies/dummy_ma_strategy.cpp
)
add_library(backtest_core STATIC ${CORE_SOURCES})
target_include_directories(backtest_core PUBLIC
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/strategies
)
target_link_libraries(backtest_core PUBLIC
nlohmann_json::nlohmann_json
tomlplusplus::tomlplusplus
)
if(onnxruntime_FOUND)
target_compile_definitions(backtest_core PUBLIC ONNXRUNTIME_AVAILABLE)
target_link_libraries(backtest_core PUBLIC onnxruntime::onnxruntime)
message(STATUS "ONNX Runtime found - ML inference enabled")
else()
message(STATUS "ONNX Runtime not found - ML inference disabled (stub mode)")
endif()
# -----------------------------------------------------------------------
# 実行ファイル
# -----------------------------------------------------------------------
add_executable(backtest_engine src/main.cpp)
target_include_directories(backtest_engine PRIVATE
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/strategies
)
target_link_libraries(backtest_engine PRIVATE backtest_core)
# -----------------------------------------------------------------------
# テスト
# -----------------------------------------------------------------------
enable_testing()
add_subdirectory(tests)