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.

72 lines
2.8 KiB

  1. # 写到了cmake默认查找地点/usr/share/cmake-3.16/Modules
  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 "PROTOBUF_ROOT not set in FindgRPC.cmake")
  23. else()
  24. find_path(PROTOBUF_INCLUDE_DIR google/protobuf/service.h ${PROTOBUF_ROOT}/include)
  25. mark_as_advanced(PROTOBUF_INCLUDE_DIR)
  26. message("${BoldGreen}Find_package protobuf: PROTOBUF_INCLUDE_DIR is ${PROTOBUF_INCLUDE_DIR}${ColourReset}")
  27. set(PROTOBUF_BINARY_DIR ${PROTOBUF_ROOT}/bin)
  28. set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PROTOBUF_ROOT}/lib)
  29. endif ()
  30. # The Protobuf library
  31. find_library(PROTOBUF_LIBRARY NAMES protobuf)
  32. mark_as_advanced(PROTOBUF_LIBRARY)
  33. add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
  34. set_target_properties(protobuf::libprotobuf PROPERTIES
  35. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  36. INTERFACE_LINK_LIBRARIES pthread
  37. IMPORTED_LOCATION ${PROTOBUF_LIBRARY}
  38. )
  39. # The Protobuf lite library
  40. find_library(PROTOBUF_LITE_LIBRARY NAMES protobuf-lite)
  41. mark_as_advanced(PROTOBUF_LITE_LIBRARY)
  42. add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED)
  43. set_target_properties(protobuf::libprotobuf-lite PROPERTIES
  44. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  45. INTERFACE_LINK_LIBRARIES pthread
  46. IMPORTED_LOCATION ${PROTOBUF_LITE_LIBRARY}
  47. )
  48. # The Protobuf Protoc Library
  49. find_library(PROTOBUF_PROTOC_LIBRARY NAMES protoc)
  50. mark_as_advanced(PROTOBUF_PROTOC_LIBRARY)
  51. add_library(protobuf::libprotoc UNKNOWN IMPORTED)
  52. set_target_properties(protobuf::libprotoc PROPERTIES
  53. INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_INCLUDE_DIR}
  54. INTERFACE_LINK_LIBRARIES protobuf::libprotobuf
  55. IMPORTED_LOCATION ${PROTOBUF_PROTOC_LIBRARY}
  56. )
  57. # Find the protoc Executable
  58. find_program(PROTOBUF_PROTOC_EXECUTABLE protoc ${PROTOBUF_BINARY_DIR})
  59. mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE)
  60. message("${BoldGreen}PROTOBUF_PROTOC_EXECUTABLE is ${PROTOBUF_PROTOC_EXECUTABLE}${ColourReset}")
  61. add_executable(protobuf::protoc IMPORTED)
  62. set_target_properties(protobuf::protoc PROPERTIES
  63. IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE}
  64. )
  65. include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
  66. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf DEFAULT_MSG
  67. PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR PROTOBUF_PROTOC_EXECUTABLE)