Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grpc] Use build_modules to find executable grpc_cpp_plugin #5404

Merged
merged 14 commits into from
May 5, 2021
18 changes: 18 additions & 0 deletions recipes/grpc/all/cmake/grpc_cpp_plugin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if(NOT TARGET gRPC::grpc_cpp_plugin)
if(CMAKE_CROSSCOMPILING)
find_program(GRPC_CPP_PLUGIN_PROGRAM
NAMES grpc_cpp_plugin
PATHS ENV
PATH NO_DEFAULT_PATH)
else()
find_program(GRPC_CPP_PLUGIN_PROGRAM
NAMES grpc_cpp_plugin
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../bin/"
NO_DEFAULT_PATH)
endif()

get_filename_component(GRPC_CPP_PLUGIN_PROGRAM "${GRPC_CPP_PLUGIN_PROGRAM}" ABSOLUTE)

add_executable(gRPC::grpc_cpp_plugin IMPORTED)
set_property(TARGET gRPC::grpc_cpp_plugin PROPERTY IMPORTED_LOCATION ${GRPC_CPP_PLUGIN_PROGRAM})
endif()
10 changes: 8 additions & 2 deletions recipes/grpc/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class grpcConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/grpc/grpc"
license = "Apache-2.0"
exports_sources = ["CMakeLists.txt"]
exports_sources = ["CMakeLists.txt", "cmake/*"]
generators = "cmake", "cmake_find_package", "cmake_find_package_multi"
short_paths = True

Expand Down Expand Up @@ -116,13 +116,15 @@ def build(self):
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))

self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*.cmake", dst="lib/cmake", src=os.path.join(self.source_folder, "cmake"))
jgsogo marked this conversation as resolved.
Show resolved Hide resolved

def package_info(self):
bindir = os.path.join(self.package_folder, "bin")
Expand Down Expand Up @@ -232,6 +234,10 @@ def package_info(self):

# Executables
# gRPC::grpc_cpp_plugin
if self.options.cpp_plugin:
module_target_rel_path = os.path.join("lib", "cmake", "grpc_cpp_plugin.cmake")
self.cpp_info.components["execs"].build_modules["cmake_find_package"] = [module_target_rel_path]
self.cpp_info.components["execs"].build_modules["cmake_find_package_multi"] = [module_target_rel_path]
Comment on lines +237 to +240
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did it pass the hooks? This folder is not in buiddirs.

# gRPC::grpc_csharp_plugin
# gRPC::grpc_node_plugin
# gRPC::grpc_objective_c_plugin
Expand Down
3 changes: 1 addition & 2 deletions recipes/grpc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ message(STATUS "Using protobuf ${protobuf_VERSION}")
# Find gRPC installation
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
# set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin ${CONAN_BIN_DIRS_GRPC} NO_DEFAULT_PATH)
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)

# Proto file
get_filename_component(hw_proto "helloworld.proto" ABSOLUTE)
Expand Down
5 changes: 0 additions & 5 deletions recipes/grpc/all/test_package/greeter_client_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
#include <thread>

#include <grpcpp/grpcpp.h>

#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif

using grpc::Channel;
using grpc::ClientContext;
Expand Down