FindWrapProtobuf.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. cmake_minimum_required(VERSION 3.10)
  2. find_package(Protobuf QUIET)
  3. unset(WrapProtobuf_FOUND)
  4. if(NOT Protobuf_FOUND OR NOT TARGET protobuf::libprotobuf
  5. OR NOT TARGET protobuf::protoc OR NOT TARGET protobuf::libprotoc)
  6. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  7. set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
  8. set(FIND_LIBRARY_USE_LIBX32_PATHS FALSE)
  9. set(FIND_LIBRARY_USE_LIB32_PATHS FALSE)
  10. else()
  11. set(FIND_LIBRARY_USE_LIBX32_PATHS TRUE)
  12. set(FIND_LIBRARY_USE_LIB32_PATHS TRUE)
  13. set(FIND_LIBRARY_USE_LIB64_PATHS FALSE)
  14. endif()
  15. find_library(Protobuf_LIBRARY protobuf)
  16. if(NOT TARGET protobuf::libprotobuf AND Protobuf_LIBRARY)
  17. add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
  18. set_target_properties(protobuf::libprotobuf PROPERTIES
  19. IMPORTED_LOCATION ${Protobuf_LIBRARY}
  20. )
  21. if(DEFINED Protobuf_INCLUDE_DIRS)
  22. set_target_properties(protobuf::libprotobuf PROPERTIES
  23. INTERFACE_INCLUDE_DIRECTORIES ${Protobuf_INCLUDE_DIRS})
  24. endif()
  25. endif()
  26. find_program(Protobuf_PROTOC_EXECUTABLE protoc)
  27. if(NOT TARGET protobuf::protoc AND Protobuf_PROTOC_EXECUTABLE)
  28. add_executable(protobuf::protoc IMPORTED)
  29. set_target_properties(protobuf::protoc PROPERTIES IMPORTED_LOCATION ${Protobuf_PROTOC_EXECUTABLE})
  30. endif()
  31. find_package(Threads)
  32. find_library(Protobuf_PROTOC_LIBRARY protoc)
  33. if(NOT TARGET protobuf::libprotoc AND Protobuf_PROTOC_LIBRARY)
  34. add_library(protobuf::libprotoc UNKNOWN IMPORTED)
  35. set_target_properties(protobuf::libprotoc PROPERTIES IMPORTED_LOCATION ${Protobuf_PROTOC_LIBRARY}
  36. INTERFACE_LINK_LIBRARIES Threads::Threads)
  37. endif()
  38. if(TARGET protobuf::libprotoc AND TARGET protobuf::protoc AND TARGET protobuf::libprotobuf)
  39. set(WrapProtobuf_FOUND TRUE)
  40. endif()
  41. else()
  42. set(WrapProtobuf_FOUND TRUE)
  43. endif()