diff options
author | Frank Lange <langefrq@gmx.de> | 2021-04-30 20:56:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-06 17:42:21 (GMT) |
commit | f2a4b879b1cddce84c56de63809e831aea53d1ba (patch) | |
tree | 6ecff61d0f3059b2a27be53dc619d3bfe727f5b3 /Tests/FindProtobuf | |
parent | 5cbbe3d301838b361f7ff9ae7e09dc10ce089957 (diff) | |
download | CMake-f2a4b879b1cddce84c56de63809e831aea53d1ba.zip CMake-f2a4b879b1cddce84c56de63809e831aea53d1ba.tar.gz CMake-f2a4b879b1cddce84c56de63809e831aea53d1ba.tar.bz2 |
FindProtobuf: Add PLUGIN parameter to protobuf_generate
This allows for example reusing the function for generating gRPC code by
specifying which grpc plugin to use.
Diffstat (limited to 'Tests/FindProtobuf')
-rw-r--r-- | Tests/FindProtobuf/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FindProtobuf/Test/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/FindProtobuf/Test/main-generate-grpc.cxx | 6 | ||||
-rw-r--r-- | Tests/FindProtobuf/Test/msgs/example_service.proto | 8 |
4 files changed, 28 insertions, 0 deletions
diff --git a/Tests/FindProtobuf/CMakeLists.txt b/Tests/FindProtobuf/CMakeLists.txt index 1cdb2ae..b4ca29b 100644 --- a/Tests/FindProtobuf/CMakeLists.txt +++ b/Tests/FindProtobuf/CMakeLists.txt @@ -6,5 +6,6 @@ add_test(NAME FindProtobuf.Test COMMAND ${build_generator_args} --build-project TestFindProtobuf --build-options ${build_options} + "-DCMake_TEST_FindProtobuf_gRPC=${CMake_TEST_FindProtobuf_gRPC}" --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) diff --git a/Tests/FindProtobuf/Test/CMakeLists.txt b/Tests/FindProtobuf/Test/CMakeLists.txt index fc6b37e..84041ea 100644 --- a/Tests/FindProtobuf/Test/CMakeLists.txt +++ b/Tests/FindProtobuf/Test/CMakeLists.txt @@ -52,3 +52,16 @@ target_include_directories(test_desc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(test_desc msgs ${Protobuf_LIBRARIES}) target_compile_features(test_desc PRIVATE cxx_std_11) add_test(NAME test_desc COMMAND test_desc ${DESC_PROTO_DESC}) + +if(CMake_TEST_FindProtobuf_gRPC) + find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin) + add_library(msgs_grpc msgs/example_service.proto) + target_include_directories(msgs_grpc PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(msgs_grpc PUBLIC ${Protobuf_LIBRARIES}) + protobuf_generate(TARGET msgs_grpc LANGUAGE cpp) + protobuf_generate(TARGET msgs_grpc LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${gRPC_CPP_PLUGIN}") + + add_executable(test_generate_grpc main-generate-grpc.cxx) + target_link_libraries(test_generate_grpc PRIVATE msgs_grpc) + add_test(NAME test_generate_grpc COMMAND test_generate_grpc) +endif() diff --git a/Tests/FindProtobuf/Test/main-generate-grpc.cxx b/Tests/FindProtobuf/Test/main-generate-grpc.cxx new file mode 100644 index 0000000..070c6b4 --- /dev/null +++ b/Tests/FindProtobuf/Test/main-generate-grpc.cxx @@ -0,0 +1,6 @@ +#include <msgs/example_service.grpc.pb.h> + +int main() +{ + return 0; +} diff --git a/Tests/FindProtobuf/Test/msgs/example_service.proto b/Tests/FindProtobuf/Test/msgs/example_service.proto new file mode 100644 index 0000000..f35eeb5 --- /dev/null +++ b/Tests/FindProtobuf/Test/msgs/example_service.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package example.msgs; + +import "google/protobuf/empty.proto"; + +service ExampleService { + rpc nothing(google.protobuf.Empty) returns (google.protobuf.Empty) {} +} |