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.

73 lines
2.9 KiB

  1. #
  2. # Locate and configure the Google Protocol Buffers library
  3. #
  4. # Adds the following targets:
  5. #
  6. # protobuf::libprotobuf - Protobuf library
  7. # protobuf::libprotobuf-lite - Protobuf lite library
  8. # protobuf::libprotoc - Protobuf Protoc Library
  9. # protobuf::protoc - protoc executable
  10. #
  11. #
  12. # Generates C++ sources from the .proto files
  13. #
  14. # protobuf_generate_cpp (<SRCS> <HDRS> <DEST> [<ARGN>...])
  15. #
  16. # SRCS - variable to define with autogenerated source files
  17. # HDRS - variable to define with autogenerated header files
  18. # DEST - directory where the source files will be created
  19. # ARGN - .proto files
  20. #
  21. if(NOT DEFINED PROTOBUF_ROOT)
  22. message(FATAL_ERROR "GRPC_ROOT not set in FindgRPC.cmake")
  23. else()
  24. # Find gRPC include directory
  25. find_path(PROTOBUF_INCLUDE_DIR google/protobuf/service.h ${PROTOBUF_ROOT}/include)
  26. mark_as_advanced(PROTOBUF_INCLUDE_DIR)
  27. message("${BoldGreen}PROTOBUF_INCLUDE_DIR is ${PROTOBUF_INCLUDE_DIR}${ColourReset}")
  28. set(PROTOBUF_BINARY_DIR ${PROTOBUF_ROOT}/bin)
  29. set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PROTOBUF_ROOT}/lib)
  30. message("${BoldGreen}PROTOBUF_BINARY_DIR is ${PROTOBUF_BINARY_DIR}${ColourReset}")
  31. endif ()
  32. # The Protobuf library
  33. find_library(PROTOBUF_LIBRARY NAMES protobuf)
  34. mark_as_advanced(PROTOBUF_LIBRARY)
  35. add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
  36. set_target_properties(protobuf::libprotobuf PROPERTIES
  37. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  38. INTERFACE_LINK_LIBRARIES pthread
  39. IMPORTED_LOCATION ${PROTOBUF_LIBRARY}
  40. )
  41. # The Protobuf lite library
  42. find_library(PROTOBUF_LITE_LIBRARY NAMES protobuf-lite)
  43. mark_as_advanced(PROTOBUF_LITE_LIBRARY)
  44. add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED)
  45. set_target_properties(protobuf::libprotobuf-lite PROPERTIES
  46. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  47. INTERFACE_LINK_LIBRARIES pthread
  48. IMPORTED_LOCATION ${PROTOBUF_LITE_LIBRARY}
  49. )
  50. # The Protobuf Protoc Library
  51. find_library(PROTOBUF_PROTOC_LIBRARY NAMES protoc)
  52. mark_as_advanced(PROTOBUF_PROTOC_LIBRARY)
  53. add_library(protobuf::libprotoc UNKNOWN IMPORTED)
  54. set_target_properties(protobuf::libprotoc PROPERTIES
  55. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  56. INTERFACE_LINK_LIBRARIES protobuf::libprotobuf
  57. IMPORTED_LOCATION ${PROTOBUF_PROTOC_LIBRARY}
  58. )
  59. # Find the protoc Executable
  60. find_program(PROTOBUF_PROTOC_EXECUTABLE protoc ${PROTOBUF_BINARY_DIR})
  61. mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE)
  62. message("${BoldGreen}PROTOBUF_PROTOC_EXECUTABLE is ${PROTOBUF_PROTOC_EXECUTABLE}${ColourReset}")
  63. add_executable(protobuf::protoc IMPORTED)
  64. set_target_properties(protobuf::protoc PROPERTIES
  65. IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE}
  66. )
  67. include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
  68. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf DEFAULT_MSG
  69. PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR PROTOBUF_PROTOC_EXECUTABLE)