Last active
April 18, 2021 05:16
-
-
Save alexcpn/50c9ae6462b4b546c1df52de5329a68d to your computer and use it in GitHub Desktop.
CMake for GRPC Protobuffer C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.3) | |
project(CvMat) | |
find_package(Protobuf 3.2 REQUIRED) | |
if ( NOT (PROTOBUF_FOUND)) | |
message(FATAL_ERROR "Please Compile and Install ProtoBuffer -version 3 using GRPC C++: CMake will Exit") | |
endif() | |
set(CMAKE_BUILD_TYPE Debug) | |
MESSAGE(${PROTOBUF_PROTOC_EXECUTABLE}) | |
get_filename_component(PROTO_PATH ${CMAKE_SOURCE_DIR} DIRECTORY) | |
set(PROTO_PATH ${PROTO_PATH}/grpc_cvmat/Interfaces) | |
set(GENERATED_PROTOBUF_PATH ${CMAKE_SOURCE_DIR}/generated) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
set(GENERATED_PROTOBUF_PATH "${CMAKE_SOURCE_DIR}/generated") | |
execute_process(COMMAND which grpc_cpp_plugin OUTPUT_VARIABLE GRPC_CPP_PLUGIN) | |
string(STRIP ${GRPC_CPP_PLUGIN} GRPC_CPP_PLUGIN) | |
set(PROTO_LIST "cvmat") | |
set(PROTO_FILE_LIST ${PROTO_PATH} ) | |
foreach(loop_var RANGE 0) | |
list(GET PROTO_LIST ${loop_var} PROTO_FILE_NAME) | |
list(GET PROTO_FILE_LIST ${loop_var} PROTO_PATH) | |
message("file name " ${PROTO_FILE_NAME}) | |
message("file path " ${PROTO_PATH}) | |
add_custom_command( | |
OUTPUT "${PROTO_FILE_NAME}.pb.cc" | |
"${PROTO_FILE_NAME}.pb.h" | |
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} | |
ARGS "--proto_path=${PROTO_PATH}" | |
"--cpp_out=${GENERATED_PROTOBUF_PATH}" | |
"${PROTO_PATH}/${PROTO_FILE_NAME}.proto" | |
) | |
list(APPEND GENERATED_FILES | |
"${GENERATED_PROTOBUF_PATH}/${PROTO_FILE_NAME}.pb.cc" | |
) | |
list(APPEND OUT_FILES ${PROTO_FILE_NAME}.pb.cc ${PROTO_FILE_NAME}.pb.h) | |
endforeach(loop_var) | |
foreach(loop_var RANGE 0) | |
list(GET PROTO_LIST ${loop_var} PROTO_FILE_NAME) | |
list(GET PROTO_FILE_LIST ${loop_var} PROTO_PATH) | |
message("file name " ${PROTO_FILE_NAME}) | |
message("file path " ${PROTO_PATH}) | |
add_custom_command( | |
OUTPUT "${PROTO_FILE_NAME}.grpc.pb.h" | |
"${PROTO_FILE_NAME}.grpc.pb.cc" | |
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} | |
ARGS "--proto_path=${PROTO_PATH}" | |
"--grpc_out=${GENERATED_PROTOBUF_PATH}" | |
"--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}" | |
"${PROTO_PATH}/${PROTO_FILE_NAME}.proto" | |
) | |
list(APPEND GENERATED_FILES | |
"${GENERATED_PROTOBUF_PATH}/${PROTO_FILE_NAME}.grpc.pb.cc" | |
) | |
list(APPEND OUT_FILES ${PROTO_FILE_NAME}.grpc.pb.cc ${PROTO_FILE_NAME}.grpc.pb.h) | |
endforeach(loop_var) | |
add_custom_target(vsphere_header ALL DEPENDS ${OUT_FILES}) | |
include_directories(${GENERATED_PROTOBUF_PATH}) | |
include_directories(${Protobuf_INCLUDE}) | |
link_libraries(grpc++_unsecure grpc protobuf pthread ) | |
set_source_files_properties(${GENERATED_FILES} | |
PROPERTIES GENERATED TRUE) | |
add_executable(cvMat src/CvMatServer.cc ${GENERATED_FILES}) | |
add_dependencies(cvMat vsphere_header ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment