diff --git a/cmake/GrpcTargets.cmake b/cmake/GrpcTargets.cmake index 79a9adcf7504..aae36e682a0a 100644 --- a/cmake/GrpcTargets.cmake +++ b/cmake/GrpcTargets.cmake @@ -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() @@ -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}) @@ -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}") @@ -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 diff --git a/cmake/SetupGrpc.cmake b/cmake/SetupGrpc.cmake index 7a3110a1c316..da6ea6639471 100644 --- a/cmake/SetupGrpc.cmake +++ b/cmake/SetupGrpc.cmake @@ -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() @@ -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() @@ -97,8 +93,6 @@ CPMAddPackage( set(gRPC_VERSION "${CPM_PACKAGE_gRPC_VERSION}") set(PROTO_GRPC_CPP_PLUGIN $) set(PROTO_GRPC_PYTHON_PLUGIN $) -set(PROTOBUF_PROTOC $) -set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT OFF) write_package_stub(gRPC) if (NOT TARGET "gRPC::grpc++") add_library(gRPC::grpc++ ALIAS grpc++) diff --git a/cmake/SetupProtobuf.cmake b/cmake/SetupProtobuf.cmake index a1be81f774ac..7369e987289a 100644 --- a/cmake/SetupProtobuf.cmake +++ b/cmake/SetupProtobuf.cmake @@ -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() @@ -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() @@ -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 $) +set(GENERATE_PROTOS_AT_CONFIGURE_DEFAULT OFF)