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

CMakeLists.txt 2.7 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. find_package(Threads REQUIRED)
  2. # This branch assumes that gRPC and all its dependencies are already installed
  3. # on this system, so they can be located by find_package().
  4. # Find Protobuf installation
  5. # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
  6. #set(protobuf_MODULE_COMPATIBLE TRUE)
  7. #find_package(Protobuf CONFIG REQUIRED)
  8. #message(STATUS "Using protobuf ${protobuf_VERSION}")
  9. add_library(protobuf::libprotobuf ALIAS protobuf::protobuf)
  10. add_executable(protobuf::libprotoc ALIAS protobuf::protoc)
  11. set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
  12. set(_REFLECTION gRPC::grpc++_reflection)
  13. if(CMAKE_CROSSCOMPILING)
  14. find_program(_PROTOBUF_PROTOC protoc)
  15. else()
  16. set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
  17. endif()
  18. # Find gRPC installation
  19. # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
  20. find_package(gRPC CONFIG REQUIRED)
  21. message(STATUS "Using gRPC ${gRPC_VERSION}")
  22. set(_GRPC_GRPCPP gRPC::grpc++)
  23. if(CMAKE_CROSSCOMPILING)
  24. find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
  25. else()
  26. set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
  27. endif()
  28. # Proto file
  29. get_filename_component(hw_proto "ms_service.proto" ABSOLUTE)
  30. get_filename_component(hw_proto_path "${hw_proto}" PATH)
  31. # Generated sources
  32. set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.pb.cc")
  33. set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.pb.h")
  34. set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.grpc.pb.cc")
  35. set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/ms_service.grpc.pb.h")
  36. add_custom_command(
  37. OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
  38. COMMAND ${_PROTOBUF_PROTOC}
  39. ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
  40. --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
  41. -I "${hw_proto_path}"
  42. --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
  43. "${hw_proto}"
  44. DEPENDS "${hw_proto}")
  45. # Include generated *.pb.h files
  46. include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/core"
  47. "${PROJECT_SOURCE_DIR}/mindspore/ccsrc")
  48. file(GLOB_RECURSE CORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  49. "core/*.cc" "core/util/*.cc" "core/version_control/*.cc")
  50. list(APPEND SERVING_SRC "main.cc" ${hw_proto_srcs} ${hw_grpc_srcs} ${CORE_SRC_LIST})
  51. include_directories(${CMAKE_BINARY_DIR})
  52. add_executable(ms_serving ${SERVING_SRC})
  53. target_link_libraries(ms_serving inference mindspore_gvar)
  54. target_link_libraries(ms_serving ${_REFLECTION} ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} pthread)
  55. if (ENABLE_D)
  56. add_compile_definitions(ENABLE_D)
  57. target_link_libraries(ms_serving ${RUNTIME_LIB})
  58. endif()