Skip to content

Commit cfeb211

Browse files
committed
Fix: try find protobuf config and get userver_protobuf_import_dir from libprotobuf target, otherwise find default protobuf
1 parent 0e326fd commit cfeb211

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cmake/SetupProtobuf.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ if(NOT USERVER_FORCE_DOWNLOAD_PROTOBUF)
4141
if(USERVER_DOWNLOAD_PACKAGE_PROTOBUF)
4242
find_package(Protobuf QUIET)
4343
else()
44-
find_package(Protobuf)
44+
find_package(Protobuf CONFIG)
45+
if (NOT Protobuf_FOUND)
46+
find_package(Protobuf)
47+
endif()
4548
if(NOT Protobuf_FOUND)
4649
message(
4750
FATAL_ERROR

cmake/UserverGrpcTargets.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ function(_userver_prepare_grpc)
5252
elseif(protobuf_INCLUDE_DIRS)
5353
set_property(GLOBAL PROPERTY userver_protobuf_import_dir "${protobuf_INCLUDE_DIRS}")
5454
else()
55-
message(FATAL_ERROR "Invalid Protobuf package")
55+
# maybe we found protobuf config
56+
get_target_property(_incs protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
57+
if (_incs)
58+
set_property(GLOBAL PROPERTY userver_protobuf_import_dir "${_incs}")
59+
else()
60+
message(FATAL_ERROR "Invalid Protobuf package")
61+
endif()
5662
endif()
5763

5864
if(NOT Protobuf_VERSION)
@@ -61,7 +67,7 @@ function(_userver_prepare_grpc)
6167
if(NOT gRPC_VERSION)
6268
message(FATAL_ERROR "Invalid gRPC package")
6369
endif()
64-
if(NOT PROTOBUF_PROTOC)
70+
if(NOT PROTOBUF_PROTOC AND NOT TARGET protobuf::libprotoc)
6571
message(FATAL_ERROR "protoc not found")
6672
endif()
6773
if(NOT PROTO_GRPC_CPP_PLUGIN)

0 commit comments

Comments
 (0)