cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(helloworld_grpc) # set color string(ASCII 27 Esc) set(ColourReset "${Esc}[m") set(BoldGreen "${Esc}[1;32m") set(BoldRed "${Esc}[31m") option(CLEAN_CMAKE_CACHE "更换Build目录运行需要清空缓存" ON) set(LIB_BASE_DIR /root/CXX_ENVS/wenet_runtime) #清空缓存 if(CLEAN_CMAKE_CACHE) message(STATUS "Cleaning CMakeCache.txt") execute_process( COMMAND rm -rf *.pb.cc *.pb.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) execute_process( COMMAND rm -rf !(*.cc|*.proto|CMakeLists.txt) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif () # GRPC and Protocol Buffers libraries location list(APPEND CMAKE_PREFIX_PATH "${LIB_BASE_DIR}/grpc-build" "${LIB_BASE_DIR}/protobuf-build") find_package(Protobuf REQUIRED) find_package(GRPC REQUIRED) set(PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}) add_custom_command( OUTPUT ${PROTO_DIR}/helloworld.pb.cc ${PROTO_DIR}/helloworld.pb.h ${PROTO_DIR}/helloworld.grpc.pb.cc ${PROTO_DIR}/helloworld.grpc.pb.h COMMAND protobuf::protoc ARGS --grpc_out "${PROTO_DIR}" --cpp_out "${PROTO_DIR}" --plugin=protoc-gen-grpc=gRPC::grpc_cpp_plugin ${PROTO_DIR}/helloworld.proto) message("${BoldGreen}add files at ${PROTO_DIR} successfully!${ColourReset}") add_library(test2_grpc STATIC ${PROTO_DIR}/helloworld.pb.cc ${PROTO_DIR}/helloworld.pb.h ${PROTO_DIR}/helloworld.grpc.pb.cc ${PROTO_DIR}/helloworld.grpc.pb.h) target_link_libraries(wenet_proto PUBLIC ${third_party_libraries}) foreach(_target greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server) add_executable(${_target} "${_target}.cc") target_link_libraries(${_target} test2_grpc ${third_party_libraries}) endforeach()