diff --git a/recipes/grpc/all/test_package/CMakeLists.txt b/recipes/grpc/all/test_package/CMakeLists.txt index 3f362bb23d2c58..68a33e841d74a8 100644 --- a/recipes/grpc/all/test_package/CMakeLists.txt +++ b/recipes/grpc/all/test_package/CMakeLists.txt @@ -13,37 +13,26 @@ message(STATUS "Using protobuf ${protobuf_VERSION}") find_package(gRPC CONFIG REQUIRED) message(STATUS "Using gRPC ${gRPC_VERSION}") -# Proto file -get_filename_component(hw_proto "helloworld.proto" ABSOLUTE) -get_filename_component(hw_proto_path "${hw_proto}" PATH) - -# Generated sources -set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc") -set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h") -set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc") -set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h") -add_custom_command( - OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" - COMMAND $ - ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" - -I "${hw_proto_path}" - --plugin=protoc-gen-grpc="$" - "${hw_proto}" - DEPENDS "${hw_proto}" -) - -# Build generated sources as an object library -add_library(hw_proto_obj OBJECT ${hw_proto_srcs} ${hw_grpc_srcs}) -target_include_directories(hw_proto_obj PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(hw_proto_obj PRIVATE gRPC::grpc protobuf::libprotobuf) -target_compile_features(hw_proto_obj PUBLIC cxx_std_11) - # Targets greeter_[async_](client) -add_executable(greeter_client_server greeter_client_server.cc) -target_link_libraries(greeter_client_server PRIVATE hw_proto_obj) +add_executable(${PROJECT_NAME} test_package.cpp helloworld.proto) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf) if(NOT SECURE) - target_link_libraries(greeter_client_server PRIVATE gRPC::grpc++_unsecure) + target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::grpc++_unsecure) else() - target_link_libraries(greeter_client_server PRIVATE gRPC::grpc++) + target_link_libraries(${PROJECT_NAME} PRIVATE gRPC::grpc++) endif() + +protobuf_generate(TARGET ${PROJECT_NAME} LANGUAGE cpp) +protobuf_generate( + TARGET + ${PROJECT_NAME} + LANGUAGE + grpc + GENERATE_EXTENSIONS + .grpc.pb.h + .grpc.pb.cc + PLUGIN + protoc-gen-grpc=$ +) diff --git a/recipes/grpc/all/test_package/conanfile.py b/recipes/grpc/all/test_package/conanfile.py index 5a99ddf1668b79..aafb9bf0e99bbf 100644 --- a/recipes/grpc/all/test_package/conanfile.py +++ b/recipes/grpc/all/test_package/conanfile.py @@ -7,8 +7,8 @@ class TestPackageConan(ConanFile): generators = "cmake", "cmake_find_package_multi" def build_requirements(self): - if hasattr(self, "settings_build") and tools.cross_building(self): - self.build_requires(str(self.requires['grpc'])) + if hasattr(self, "settings_build"): + self.build_requires(str(self.requires["grpc"])) def build(self): cmake = CMake(self) @@ -18,5 +18,5 @@ def build(self): def test(self): if not tools.cross_building(self): - bin_path = os.path.join("bin", "greeter_client_server") + bin_path = os.path.join("bin", "test_package") self.run(bin_path, run_environment=True) diff --git a/recipes/grpc/all/test_package/greeter_client_server.cc b/recipes/grpc/all/test_package/test_package.cpp similarity index 100% rename from recipes/grpc/all/test_package/greeter_client_server.cc rename to recipes/grpc/all/test_package/test_package.cpp