SHARE
TWEET

Cmake example

a guest Aug 3rd, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. project(grpc-cmake-example)
  2. cmake_minimum_required(VERSION 3.2)
  3.  
  4. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  5.  
  6. add_compile_options(-std=c++11)
  7.  
  8. # GRPC and Protocol Buffers libraries location
  9. list(APPEND CMAKE_PREFIX_PATH "/usr/local/include")
  10.  
  11. # Cmake find modules
  12. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
  13.  
  14. find_package(Protobuf REQUIRED)
  15. find_package(GRPC REQUIRED)
  16.  
  17. set(PROTOS
  18.     ${CMAKE_CURRENT_SOURCE_DIR}/protos/photo_album.proto
  19. )
  20.  
  21. set(PROTO_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto-src)
  22. file(MAKE_DIRECTORY ${PROTO_SRC_DIR})
  23. include_directories(
  24.     ${PROTO_SRC_DIR}
  25.     ${CMAKE_CURRENT_BINARY_DIR}
  26.     ${CMAKE_SOURCE_DIR}/src/models
  27.     ${CMAKE_SOURCE_DIR}/src/server
  28. )
  29.  
  30. protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_SRC_DIR} ${PROTOS})
  31. grpc_generate_cpp(GRPC_SRCS GRPC_HDRS ${PROTO_SRC_DIR} ${PROTOS})
  32.  
  33. # Building server
  34. add_executable(server
  35.     ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc
  36.     ${CMAKE_CURRENT_SOURCE_DIR}/src/server/server.cc
  37.     ${CMAKE_CURRENT_SOURCE_DIR}/src/server/server.h
  38.     ${CMAKE_CURRENT_SOURCE_DIR}/src/models/models.cc
  39.     ${CMAKE_CURRENT_SOURCE_DIR}/src/models/models.h
  40.     ${PROTO_SRCS}
  41.     ${GRPC_SRCS}
  42. )
  43. target_link_libraries(server
  44.     gRPC::grpc++_reflection
  45.     protobuf::libprotobuf
  46. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top