-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
89 lines (70 loc) · 2.55 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
cmake_minimum_required (VERSION 3.1.0)
project(grpc_image_client)
include(cmake/project_version.cmake)
include(GNUInstallDirs)
# For CMake Version >= 3.0: issue FATAL_ERROR if link dependency contains
# double-colons but is not an imported target.
if (POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif ()
# - Configuration for code optimization -
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Build type: DEBUG or RELEASE" FORCE)
endif ()
include(cmake/optimization_flags.cmake)
# - Standard definitions -
add_definitions(-Wall)
# - find protobuf and grpc and compile definitions -
find_package(PkgConfig)
pkg_check_modules(PROTOBUF REQUIRED protobuf)
message(STATUS "Using protobuf ${PROTOBUF_VERSION}")
message(STATUS "PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES}")
find_program(_PROTOBUF_PROTOC protoc)
pkg_check_modules(gRPC REQUIRED grpc++)
message(STATUS "Using gRPC ${gRPC_VERSION}")
message(STATUS "gRPC_LIBRARIES ${gRPC_LIBRARIES}")
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
# Proto file
get_filename_component(ii_proto "protobuf_msgs/image_interface.proto" ABSOLUTE)
get_filename_component(ii_proto_path "${ii_proto}" PATH)
message(STATUS "ii_proto ${ii_proto}")
message(STATUS "ii_proto_path ${ii_proto_path}")
# Generated sources
set(ii_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/image_interface.pb.cc")
set(ii_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/image_interface.pb.h")
set(ii_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/image_interface.grpc.pb.cc")
set(ii_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/image_interface.grpc.pb.h")
add_custom_command(
OUTPUT "${ii_proto_srcs}" "${ii_proto_hdrs}" "${ii_grpc_srcs}" "${ii_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${ii_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${ii_proto}"
DEPENDS "${ii_proto}")
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
# png for saving (optional)
find_package(PNG)
if (PNG_FOUND)
include_directories(${PNG_INCLUDE_DIRS})
add_definitions(-DINCLUDE_PNG)
add_definitions(${PNG_DEFINITIONS})
endif ()
# example client
add_executable(grpc_image_client
src/grpc_image_client.cpp
src/image_utils.cpp
${ii_proto_srcs}
${ii_grpc_srcs}
)
target_link_libraries(grpc_image_client
${PROTOBUF_LIBRARIES}
${gRPC_LIBRARIES}
${PNG_LIBRARIES}
)
install(TARGETS grpc_image_client COMPONENT bin DESTINATION bin)
# - Define information for packaging -
include(cmake/package_debian.cmake)