-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
199 lines (154 loc) · 5.89 KB
/
CMakeLists.txt
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
189
190
191
192
193
194
195
196
197
198
199
# Top-level CMakeLists.txt
##########################################################################################################
# Set the minimum required version of CMake
cmake_minimum_required(VERSION 3.26)
# Enable verbose output during the build process
set(CMAKE_VERBOSE_MAKEFILE on)
# Project configuration
project(black-scholes-cpp VERSION 1.0 LANGUAGES CXX)
# General
##########################################################################################################
## Set the policy for find_package to use upper-case <PACKAGENAME>_ROOT variables
#cmake_policy(SET CMP0146 OLD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
message(STATUS "C++ Compiler Flags: ${CMAKE_CXX_FLAGS}")
# Set the minimum macOS deployment target
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.5" CACHE STRING "Minimum macOS version")
# Set C++ standard to 20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include default project specifications
include (project-defaults.cmake)
# Google Test & Mocking
##########################################################################################################
## Set GTest root directory
# set(GTEST_ROOT "/opt/homebrew/Cellar/googletest/1.14.0" CACHE PATH "Google Test root directory")
## Locate the Google Test library
# find_package(GTest REQUIRED)
# if(NOT GTest_FOUND)
# message(FATAL_ERROR "Google Test not found. Please make sure it is installed.")
# endif()
# Optionally, enable CTest for running tests with 'make test'
enable_testing()
# Main program executable
##########################################################################################################
# Add subdirectories for project components
add_subdirectory(src)
add_subdirectory(test)
# Executable dependencies
# Collect source files
file(GLOB SOURCES "src/*.cpp" "include/black-scholes-cpp/*.h")
# Check if there are source files before creating the executable
if(SOURCES)
# Create the main executable
add_executable(black_scholes ${SOURCES}
src/optionGreeksModel.cpp)
# Set include directories for the executable
target_include_directories(black_scholes PRIVATE include/black-scholes-cpp)
target_include_directories(black_scholes PRIVATE include/third_party)
# Link the main executable against Google Test, the Black-Scholes library, and other necessary libraries
target_link_libraries(black_scholes
PRIVATE
GTest::gtest
GTest::gtest_main
blackScholesLibrary
curl
)
endif()
# Instantiate and define the Black-Scholes library
##########################################################################################################
# Add the source files for the library
add_library(blackScholesLibrary
src/blackScholesModel.cpp
src/hestonModel.cpp
src/inputReader.cpp
src/optionGreeks.cpp
src/optionGreeksModel.cpp
src/outputWriter.cpp
src/Program.cpp
src/main.cpp
src/optionGreeksModel.cpp
)
# Add include directories for the library
target_include_directories(blackScholesLibrary
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
# Add other include directories as needed
)
# Set compiler features for the library
target_compile_features(blackScholesLibrary PUBLIC cxx_std_20)
# Link against Google Test and other necessary libraries
target_link_libraries(blackScholesLibrary PRIVATE GTest::gtest GTest::gtest_main curl)
# Testing configurations
##########################################################################################################
include(GoogleTest)
include(CTest)
# Discover and run tests using Google Test
gtest_discover_tests(black_scholes)
# Add a test target
add_test(NAME black_scholes_test COMMAND black_scholes)
# Custom targets
##########################################################################################################
# Add a custom target for cleaning up the project and the build directory
add_custom_target(cleanup
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cleanup.cmake
COMMENT "Cleaning build artifacts"
)
# Create a custom target for each test file
# Testing blackScholesModel
add_custom_target(test_blackScholesModel
COMMAND test_blackScholesModel
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for blackScholesModel"
)
# Testing hestonModel
add_custom_target(test_hestonModel
COMMAND test_hestonModel
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for hestonModel"
)
# Testing inputReader
add_custom_target(test_inputReader
COMMAND test_inputReader
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for inputReader"
)
# Testing optionGreeks
add_custom_target(test_optionGreeks
COMMAND test_optionGreeks
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for optionGreeks"
)
# Testing optionGreeksModel
add_custom_target(test_optionGreeksModel
COMMAND test_optionGreeksModel
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for optionGreeksModel"
)
# Testing outputWriter
add_custom_target(test_outputWriter
COMMAND test_outputWriter
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for outputWriter"
)
# Testing Program
add_custom_target(test_Program
COMMAND test_Program
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests for Program"
)
# Add a custom target for running all tests
add_custom_target(run_tests
COMMAND ${CMAKE_CTEST_COMMAND} --verbose
DEPENDS
test_blackScholesModel
test_hestonModel
test_inputReader
test_optionGreeks
test_optionGreeksModel
test_outputWriter
test_Program
# Add other test targets if needed
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running all unit tests"
)