Q: How to cross-compile the example for, e.g. ARM target?
jmccabe opened this issue · 0 comments
Hi,
I hope you don't mind me asking this as an issue.
Your example's been useful, and I've built the example for native (Ubuntu), but the next thing I'd like to do is be able to cross-compile to an ARM target. I've already got gRPC and the associated protobuf stuff built for ARM, as well as native, so I've got a toolchain file as follows:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_ROOT}/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_ROOT}/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH $ENV{TOOLCHAIN_ROOT}/../arm-linux-gnueabihf)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(THREADS_PTHREAD_ARG 2)
I've got some locally built libraries in use for OpenSSL, zlib, and so on, but I've got to the point where I can get cmake to run successfully through using a command like:
cmake \
-DCMAKE_TOOLCHAIN_FILE=Toolchain.cmake \
-DOPENSSL_ROOT_DIR=${LIBRARY_ROOT}/OpenSSL/Cross/install \
-DOPENSSL_INCLUDE_DIR=${LIBRARY_ROOT}/OpenSSL/Cross/install/include \
-DOPENSSL_CRYPTO_LIBRARY=${LIBRARY_ROOT}/OpenSSL/Cross/install/lib/libcrypto.so \
-DOPENSSL_SSL_LIBRARY=${LIBRARY_ROOT}/OpenSSL/Cross/install/lib/libssl.so \
-DZLIB_INCLUDE_DIR=${TARGET_SYS_ROOT}/usr/include \
-DZLIB_LIBRARY=${TARGET_SYS_ROOT}/usr/lib \
-Dprotobuf_DIR=${LIBRARY_ROOT}/gRPC/Cross/install/lib/cmake/protobuf \
-DgRPC_DIR=${LIBRARY_ROOT}/gRPC/Cross/install/lib/cmake/grpc \
-Dabsl_DIR=${LIBRARY_ROOT}/gRPC/Cross/install/lib/cmake/absl \
..
where the environment variables are set appropriately!
The next step, make
, however, fails as it tries to execute the target version of protoc
. As you can probably tell, I'm just beginning with cmake and protobug/grpc but, obviously, the problem I've got is how to make the cmake generation use the native version of protoc
for generating the C++ files from the proto
files, but use the target ARM libraries for the build and link.
I've spent most of the day searching for the solution but am finding myself substantially confused now! The most promising comments I've seen have been related to the use of the Protobuf_PROTOC_EXECUTABLE
setting to cmake but, when I try to use that, I just get:
CMake Warning:
Manually-specified variables were not used by the project:
Protobuf_PROTOC_EXECUTABLE
If you, or anyone, can make any suggestions on where to look next, it would be massively appreciated.