gRPCLookup.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. find_package(gRPC CONFIG QUIET)
  2. if(NOT gRPC_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_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
  13. if(NOT TARGET gRPC::grpc_cpp_plugin AND NOT gRPC_CPP_PLUGIN_EXECUTABLE STREQUAL gRPC_CPP_PLUGIN_EXECUTABLE-NOTFOUND)
  14. add_executable(gRPC::grpc_cpp_plugin IMPORTED)
  15. set_target_properties(gRPC::grpc_cpp_plugin PROPERTIES IMPORTED_LOCATION ${gRPC_CPP_PLUGIN_EXECUTABLE})
  16. endif()
  17. find_library(gRPC_LIBRARY grpc)
  18. if(NOT TARGET gRPC::grpc AND NOT gRPC_LIBRARY STREQUAL gRPC_LIBRARY-NOTFOUND)
  19. add_library(gRPC::grpc SHARED IMPORTED)
  20. set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION ${gRPC_LIBRARY})
  21. endif()
  22. find_library(gRPC_CPP_LIBRARY grpc++)
  23. if(NOT TARGET gRPC::grpc++ AND NOT gRPC_CPP_LIBRARY STREQUAL gRPC_CPP_LIBRARY-NOTFOUND)
  24. add_library(gRPC::grpc++ SHARED IMPORTED)
  25. set_target_properties(gRPC::grpc++ PROPERTIES IMPORTED_LOCATION ${gRPC_CPP_LIBRARY} INTERFACE_LINK_LIBRARIES protobuf::libprotobuf)
  26. endif()
  27. unset(gRPC_FOUND)
  28. if(TARGET gRPC::grpc++ AND TARGET gRPC::grpc AND TARGET gRPC::grpc_cpp_plugin)
  29. # message(STATUS "Found gRPC")
  30. set(gRPC_FOUND TRUE)
  31. else()
  32. unset(gRPC_LIBRARY)
  33. unset(gRPC_CPP_PLUGIN_EXECUTABLE)
  34. unset(gRPC_CPP_LIBRARY)
  35. endif()
  36. endif()