You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

  1. cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
  2. project(helloworld_grpc)
  3. # set color
  4. string(ASCII 27 Esc)
  5. set(ColourReset "${Esc}[m")
  6. set(BoldGreen "${Esc}[1;32m")
  7. set(BoldRed "${Esc}[31m")
  8. option(CLEAN_CMAKE_CACHE "更换Build目录运行需要清空缓存" ON)
  9. set(LIB_BASE_DIR /root/CXX_ENVS/wenet_runtime)
  10. #清空缓存
  11. if(CLEAN_CMAKE_CACHE)
  12. message(STATUS "Cleaning CMakeCache.txt")
  13. execute_process(
  14. COMMAND rm -rf *.pb.cc *.pb.h
  15. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  16. )
  17. execute_process(
  18. COMMAND rm -rf !(*.cc|*.proto|CMakeLists.txt)
  19. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  20. )
  21. endif ()
  22. # GRPC and Protocol Buffers libraries location
  23. list(APPEND CMAKE_PREFIX_PATH "${LIB_BASE_DIR}/grpc-build" "${LIB_BASE_DIR}/protobuf-build")
  24. find_package(Protobuf REQUIRED)
  25. find_package(GRPC REQUIRED)
  26. set(PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  27. add_custom_command(
  28. OUTPUT ${PROTO_DIR}/helloworld.pb.cc
  29. ${PROTO_DIR}/helloworld.pb.h
  30. ${PROTO_DIR}/helloworld.grpc.pb.cc
  31. ${PROTO_DIR}/helloworld.grpc.pb.h
  32. COMMAND protobuf::protoc
  33. ARGS --grpc_out "${PROTO_DIR}"
  34. --cpp_out "${PROTO_DIR}"
  35. --plugin=protoc-gen-grpc=gRPC::grpc_cpp_plugin
  36. ${PROTO_DIR}/helloworld.proto)
  37. message("${BoldGreen}add files at ${PROTO_DIR} successfully!${ColourReset}")
  38. add_library(test2_grpc STATIC
  39. ${PROTO_DIR}/helloworld.pb.cc
  40. ${PROTO_DIR}/helloworld.pb.h
  41. ${PROTO_DIR}/helloworld.grpc.pb.cc
  42. ${PROTO_DIR}/helloworld.grpc.pb.h)
  43. target_link_libraries(wenet_proto PUBLIC ${third_party_libraries})
  44. foreach(_target
  45. greeter_client greeter_server
  46. greeter_async_client greeter_async_client2 greeter_async_server)
  47. add_executable(${_target} "${_target}.cc")
  48. target_link_libraries(${_target} test2_grpc ${third_party_libraries})
  49. endforeach()