ProtobufLookup.cmake 1.9 KB

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