-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
217 lines (183 loc) · 6.66 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
cmake_minimum_required(VERSION 3.10)
project(PropaneDB)
include(FetchContent)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_PREFIX_PATH "./dependencies/deploy")
list(APPEND CMAKE_PREFIX_PATH "./dependencies/deploy/lib/cmake")
list(APPEND CMAKE_PREFIX_PATH "./dependencies/deploy/lib/cmake/rocksdb")
include_directories("./dependencies/deploy/include")
link_directories("./dependencies/deploy/lib")
LIST(APPEND CMAKE_PROGRAM_PATH "./dependencies/deploy/bin")
find_package (glog 0.5.0 REQUIRED)
find_package (Boost 1.76.0 REQUIRED COMPONENTS filesystem)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if ( Protobuf_FOUND )
message( STATUS "Protobuf version : ${Protobuf_VERSION}" )
message( STATUS "Protobuf include path : ${Protobuf_INCLUDE_DIRS}" )
message( STATUS "Protobuf libraries : ${Protobuf_LIBRARIES}" )
message( STATUS "Protobuf compiler libraries : ${Protobuf_PROTOC_LIBRARIES}")
message( STATUS "Protobuf lite libraries : ${Protobuf_LITE_LIBRARIES}")
message( STATUS "Protoc : ${Protobuf_PROTOC_EXECUTABLE}")
else()
message( WARNING "Protobuf package not found -> specify search path via PROTOBUF_ROOT variable")
endif()
find_package(gRPC REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
message(STATUS "gRPC libraries ${gRPC_LIBRARIES}")
find_package(RocksDB REQUIRED )
set(_GRPC_GRPCPP_UNSECURE gRPC::grpc++_unsecure)
find_package(pegtl)
get_filename_component(hw_proto "./protos/propanedb.proto" ABSOLUTE)
get_filename_component(test_proto "./protos/test.proto" ABSOLUTE)
get_filename_component(hw_proto_path "${hw_proto}" PATH)
get_filename_component(base_proto "${CMAKE_SOURCE_DIR}/dependencies/grpc/third_party/protobuf/src" ABSOLUTE)
#"${CMAKE_SOURCE_DIR}/dependencies/grpc/third_party/abseil-cpp")
# Generated sources
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/propanedb.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/propanedb.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/propanedb.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/propanedb.grpc.pb.h")
set(test_hdrs "${CMAKE_CURRENT_BINARY_DIR}/test.pb.cc")
set(test_srcs "${CMAKE_CURRENT_BINARY_DIR}/test.pb.h")
set(descriptor "${CMAKE_CURRENT_BINARY_DIR}/descriptor.bin")
set(BIN_DIR "../dependencies/deploy/bin")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}" -I "${base_proto}"
--plugin=protoc-gen-grpc="${BIN_DIR}/grpc_cpp_plugin"
"${hw_proto}"
DEPENDS "${hw_proto}")
add_custom_command(
OUTPUT "${test_srcs}" "${test_hdrs}"
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --descriptor_set_out "${CMAKE_CURRENT_BINARY_DIR}/descriptor.bin"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}" -I "${base_proto}"
"${test_proto}"
DEPENDS "${test_proto}")
add_custom_target(protoGenerate DEPENDS "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}")
# Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_SOURCE_DIR}/src")
include_directories("${CMAKE_SOURCE_DIR}/dependencies/grpc/third_party/abseil-cpp")
link_directories("${CMAKE_SOURCE_DIR}/dependencies/deploy/lib")
add_library(propane_lib
${hw_grpc_srcs}
${hw_grpc_hdrs}
${hw_proto_srcs}
${hw_proto_hdrs}
src/DatabaseServiceImpl.cpp
src/DatabaseImpl.cpp
src/QueryParser.cpp
src/Query.cpp
src/FileWriter.cpp
)
add_dependencies(propane_lib protoGenerate)
target_link_libraries(propane_lib
Boost::filesystem
rocksdb
pthread
gRPC::grpc++_reflection
gRPC::grpc++
${Protobuf_LIBRARIES}
glog::glog
taocpp::pegtl
PocoFoundation
PocoZip
)
add_executable(server src/Server.cpp )
add_dependencies(server propane_lib )
target_link_libraries(server
propane_lib
${Protobuf_LIBRARIES})
option(USE_GCOV "Use GCOV" OFF) #OFF by default
if(CMAKE_BUILD_TYPE STREQUAL Debug )
#set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=clang-diagnostic-*,clang-analyzer-*")
#set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*,,readability-*")
if(USE_GCOV )
message( "GCOV enabled" )
include (CodeCoverage)
append_coverage_compiler_flags()
include(ExternalProject)
ExternalProject_Add(gcovr
URL https:/gcovr/gcovr/archive/3.2.zip
URL_HASH SHA1=7411d3989116c5fa65519ee1a54237df16944ad2
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(gcovr source_dir)
SET(GCOVR ${source_dir}/scripts/gcovr)
setup_target_for_coverage_gcovr_xml(
NAME test_coverage # New target name
EXECUTABLE unitTest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
DEPENDENCIES unitTest # Dependencies to build first
BASE_DIRECTORY "../" # Base directory for report
# (defaults to PROJECT_SOURCE_DIR)
EXCLUDE "./dependencies/deploy/*" # Patterns to exclude (can be relative
# to BASE_DIRECTORY, with CMake 3.4+)
)
endif(USE_GCOV)
unset(USE_GCOV CACHE) # <---- this is the important!!
FetchContent_Declare(
googletest
URL https:/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_library(test_proto
${test_srcs}
${test_hdrs}
)
target_link_libraries(test_proto
gRPC::grpc++_reflection
gRPC::grpc++
${Protobuf_LIBRARIES})
enable_testing()
add_executable(
unitTest
test/UnitTest.cpp
)
add_dependencies(unitTest propane_lib test_proto)
target_link_libraries(
unitTest
gtest_main
rocksdb
pthread
propane_lib
test_proto
Boost::filesystem
gRPC::grpc++_reflection
gRPC::grpc++
${Protobuf_LIBRARIES})
add_executable(
systemTest
test/SystemTest.cpp
test/Client.cpp
)
add_dependencies(systemTest propane_lib test_proto)
target_link_libraries(
systemTest
gtest_main
rocksdb
pthread
propane_lib
test_proto
Boost::filesystem
gRPC::grpc++_reflection
gRPC::grpc++
${Protobuf_LIBRARIES})
include(GoogleTest)
gtest_discover_tests(unitTest PROPERTIES TIMEOUT 600 RUN_SERIAL)
# gtest_discover_tests(systemTest PROPERTIES TIMEOUT 600 RUN_SERIAL)
endif()