-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
197 lines (177 loc) · 6.38 KB
/
Copy pathCMakeLists.txt
File metadata and controls
197 lines (177 loc) · 6.38 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
189
190
191
192
193
194
195
196
197
cmake_minimum_required(VERSION 3.14)
project(bob LANGUAGES C ASM CXX)
set (CMAKE_CXX_STANDARD 17) # redis-plus-plus requires C++17
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
SET(CXX_BOB_FLAGS "/arch:AVX2")
else ()
SET(CXX_BOB_FLAGS "-Wunused-variable -mavx2")
endif()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CXX_BOB_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_BOB_FLAGS}")
# --- Fetch and configure dependencies ---
include(FetchContent)
# redis-plus-plus
FetchContent_Declare(
redis-plus-plus
GIT_REPOSITORY https://github.com/sewenew/redis-plus-plus.git
GIT_TAG 1.3.15 # Using a specific tag for reproducibility
)
# redis-plus-plus specific options
set(REDIS_PLUS_PLUS_USE_HIREDIS_STATIC_LIB ON CACHE BOOL "" FORCE) # Avoid runtime dependency on hiredis
set(REDIS_PLUS_PLUS_BUILD_TEST OFF CACHE BOOL "" FORCE)
set(REDIS_PLUS_PLUS_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(REDIS_PLUS_PLUS_BUILD_SHARED OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(redis-plus-plus)
include_directories(${redis-plus-plus_SOURCE_DIR}/include)
# spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.12.0
)
FetchContent_MakeAvailable(spdlog)
include_directories(${spdlog_SOURCE_DIR}/include)
# cxxopts
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v3.1.1
)
FetchContent_MakeAvailable(cxxopts)
include_directories(${cxxopts_SOURCE_DIR}/include)
# gtest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
FetchContent_MakeAvailable(googletest)
# zstd
FetchContent_Declare(
zstd
GIT_REPOSITORY https://github.com/facebook/zstd.git
GIT_TAG v1.5.7
SOURCE_SUBDIR build/cmake
)
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(ZSTD_BUILD_STATIC ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(zstd)
include_directories(${zstd_SOURCE_DIR}/lib)
# Choose the correct zstd target name depending on how it's defined.
if (TARGET libzstd_static)
set(ZSTD_TARGET libzstd_static)
elseif (TARGET zstd::libzstd_static)
set(ZSTD_TARGET zstd::libzstd_static)
elseif (TARGET zstd::libzstd_shared)
set(ZSTD_TARGET zstd::libzstd_shared)
else()
message(FATAL_ERROR "zstd target not found; expected libzstd_static or zstd::libzstd_static")
endif()
find_package(jsoncpp REQUIRED)
get_target_property(JSONCPP_INCLUDE_DIRS jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
if(JSONCPP_INCLUDE_DIRS)
include_directories(${JSONCPP_INCLUDE_DIRS})
endif()
set(JSONCPP_TARGET jsoncpp_lib)
# drogon
FetchContent_Declare(
drogon
GIT_REPOSITORY https://github.com/drogonframework/drogon.git
GIT_TAG v1.8.7
)
set(BUILD_EXAMPLES OFF CACHE BOOL "Build Drogon examples" FORCE)
set(BUILD_CTL OFF CACHE BOOL "Build drogon_ctl" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "Build Drogon tests" FORCE)
set(BUILD_DOC OFF CACHE BOOL "Build Drogon documentation" FORCE)
FetchContent_MakeAvailable(drogon)
include_directories(${drogon_SOURCE_DIR}/lib/inc)
# Get git commit hash
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT GIT_COMMIT_HASH)
set(GIT_COMMIT_HASH "unknown")
endif()
# Get compiler name and version
set(COMPILER_NAME "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
# Pass to compiler definitions
add_compile_definitions(
GIT_COMMIT_HASH="${GIT_COMMIT_HASH}"
COMPILER_NAME="${COMPILER_NAME}"
)
# Check for AVX2 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-mavx2" COMPILER_SUPPORTS_AVX2)
if (NOT COMPILER_SUPPORTS_AVX2)
message(WARNING "AVX2 not supported by the compiler")
endif ()
# --- Project Sources ---
SET(FILES
${CMAKE_SOURCE_DIR}/connection/connection.cpp
${CMAKE_SOURCE_DIR}/connection/connectionPool.cpp
${CMAKE_SOURCE_DIR}/connection/NodeIntroducer.cpp
${CMAKE_SOURCE_DIR}/database/db.cpp
${CMAKE_SOURCE_DIR}/database/garbageCleaner.cpp
${CMAKE_SOURCE_DIR}/spdlogDriver/Logger.cpp
${CMAKE_SOURCE_DIR}/processors/DataProcessors.cpp
${CMAKE_SOURCE_DIR}/processors/IOProcessor.cpp
${CMAKE_SOURCE_DIR}/processors/QubicServer.cpp
${CMAKE_SOURCE_DIR}/processors/QubicIndexerProcessor.cpp
${CMAKE_SOURCE_DIR}/logEventCore/LoggingEventProcessor.cpp
${CMAKE_SOURCE_DIR}/logEventCore/LoggingEventProcessorCore.cpp
${CMAKE_SOURCE_DIR}/logEventCore/LogEvent.cpp
${CMAKE_SOURCE_DIR}/Config.cpp
${CMAKE_SOURCE_DIR}/bob.cpp
${CMAKE_SOURCE_DIR}/common/GlobalVar.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/bobAPI.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/ApiHelpers.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/querySmartContract.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/RESTServer.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcMapper.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcWebSocket.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcMethods.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicSubscriptionManager.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcHandler.cpp
)
# Create a library from the source files to be shared between the main executable and tests
add_library(bob_lib STATIC ${FILES})
target_link_libraries(bob_lib PRIVATE redis++_static hiredis spdlog::spdlog cxxopts::cxxopts
${ZSTD_TARGET} drogon ${JSONCPP_TARGET})
# --- Executable and Linking ---
ADD_EXECUTABLE(bob main.cpp)
ADD_EXECUTABLE(pop10 pop10.cpp)
target_link_libraries(bob PRIVATE bob_lib)
target_link_libraries(pop10 PRIVATE bob_lib)
# --- Testing with Google Test ---
enable_testing()
include(GoogleTest)
include_directories(${CMAKE_SOURCE_DIR}/)
include_directories(${CMAKE_SOURCE_DIR}/common)
file(GLOB TEST_FILES "tests/*.cpp"
database/db.cpp
logEventCore/LogEvent.cpp
logEventCore/LoggingEventProcessorCore.cpp)
add_executable(bob_tests ${TEST_FILES})
target_link_libraries(bob_tests PRIVATE bob_lib gtest_main gmock redis++_static hiredis spdlog::spdlog)
target_compile_definitions(bob_tests PRIVATE GTEST)
gtest_discover_tests(bob_tests)
# Copy configuration file after building bob
add_custom_command(
TARGET bob POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/default_config_bob.json
${CMAKE_BINARY_DIR}/bob.json
)
# Copy OpenAPI spec to build directory
add_custom_command(
TARGET bob POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/RESTAPI/openapi.json
${CMAKE_BINARY_DIR}/openapi.json
)