-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
214 lines (178 loc) · 6.25 KB
/
CMakeLists.txt
File metadata and controls
214 lines (178 loc) · 6.25 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
cmake_minimum_required(VERSION 3.9)
project(cornerstone VERSION 0.0.0 LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CheckIPOSupported)
option(BUILD_TESTS "Build unit tests" ON)
add_definitions(-DASIO_STANDALONE)
add_definitions(-DASIO_HAS_STD_CHRONO)
# ASIO requires threads
find_package(Threads REQUIRED)
# Cross compiling
if (CMAKE_SYSTEM_NAME MATCHES Darwin|FreeBSD)
add_definitions(-DOS_FREEBSD)
endif ()
# Builds default to RELEASE
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: None Debug Release."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
# Set default optimizations
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()
# Enable compile commands for clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# If no installation prefix is given manually, install locally.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE STRING
"The install location"
FORCE)
endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(SOURCE_FILES
src/asio_service.cxx
src/buffer.cxx
src/cluster_config.cxx
src/fs_log_store.cxx
src/peer.cxx
src/raft_server.cxx
src/raft_server_req_handlers.cxx
src/raft_server_resp_handlers.cxx
src/snapshot.cxx
src/snapshot_sync_req.cxx
src/srv_config.cxx)
set(TEST_SOURCE_FILES
tests/src/test_async_result.cxx
tests/src/test_buffer.cxx
tests/src/test_everything_together.cxx
tests/src/test_impls.cxx
tests/src/test_log_store.cxx
tests/src/test_logger.cxx
tests/src/test_ptr.cxx
tests/src/test_runner.cxx
tests/src/test_scheduler.cxx
tests/src/test_serialization.cxx
tests/src/test_strfmt.cxx)
set(HEADER_FILES
include/asio_service.hxx
include/async.hxx
include/basic_types.hxx
include/buffer.hxx
include/cluster_config.hxx
include/context.hxx
include/cornerstone.hxx
include/delayed_task.hxx
include/delayed_task_scheduler.hxx
include/fs_log_store.hxx
include/log_entry.hxx
include/log_store.hxx
include/log_val_type.hxx
include/logger.hxx
include/msg_base.hxx
include/msg_type.hxx
include/peer.hxx
include/pp_util.hxx
include/ptr.hxx
include/raft_params.hxx
include/raft_server.hxx
include/req_msg.hxx
include/resp_msg.hxx
include/rpc_cli.hxx
include/rpc_cli_factory.hxx
include/rpc_exception.hxx
include/rpc_listener.hxx
include/snapshot.hxx
include/snapshot_sync_ctx.hxx
include/snapshot_sync_req.hxx
include/srv_config.hxx
include/srv_role.hxx
include/srv_state.hxx
include/state_machine.hxx
include/state_mgr.hxx
include/strfmt.hxx
include/timer_task.hxx)
add_library(cornerstone
${SOURCE_FILES}
${HEADER_FILES})
add_library(cornerstone::cornerstone ALIAS cornerstone)
if (BUILD_TESTS)
enable_testing()
add_executable(testr
${TEST_SOURCE_FILES}
${HEADER_FILES})
add_test(NAME testr COMMAND $<TARGET_FILE:testr>)
endif (BUILD_TESTS)
target_link_libraries(cornerstone
# asio
Threads::Threads
)
if (BUILD_TESTS)
target_link_libraries(testr
cornerstone)
endif (BUILD_TESTS)
set(PROJECT_PREFIX cornerstone-${cornerstone_VERSION})
target_include_directories(cornerstone PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_PREFIX}>
PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR}/asio/asio/include)
if (BUILD_TESTS)
target_include_directories(testr PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE src ${CMAKE_CURRENT_SOURCE_DIR}/asio/asio/include)
endif (BUILD_TESTS)
set(PUBLIC_COMPILE_FEATURES
cxx_std_17
cxx_override
cxx_nullptr)
target_compile_features(cornerstone
PUBLIC ${PUBLIC_COMPILE_FEATURES})
if (BUILD_TESTS)
target_compile_features(testr
PUBLIC ${PUBLIC_COMPILE_FEATURES})
endif (BUILD_TESTS)
set(INSTALL_RUNTIME_DIR ${CMAKE_INSTALL_BINDIR})
set(INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_PREFIX}/cmake)
set(INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_PREFIX}/${CMAKE_BUILD_TYPE})
set(INSTALL_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_PREFIX}/${CMAKE_BUILD_TYPE}/static)
set(INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_PREFIX}/cornerstone)
set(PROJECT_CONFIG_VERSION_FILE "${PROJECT_BINARY_DIR}/cornerstone-config-version.cmake")
set(PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/cornerstone-config.cmake")
configure_package_config_file(cmake/cornerstone-config.cmake.in
${PROJECT_CONFIG_FILE}
INSTALL_DESTINATION ${INSTALL_CONFIG_DIR})
write_basic_package_version_file(
${PROJECT_CONFIG_VERSION_FILE}
COMPATIBILITY SameMajorVersion)
install(TARGETS cornerstone
EXPORT cornerstone-targets
RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR})
install(FILES ${HEADER_FILES}
DESTINATION ${INSTALL_INCLUDE_DIR})
install(FILES
${PROJECT_CONFIG_VERSION_FILE}
${PROJECT_CONFIG_FILE}
DESTINATION ${INSTALL_CONFIG_DIR})
install(EXPORT cornerstone-targets
FILE cornerstone-targets.cmake
NAMESPACE cornerstone::
DESTINATION ${INSTALL_CONFIG_DIR})
export(EXPORT cornerstone-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/cornerstone-targets.cmake
NAMESPACE foo::)
export(PACKAGE cornerstone)
check_ipo_supported(RESULT ipo_supported)
if(ipo_supported)
set_property(TARGET cornerstone PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
find_program(CCACHE_FOUND "ccache")
if(CCACHE_FOUND)
set_property(TARGET cornerstone PROPERTY RULE_LAUNCH_COMPILE ccache)
if(BUILD_TESTS)
set_property(TARGET testr PROPERTY RULE_LAUNCH_LINK ccache)
endif(BUILD_TESTS)
endif(CCACHE_FOUND)