-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
142 lines (128 loc) · 5.47 KB
/
CMakeLists.txt
File metadata and controls
142 lines (128 loc) · 5.47 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
cmake_minimum_required(VERSION 3.15)
project(basic_grpc)
# Support C++ 14
set(CMAKE_CXX_STANDARD 14)
## Enable testing targets
option(ChirpStackClient_TESTING "Enable testing targets" OFF)
# Find Threads package
find_package(Threads)
# Find Protobuf package
set(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)
# Find protoc compiler
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()
# Find gRPC packet
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
set(_GRPC_GRPCPP gRPC::grpc++)
# Find grpc_cpp_plugin
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()
# Generate Google API code
get_filename_component(google_proto_dir "/usr/local/include/" ABSOLUTE)
set(google_protos
"google/protobuf/descriptor.proto"
"google/api/http.proto"
"google/api/annotations.proto")
set(google_proto_srcs "")
set(google_proto_hdrs "")
set(google_grpc_srcs "")
set(google_grpc_hdrs "")
foreach(google_proto ${google_protos})
get_filename_component(current_proto "${google_proto_dir}/${google_proto}" ABSOLUTE)
get_filename_component(current_proto_path "${current_proto}" PATH)
string(REPLACE ".proto" "" current_file "${google_proto}")
set(current_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.pb.cc")
set(current_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.pb.h")
set(current_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.grpc.pb.cc")
set(current_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.grpc.pb.h")
add_custom_command(
OUTPUT "${current_proto_srcs}" "${current_proto_hdrs}" "${current_grpc_srcs}" "${current_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
--proto_path "${google_proto_dir}"
-I "${current_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${current_proto}"
DEPENDS "${current_proto}")
list(APPEND google_proto_srcs ${current_proto_srcs})
list(APPEND google_proto_hdrs ${current_proto_hdrs})
list(APPEND google_grpc_srcs ${current_grpc_srcs})
list(APPEND google_grpc_hdrs ${current_grpc_hdrs})
endforeach()
# Generate ChirpStack API
get_filename_component(chirpstack_proto_dir "modules/chirpstack-api/protobuf/" ABSOLUTE)
file(GLOB_RECURSE chirpstack_protos RELATIVE ${chirpstack_proto_dir} ${chirpstack_proto_dir}/*.proto)
set(chirpstack_proto_srcs "")
set(chirpstack_proto_hdrs "")
set(chirpstack_grpc_srcs "")
set(chirpstack_grpc_hdrs "")
foreach(chirpstack_proto ${chirpstack_protos})
get_filename_component(current_proto "${chirpstack_proto_dir}/${chirpstack_proto}" ABSOLUTE)
get_filename_component(current_proto_path "${current_proto}" PATH)
string(REPLACE ".proto" "" current_file "${chirpstack_proto}")
set(current_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.pb.cc")
set(current_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.pb.h")
set(current_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.grpc.pb.cc")
set(current_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${current_file}.grpc.pb.h")
add_custom_command(
OUTPUT "${current_proto_srcs}" "${current_proto_hdrs}" "${current_grpc_srcs}" "${current_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
--proto_path "${chirpstack_proto_dir}"
-I "${current_proto_path}" -I "${google_proto_dir}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${current_proto}"
DEPENDS "${current_proto}")
list(APPEND chirpstack_proto_srcs ${current_proto_srcs})
list(APPEND chirpstack_proto_hdrs ${current_proto_hdrs})
list(APPEND chirpstack_grpc_srcs ${current_grpc_srcs})
list(APPEND chirpstack_grpc_hdrs ${current_grpc_hdrs})
endforeach()
# Include binary directory
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Create chirpstack_grpc_proto target
add_library(chirpstack_grpc_proto SHARED
${chirpstack_proto_srcs}
${chirpstack_proto_hdrs}
${chirpstack_grpc_srcs}
${chirpstack_grpc_hdrs}
${google_proto_srcs}
${google_proto_hdrs}
${google_grpc_srcs}
${google_rpc_hdrs})
target_link_libraries(chirpstack_grpc_proto
${_PROTOBUF_LIBPROTOBUF}
${_REFLECTION}
${_GRPC_GRPCPP})
# Include chirpstack_client directory
include_directories("include")
# Create chirpstack_client target
set(chirpstack_client_srcs
"src/chirpstack_client.cc")
set(chirpstack_client_hdrs
"include/chirpstack_client/chirpstack_client.h"
"include/chirpstack_client/messages.h")
add_library(chirpstack_client SHARED
${chirpstack_client_srcs}
${chirpstack_client_hdrs})
target_link_libraries(chirpstack_client
chirpstack_grpc_proto
${_PROTOBUF_LIBPROTOBUF}
${_REFLECTION}
${_GRPC_GRPCPP})
target_include_directories(chirpstack_client
PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
if (ChirpStackClient_TESTING)
add_subdirectory(tests)
endif()