-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
148 lines (124 loc) · 7.1 KB
/
CMakeLists.txt
File metadata and controls
148 lines (124 loc) · 7.1 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
cmake_minimum_required(VERSION 3.15)
project(finmath)
# Set the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add debugging symbols (set to Release for optimized performance if needed)
set(CMAKE_BUILD_TYPE Release)
# --- Profiling / performance analysis ---
# FINMATH_PROFILING=ON: keep debug symbols, frame pointer, suitable for perf/stat/sample
# FINMATH_INSTRUMENTATION=ON: add -pg for gprof-style instrumentation (optional)
option(FINMATH_PROFILING "Build with profiling-friendly flags (symbols, frame pointer)" OFF)
option(FINMATH_INSTRUMENTATION "Build with -pg for gprof instrumentation" OFF)
if(FINMATH_PROFILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-omit-frame-pointer")
message(STATUS "Profiling build: -g -fno-omit-frame-pointer")
endif()
if(FINMATH_INSTRUMENTATION)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
message(STATUS "Instrumentation build: -pg (gprof)")
endif()
# Enable SIMD optimizations based on architecture
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
# x86/x86_64: Enable SSE2 (baseline) and detect AVX
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
# Try to enable AVX if available
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-mavx" COMPILER_SUPPORTS_AVX)
if(COMPILER_SUPPORTS_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
message(STATUS "AVX support enabled")
else()
message(STATUS "AVX not supported, using SSE2")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)")
# ARM64: NEON is standard on ARMv8
message(STATUS "ARM NEON support enabled (ARMv8)")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
# ARM32: Try to enable NEON
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
message(STATUS "ARM NEON support enabled (ARMv7)")
else()
message(STATUS "Using scalar fallback (no SIMD)")
endif()
# Add include directories
include_directories(${PROJECT_SOURCE_DIR}/include)
# Source files
file(GLOB SOURCES "src/cpp/*/*.cpp")
# Create the main C++ library target with a unique name
add_library(finmath_library SHARED ${SOURCES}
"src/cpp/InterestAndAnnuities/simple_interest.cpp"
"include/finmath/InterestAndAnnuities/simple_interest.h"
"include/finmath/InterestAndAnnuities/discount_factor.h"
"include/finmath/InterestAndAnnuities/present_future_value.h"
"include/finmath/InterestAndAnnuities/annuity.h"
"include/finmath/InterestAndAnnuities/cash_flow.h"
"include/finmath/FixedIncome/bond_pricing.h"
"include/finmath/OptionPricing/options_pricing.h"
"include/finmath/OptionPricing/options_pricing_types.h"
"include/finmath/TimeSeries/rolling_volatility.h"
"include/finmath/TimeSeries/simple_moving_average.h"
"include/finmath/TimeSeries/rsi.h"
"include/finmath/TimeSeries/ema.h")
# Link pybind11 headers to the main library (needed for numpy integration in C++ files)
target_link_libraries(finmath_library PUBLIC pybind11::headers)
# Also link Python libraries/headers (needed for Python.h)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
target_link_libraries(finmath_library PUBLIC Python::Python)
# Enable testing
enable_testing()
# Test include dir for test_common.h (optional use by tests)
set(FINMATH_TEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/include)
# Helper macro: add a C++ test executable, link to library, register with CTest, set labels
macro(add_cpp_test test_name source_file)
message(STATUS "Adding C++ test: ${test_name} from ${source_file}")
add_executable(${test_name}_executable ${source_file})
target_include_directories(${test_name}_executable PRIVATE ${FINMATH_TEST_INCLUDE_DIR})
target_link_libraries(${test_name}_executable PRIVATE finmath_library)
add_test(NAME ${test_name} COMMAND ${test_name}_executable)
endmacro()
# Helper: add test and assign CTest labels (e.g. for ctest -L SIMD)
macro(add_cpp_test_labeled test_name source_file labels)
add_cpp_test(${test_name} ${source_file})
set_tests_properties(${test_name} PROPERTIES LABELS "${labels}")
endmacro()
# --- SIMD and helper tests (label: SIMD) ---
# add_cpp_test_labeled(SIMDHelperTest test/Helper/C++/simd_helper_test.cpp "SIMD;Helper;Unit")
# add_cpp_test_labeled(SimpleMovingAverageSIMDTest test/TimeSeries/SimpleMovingAverage/C++/simple_moving_average_simd_test.cpp "SIMD;TimeSeries;Unit")
# add_cpp_test_labeled(RSISIMDTest test/TimeSeries/RSI/C++/rsi_simd_test.cpp "SIMD;TimeSeries;Unit")
# add_cpp_test_labeled(EMASIMDTest test/TimeSeries/EMA/C++/ema_simd_test.cpp "SIMD;TimeSeries;Unit")
# --- Core unit tests ---
add_cpp_test_labeled(CompoundInterestTest test/InterestAndAnnuities/compound_interest_test.cpp "InterestAndAnnuities;Unit")
add_cpp_test_labeled(BlackScholesTest test/OptionPricing/black_scholes_test.cpp "OptionPricing;Unit")
add_cpp_test_labeled(BinomialOptionPricingTest test/OptionPricing/binomial_option_pricing_test.cpp "OptionPricing;Unit")
add_cpp_test_labeled(RSITest test/TimeSeries/rsi_test.cpp "TimeSeries;Unit")
add_cpp_test_labeled(RollingStdDevTest test/TimeSeries/rolling_std_dev_test.cpp "TimeSeries;Unit")
add_cpp_test_labeled(BellmanArbitrageTest test/GraphAlgos/bellman_arbitrage_test.cpp "GraphAlgos;Unit")
add_cpp_test_labeled(BondPricingTest test/FixedIncome/bond_pricing_test.cpp "FixedIncome;Unit")
add_cpp_test_labeled(AnnuityTest test/InterestAndAnnuities/annuity_test.cpp "InterestAndAnnuities;Unit")
add_cpp_test_labeled(CashFlowTest test/InterestAndAnnuities/cash_flow_test.cpp "InterestAndAnnuities;Unit")
add_cpp_test_labeled(DiscountFactorTest test/InterestAndAnnuities/discount_factor_test.cpp "InterestAndAnnuities;Unit")
add_cpp_test_labeled(PresentFutureValueTest test/InterestAndAnnuities/present_future_value_test.cpp "InterestAndAnnuities;Unit")
# add_cpp_test_labeled(RSITest test/TimeSeries/rsi_test.cpp "TimeSeries;Unit")
# add_cpp_test_labeled(RollingStdDevTest test/TimeSeries/rolling_std_dev_test.cpp "TimeSeries;Unit")
# add_cpp_test_labeled(BellmanArbitrageTest test/GraphAlgos/bellman_arbitrage_test.cpp "GraphAlgos;Unit")
# Profiling harness: rolling volatility (scalar path only; SIMD path via Python)
add_executable(RollingVolatilityProfile_harness profiling/harness_rolling_volatility.cpp)
target_link_libraries(RollingVolatilityProfile_harness PRIVATE finmath_library)
# Add pybind11 for Python bindings
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.11.1 # Use a stable version of pybind11
)
FetchContent_MakeAvailable(pybind11)
# Create the Python bindings target
pybind11_add_module(finmath_bindings src/python_bindings.cpp ${SOURCES})
# Set the output name of the bindings to 'finmath' to match your desired module name
set_target_properties(finmath_bindings PROPERTIES OUTPUT_NAME "finmath")
# Set the library output directory to be alongside the source bindings file
set_target_properties(finmath_bindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/src")
# Link the Python bindings target with the C++ library
target_link_libraries(finmath_bindings PRIVATE finmath_library)