FindWrapgRPC.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. cmake_minimum_required(VERSION 3.10)
  2. function(_add_grpc_target_alias target)
  3. if(NOT TARGET ${target})
  4. message(FATAL_ERROR "${target} is not a target")
  5. endif()
  6. get_target_property(_aliased ${target} ALIASED_TARGET)
  7. if(_aliased)
  8. message(FATAL_ERROR "_add_grpc_target_alias only could be called with
  9. the non-aliased target")
  10. endif()
  11. get_target_property(_type ${target} TYPE)
  12. if(NOT TARGET gRPC::${target})
  13. if(_type STREQUAL "EXECUTABLE")
  14. add_executable(gRPC::${target} ALIAS ${target})
  15. else()
  16. add_library(gRPC::${target} ALIAS ${target})
  17. endif()
  18. endif()
  19. endfunction()
  20. find_package(gRPC CONFIG)
  21. if(TARGET grpc)
  22. _add_grpc_target_alias(grpc)
  23. endif()
  24. if(TARGET grpc++)
  25. _add_grpc_target_alias(grpc++)
  26. endif()
  27. if(TARGET grpc_cpp_plugin)
  28. _add_grpc_target_alias(grpc_cpp_plugin)
  29. endif()
  30. unset(WrapgRPC_FOUND)
  31. if(gRPC_FOUND AND TARGET gRPC::grpc AND TARGET gRPC::grpc++ AND TARGET gRPC::grpc_cpp_plugin)
  32. set(WrapgRPC_FOUND TRUE)
  33. elseif(EXISTS "${QT_PROTOBUF_SOURCE_DIR}/3rdparty/grpc/CMakeLists.txt")
  34. message(WARNING "Support for built-in gRPC will be discontinued soon. Please make sure that
  35. you have recent version of gRPC installed in your system.")
  36. set(gRPC_BUILD_TESTS FALSE CACHE INTERNAL "" FORCE)
  37. set(protobuf_BUILD_TESTS FALSE CACHE INTERNAL "" FORCE)
  38. add_subdirectory("${QT_PROTOBUF_SOURCE_DIR}/3rdparty/grpc" EXCLUDE_FROM_ALL)
  39. _add_grpc_target_alias(grpc)
  40. _add_grpc_target_alias(grpc++)
  41. _add_grpc_target_alias(grpc_cpp_plugin)
  42. set(WrapgRPC_FOUND TRUE)
  43. endif()