ProtobufLookup.cmake 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. if(NOT Protobuf_FOUND)
  2. find_package(Protobuf CONFIG)
  3. if(NOT Protobuf_FOUND)
  4. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  5. set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
  6. set(FIND_LIBRARY_USE_LIBX32_PATHS FALSE)
  7. set(FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  8. else()
  9. set(FIND_LIBRARY_USE_LIBX32_PATHS TRUE)
  10. set(FIND_LIBRARY_USE_LIB32_PATHS TRUE)
  11. set(FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  12. endif()
  13. find_library(Protobuf_LIBRARY protobuf)
  14. if(NOT Protobuf_LIBRARY STREQUAL PROTOBUF_LIBRARY-NOTFOUND)
  15. add_library(protobuf::libprotobuf SHARED IMPORTED)
  16. set_target_properties(protobuf::libprotobuf PROPERTIES IMPORTED_LOCATION ${Protobuf_LIBRARY})
  17. endif()
  18. find_program(Protobuf_PROTOC_EXECUTABLE protoc)
  19. if(NOT Protobuf_PROTOC_EXECUTABLE STREQUAL Protobuf_PROTOC_EXECUTABLE-NOTFOUND)
  20. add_executable(protobuf::protoc IMPORTED)
  21. set_target_properties(protobuf::protoc PROPERTIES IMPORTED_LOCATION ${Protobuf_PROTOC_EXECUTABLE})
  22. endif()
  23. find_package(Threads)
  24. find_library(Protobuf_PROTOC_LIBRARY protoc)
  25. if(NOT Protobuf_PROTOC_LIBRARY STREQUAL PROTOBUF_PROTOC_LIBRARY-NOTFOUND)
  26. add_library(protobuf::libprotoc SHARED IMPORTED)
  27. set_target_properties(protobuf::libprotoc PROPERTIES IMPORTED_LOCATION ${Protobuf_PROTOC_LIBRARY}
  28. INTERFACE_LINK_LIBRARIES Threads::Threads)
  29. endif()
  30. unset(Protobuf_FOUND)
  31. if(NOT Protobuf_LIBRARY STREQUAL Protobuf_LIBRARY-NOTFOUND
  32. AND NOT Protobuf_PROTOC_EXECUTABLE STREQUAL Protobuf_PROTOC_EXECUTABLE-NOTFOUND
  33. AND NOT Protobuf_PROTOC_LIBRARY STREQUAL Protobuf_PROTOC_LIBRARY-NOTFOUND)
  34. set(Protobuf_FOUND TRUE)
  35. message(STATUS "Found protobuf installation: ${Protobuf_PROTOC_EXECUTABLE} ${Protobuf_PROTOC_LIBRARY} ${Protobuf_LIBRARY}")
  36. else()
  37. message(FATAL_ERROR "Protobuf is a hard dependency of the project. You may install it (with gRPC) by following instructions in cmake/gRPCBuild.cmake script.")
  38. unset(Protobuf_LIBRARY Protobuf_PROTOC_EXECUTABLE Protobuf_PROTOC_LIBRARY)
  39. endif()
  40. endif()
  41. endif()