使用cmake交叉编译gRPC [英] Cross compiling gRPC using cmake

查看:704
本文介绍了使用cmake交叉编译gRPC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cmake交叉编译gRPC。



我实际上设法做到了。不幸的是,我的方法涉及修补CMakeLists.txt。



问题是,当我尝试编译gRPC时,它使用的是他刚刚编译的protobuffer。它无法在x86计算机上运行ARM编译的可执行文件。



我设法通过在gRPC的主CMakeLists.txt文件中手动指定protoc和grpc_cpp_plugin的路径来对其进行编译。它很脏,并且由于我想将gRPC作为子模块包含在内,因此我需要一种干净的方法来完成它。



有人可以使用cmake交叉编译gRPC吗?

解决方案

这种方法应该起作用:


  1. 针对目标(ARM)交叉编译Protobuf并安装它。



    确保可以在您拥有的工具链(ARM)中搜索交叉编译的Protobuf。
    例如


  2. 在主机上,安装相同版本的Protobuf 。不必是可搜索的(也就是说,用户本地安装就足够了。)。


  3. 具有以下参数的交叉编译gRPC(在CMake GUI或作为 cmake 可执行文件的 -D 选项):




    • gRPC_PROTOBUF_PROVIDER:包

    • gRPC_PROTOBUF_PACKAGE_TYPE:MODULE

    • Protobuf_PROTOC_EXECUTABLE:<主机的路径 protoc 可执行文件>




说明



将参数 gRPC_PROTOBUF_PROVIDER 设置为 package会告诉gRPC不要构建自己的Protobuf,而是使用已经安装的变体。此变量由 find_package(Protobuf)搜索。



设置参数 gRPC_PROTOBUF_PACKAGE_TYPE 到 MODULE告诉gRPC不要使用Protobuf安装提供的 Config文件来检测Protobuf内容(库和可执行文件)。配置文件包含无法在外部调整的硬编码路径。而是使用 FindProtobuf.cmake 脚本来查找Protobuf。 / p>

设置参数 Protobuf_PROTOC_EXECUTABLE 告诉 FindProtobuf.cmake 脚本不要搜索Protobuf可执行文件,但从参数中获取。


I'm trying to cross-compile a gRPC using cmake.

I actually managed to do it. Unfortunately my method involves tinkering inside CMakeLists.txt.

Problem was that, when I was trying to compile gRPC it was using protobuffer he just compiled. It cannot run ARM compiled executables on x86 machine.

I managed to compile it by specifying path to protoc and grpc_cpp_plugin manually in gRPCs main CMakeLists.txt. It is dirty and since I would like to include gRPC as submodule I need clean way to do it.

Has anyone managed to cross-compile gRPC using cmake?

解决方案

This way should work:

  1. Cross-compile Protobuf for target(ARM) and install it.

    Make sure that cross-compiled Protobuf can be searched in the toolchain(ARM) you have. E.g. it is installed into system-default prefix under sysroot.

  2. On host, install Protobuf of the same version. It needn't to be searchable (that is, user-local installation is sufficient).

  3. Cross-compile gRPC with following parameters (set in CMake GUI or as -D option for cmake executable):

    • gRPC_PROTOBUF_PROVIDER: package
    • gRPC_PROTOBUF_PACKAGE_TYPE: MODULE
    • Protobuf_PROTOC_EXECUTABLE: <path to your host protoc executable>

Explanations

Setting parameter gRPC_PROTOBUF_PROVIDER to "package" tells gRPC to not build its own Protobuf, but use already installed variant. This variant is searched by find_package(Protobuf).

Setting parameter gRPC_PROTOBUF_PACKAGE_TYPE to "MODULE" tells gRPC to not use "Config" file, provided by Protobuf installation, for detect Protobuf things (libraries and executable). Config file contains hardcoded paths which cannot be adjusted outside. Instead, FindProtobuf.cmake script is used for find Protobuf.

Setting parameter Protobuf_PROTOC_EXECUTABLE tells FindProtobuf.cmake script to not search Protobuf executable, but takes it from the parameter.

这篇关于使用cmake交叉编译gRPC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆