-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
53 lines (44 loc) · 1.81 KB
/
Copy pathCMakeLists.txt
File metadata and controls
53 lines (44 loc) · 1.81 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
cmake_minimum_required(VERSION 3.15)
project(ApexKey LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
# 1. Find the required packages
find_package(Threads REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
# 2. Path to proto file
set(PROTO_FILE "${CMAKE_CURRENT_SOURCE_DIR}/proto/kv_store.proto")
set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/proto")
# 3. Generate C++ files from the .proto file
# uses gRPC and Protobuf targets to handle generation
get_target_property(grpc_cpp_plugin gRPC::grpc_cpp_plugin LOCATION)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/kv_store.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/kv_store.pb.h"
"${CMAKE_CURRENT_BINARY_DIR}/kv_store.grpc.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/kv_store.grpc.pb.h"
COMMAND protobuf::protoc
ARGS --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
--grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--plugin=protoc-gen-grpc="${grpc_cpp_plugin}"
-I "${PROTO_PATH}"
"${PROTO_FILE}"
DEPENDS "${PROTO_FILE}"
)
# 4. Define Server Executable
add_executable(ApexKeyServer
src/server.cpp
"${CMAKE_CURRENT_BINARY_DIR}/kv_store.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/kv_store.grpc.pb.cc"
)
# 5. Link everything together
target_link_libraries(ApexKeyServer
PRIVATE
gRPC::grpc++
protobuf::libprotobuf
Threads::Threads
)
# 6. Tell the compiler where to find the generated headers
target_include_directories(ApexKeyServer PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
add_executable(ApexKeyClient src/client.cpp "${CMAKE_CURRENT_BINARY_DIR}/kv_store.pb.cc" "${CMAKE_CURRENT_BINARY_DIR}/kv_store.grpc.pb.cc")
target_link_libraries(ApexKeyClient PRIVATE gRPC::grpc++ protobuf::libprotobuf Threads::Threads)
target_include_directories(ApexKeyClient PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")