-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
109 lines (94 loc) · 3.2 KB
/
CMakeLists.txt
File metadata and controls
109 lines (94 loc) · 3.2 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
# REMEMBER to put CMAKE bin on path (/home/smoulder/.local)
# mkdir cmake/build
# pushd cmake/build
# cmake -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR ../..
# make -j 4
# popd
cmake_minimum_required(VERSION 3.16)
project(HelloWorld C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(Threads REQUIRED)
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
option(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()
# Proto file
message(STATUS "Using binary directory ${CMAKE_CURRENT_BINARY_DIR}")
# Include generated *.pb.h files
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
foreach(_target
helloworld largefiles)
get_filename_component(${_target}proto "protos/${_target}.proto" ABSOLUTE)
get_filename_component(${_target}proto_path "${${_target}proto}" PATH)
# Generated sources
set(${_target}proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_target}.pb.cc")
set(${_target}proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${_target}.pb.h")
set(${_target}grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_target}.grpc.pb.cc")
set(${_target}grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${_target}.grpc.pb.h")
add_custom_command(
OUTPUT "${${_target}proto_srcs}" "${${_target}proto_hdrs}" "${${_target}grpc_srcs}" "${${_target}grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${${_target}proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${${_target}proto}"
DEPENDS "${${_target}proto}")
add_library(${_target}grpc_proto
${${_target}grpc_srcs}
${${_target}grpc_hdrs}
${${_target}proto_srcs}
${${_target}proto_hdrs})
target_link_libraries(${_target}grpc_proto
absl::check
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
endforeach()
foreach(_target
dummyclient dummyserver)
add_executable(${_target} "${_target}.cpp")
target_link_libraries(${_target}
helloworldgrpc_proto
absl::check
absl::flags
absl::flags_parse
absl::log
absl::log_initialize
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
endforeach()
foreach(_target
largefilesserver largefileclient)
add_executable(${_target} "${_target}.cpp")
target_link_libraries(${_target}
largefilesgrpc_proto
absl::check
absl::flags
absl::flags_parse
absl::log
absl::log_initialize
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
endforeach()