Skip to content

Commit

Permalink
fix cmake: find PROTOBUF_PROTOC
Browse files Browse the repository at this point in the history
Tests: протестировано CI

Pull Request resolved: #716
commit_hash:67d88609811ab3530fdab288b0a35221aa03bcc4
  • Loading branch information
rtkid-nik authored and Anton3 committed Oct 17, 2024
1 parent d45d624 commit 031973e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
21 changes: 14 additions & 7 deletions cmake/GrpcTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ function(_userver_prepare_grpc)
find_package(gRPC REQUIRED)
get_target_property(PROTO_GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION)
get_target_property(PROTO_GRPC_PYTHON_PLUGIN gRPC::grpc_python_plugin LOCATION)
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT ON)
else()
include("${CMAKE_CURRENT_LIST_DIR}/SetupGrpc.cmake")
endif()
Expand Down Expand Up @@ -101,7 +99,7 @@ _userver_prepare_grpc()

function(userver_generate_grpc_files)
set(options)
set(one_value_args CPP_FILES CPP_USRV_FILES GENERATED_INCLUDES SOURCE_PATH)
set(one_value_args CPP_FILES CPP_USRV_FILES GENERATED_INCLUDES SOURCE_PATH OUTPUT_PATH)
set(multi_value_args PROTOS INCLUDE_DIRECTORIES)
cmake_parse_arguments(GEN_RPC "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

Expand Down Expand Up @@ -132,11 +130,19 @@ function(userver_generate_grpc_files)
endforeach()
endif()

set(GENERATED_PROTO_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto)
if (NOT "${GEN_RPC_OUTPUT_PATH}" STREQUAL "")
if(NOT IS_ABSOLUTE "${GEN_RPC_OUTPUT_PATH}")
message(SEND_ERROR "OUTPUT_PATH='${GEN_RPC_OUTPUT_PATH}' is a relative path, which is unsupported.")
endif()
set(GENERATED_PROTO_DIR "${GEN_RPC_OUTPUT_PATH}")
else()
set(GENERATED_PROTO_DIR "${CMAKE_CURRENT_BINARY_DIR}/proto")
endif()

get_filename_component(GENERATED_PROTO_DIR "${GENERATED_PROTO_DIR}" REALPATH BASE_DIR "/")

if(NOT "${GEN_RPC_SOURCE_PATH}" STREQUAL "")
if(NOT IS_ABSOLUTE ${GEN_RPC_SOURCE_PATH})
if(NOT IS_ABSOLUTE "${GEN_RPC_SOURCE_PATH}")
message(SEND_ERROR "SOURCE_PATH='${GEN_RPC_SOURCE_PATH}' is a relative path, which is unsupported.")
endif()
set(root_path "${GEN_RPC_SOURCE_PATH}")
Expand Down Expand Up @@ -294,14 +300,15 @@ endfunction()

function(userver_add_grpc_library NAME)
set(options)
set(one_value_args SOURCE_PATH)
set(one_value_args SOURCE_PATH OUTPUT_PATH)
set(multi_value_args PROTOS INCLUDE_DIRECTORIES)
cmake_parse_arguments(RPC_LIB "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

userver_generate_grpc_files(
PROTOS ${RPC_LIB_PROTOS}
INCLUDE_DIRECTORIES ${RPC_LIB_INCLUDE_DIRECTORIES}
SOURCE_PATH ${RPC_LIB_SOURCE_PATH}
SOURCE_PATH "${RPC_LIB_SOURCE_PATH}"
OUTPUT_PATH "${RPC_LIB_OUTPUT_PATH}"
GENERATED_INCLUDES include_paths
CPP_FILES generated_sources
CPP_USRV_FILES generated_usrv_sources
Expand Down
6 changes: 0 additions & 6 deletions cmake/SetupGrpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ macro(try_find_cmake_grpc)
# Use the found CMake-enabled gRPC package
get_target_property(PROTO_GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION)
get_target_property(PROTO_GRPC_PYTHON_PLUGIN gRPC::grpc_python_plugin LOCATION)
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT ON)
endif()
endmacro()

Expand All @@ -42,8 +40,6 @@ macro(try_find_system_grpc)

find_program(PROTO_GRPC_CPP_PLUGIN grpc_cpp_plugin)
find_program(PROTO_GRPC_PYTHON_PLUGIN grpc_python_plugin)
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT ON)
endif()
endmacro()

Expand Down Expand Up @@ -97,8 +93,6 @@ CPMAddPackage(
set(gRPC_VERSION "${CPM_PACKAGE_gRPC_VERSION}")
set(PROTO_GRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>)
set(PROTO_GRPC_PYTHON_PLUGIN $<TARGET_FILE:grpc_python_plugin>)
set(PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT OFF)
write_package_stub(gRPC)
if (NOT TARGET "gRPC::grpc++")
add_library(gRPC::grpc++ ALIAS grpc++)
Expand Down
6 changes: 6 additions & 0 deletions cmake/SetupProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ endfunction()
if(USERVER_CONAN)
find_package(Protobuf REQUIRED)
_userver_set_protobuf_version_category()
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT ON)
return()
endif()

Expand All @@ -49,6 +51,8 @@ if(NOT USERVER_FORCE_DOWNLOAD_PROTOBUF)

if(Protobuf_FOUND)
_userver_set_protobuf_version_category()
set(PROTOBUF_PROTOC "${Protobuf_PROTOC_EXECUTABLE}")
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT ON)
return()
endif()
endif()
Expand Down Expand Up @@ -78,3 +82,5 @@ set_target_properties(libprotoc PROPERTIES
write_package_stub(Protobuf)
mark_targets_as_system("${Protobuf_SOURCE_DIR}")
_userver_set_protobuf_version_category()
set(PROTOBUF_PROTOC $<TARGET_FILE:protoc>)
set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT OFF)

0 comments on commit 031973e

Please sign in to comment.