Faruk
Faruk

Reputation: 332

gRPC cmake aarch64 cross compile test for QNX SDP 7.0

I try cross-compile gRPC C++ for QNX SDP 7.0. I downloaded gRPC repo v1.52.2.

Firstly I ran source ~/qnx700/qnxsdp-env.sh and I ran run_distrib_test_cmake_aarch64_cross.sh for test my compile environment.

I added some new lines for see whether if set QNX_TARGET and QNX_HOST. Because it seems like $ENV{QNX_HOST} and $ENV{QNX_TARGET} didn't work. run_distrib_test_cmake_aarch64_cross.sh file here:

#!/bin/bash
# Copyright 2017 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

cd "$(dirname "$0")/../../.."

# Install openssl (to use instead of boringssl)
apt-get update && apt-get install -y libssl-dev

# Install CMake 3.16
apt-get update && apt-get install -y wget
wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.1/cmake-3.16.1-Linux-x86_64.sh
sh cmake-linux.sh -- --skip-license --prefix=/usr
rm cmake-linux.sh

# Use externally provided env to determine build parallelism, otherwise use default.
GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS=${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS:-4}

# Build and install gRPC for the host architecture.
# We do this because we need to be able to run protoc and grpc_cpp_plugin
# while cross-compiling.
mkdir -p "cmake/build"
pushd "cmake/build"
cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DgRPC_INSTALL=ON \
  -DgRPC_BUILD_TESTS=OFF \
  -DgRPC_SSL_PROVIDER=package \
  ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd

# Write a toolchain file to use for cross-compiling.
#cat > /tmp/toolchain.cmake <<'EOT'
#SET(CMAKE_SYSTEM_NAME QNX)
#SET(CMAKE_SYSTEM_PROCESSOR aarch64)
#set(CMAKE_STAGING_PREFIX /tmp/stage)
#set(CMAKE_C_COMPILER /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc)
#set(CMAKE_CXX_COMPILER /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc)
#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)
#EOT

cat > /tmp/toolchain.cmake <<'EOT'
include(CMakeForceCompiler)

set(CMAKE_SYSTEM_NAME QNX)

set(CMAKE_C_COMPILER "/home/arge/qnx700/host/linux/x86_64/usr/bin/qcc")
set(CMAKE_CXX_COMPILER "/home/arge/qnx700/host/linux/x86_64/usr/bin/QCC")

message(STATUS "TEST CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "TEST CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")

set(QNX_TARGET "/home/arge/qnx700/target/qnx7")
set(QNX_HOST "/home/arge/qnx700/host/linux/x86_64")

# Setting QNX compiler flags
#set(QNX_FLAGS "-Vgcc_ntoarmv7le")
set(QNX_FLAGS "-Vgcc_ntoaarch64le")
set(QNX_FLAGS "${QNX_FLAGS} -lang-c++")
set(QNX_FLAGS "${QNX_FLAGS} -Werror")
set(QNX_FLAGS "${QNX_FLAGS} -Wc,-fPIC")
set(QNX_FLAGS "${QNX_FLAGS} -Wc,-finline-functions")
set(QNX_FLAGS "${QNX_FLAGS} -lm")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(QNX_FLAGS "${QNX_FLAGS} -O0 -g")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
  set(QNX_FLAGS "${QNX_FLAGS} -O2")
endif()

# As cmake C/CXX flags are set in this toolchain file (passed to cmake
# using -DCMAKE_TOOLCHAIN_FILE these cmake variables have to be cached.
set(CMAKE_C_FLAGS "${QNX_FLAGS}" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${QNX_FLAGS}" CACHE STRING "")

# Detect the target architecture by checking the compiler flags
set(TARGET_ARCH "x86")
if(${CMAKE_CXX_FLAGS} MATCHES "ntoarmv7le")
  set(TARGET_ARCH "armle-v7")
endif()

if(${CMAKE_CXX_FLAGS} MATCHES "ntoaarch64le")
  set(TARGET_ARCH "aarch64le")
endif()

# Set the target directories
set(CMAKE_FIND_ROOT_PATH "${QNX_TARGET}/${TARGET_ARCH}")
message(STATUS "CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}")

message(STATUS "TEST QNX_TARGET ${QNX_TARGET}")
message(STATUS "TEST QNX_HOST ${QNX_HOST}")

# Search for programs in the build host directories.
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

add_definitions(-DQNX=1)
EOT

# Build and install gRPC for ARM.
# This build will use the host architecture copies of protoc and
# grpc_cpp_plugin that we built earlier because we installed them
# to a location in our PATH (/usr/local/bin).
mkdir -p "cmake/build_arm"
pushd "cmake/build_arm"
cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=/tmp/install \
      ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}" install
popd

# Build helloworld example for ARM.
# As above, it will find and use protoc and grpc_cpp_plugin
# for the host architecture.
mkdir -p "examples/cpp/helloworld/cmake/build_arm"
pushd "examples/cpp/helloworld/cmake/build_arm"
cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -Dabsl_DIR=/tmp/stage/lib/cmake/absl \
      -DProtobuf_DIR=/tmp/stage/lib/cmake/protobuf \
      -DgRPC_DIR=/tmp/stage/lib/cmake/grpc \
      ../..
make "-j${GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS}"
popd

output is:


.
.
.
-- Up-to-date: /usr/local/lib/libz.so
-- Up-to-date: /usr/local/lib/libz.a
-- Installing: /usr/local/include/zconf.h
-- Up-to-date: /usr/local/include/zlib.h
-- Up-to-date: /usr/local/share/man/man3/zlib.3
-- Installing: /usr/local/share/pkgconfig/zlib.pc
+ popd
/home/arge/dev/grpc
+ cat
+ mkdir -p cmake/build_arm
+ pushd cmake/build_arm
/home/arge/dev/grpc/cmake/build_arm /home/arge/dev/grpc
+ cmake -DCMAKE_TOOLCHAIN_FILE=/tmp/toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install ../..
-- TEST CMAKE_C_COMPILER: /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc
-- TEST CMAKE_CXX_COMPILER: /home/arge/qnx700/host/linux/x86_64/usr/bin/QCC
-- CMAKE_FIND_ROOT_PATH: /home/arge/qnx700/target/qnx7/aarch64le
-- TEST QNX_TARGET /home/arge/qnx700/target/qnx7
-- TEST QNX_HOST /home/arge/qnx700/host/linux/x86_64
-- TEST CMAKE_C_COMPILER: /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc
-- TEST CMAKE_CXX_COMPILER: /home/arge/qnx700/host/linux/x86_64/usr/bin/QCC
-- CMAKE_FIND_ROOT_PATH: /home/arge/qnx700/target/qnx7/aarch64le
-- TEST QNX_TARGET /home/arge/qnx700/target/qnx7
-- TEST QNX_HOST /home/arge/qnx700/host/linux/x86_64
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc
-- Check for working C compiler: /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/home/arge/qnx700/host/linux/x86_64/usr/bin/qcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_825e2/fast && /usr/bin/make -f CMakeFiles/cmTC_825e2.dir/build.make CMakeFiles/cmTC_825e2.dir/build
    make[1]: Entering directory '/home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_825e2.dir/testCCompiler.c.o
    /home/arge/qnx700/host/linux/x86_64/usr/bin/qcc -DQNX=1  -Vgcc_ntoaarch64le -lang-c++ -Werror -Wc,-fPIC -Wc,-finline-functions -lm -O2    -o CMakeFiles/cmTC_825e2.dir/testCCompiler.c.o   -c /home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeTmp/testCCompiler.c
    cc: The QNX_HOST/QNX_TARGET environment variables must be set
    make[1]: *** [CMakeFiles/cmTC_825e2.dir/build.make:66: CMakeFiles/cmTC_825e2.dir/testCCompiler.c.o] Error 1
    make[1]: Leaving directory '/home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_825e2/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:38 (project)


-- Configuring incomplete, errors occurred!
See also "/home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeOutput.log".
See also "/home/arge/dev/grpc/cmake/build_arm/CMakeFiles/CMakeError.log".

I am stuck here. I couldn't understand clearly problem in here. What is the wrong? Could you please help about for this issue?

Upvotes: 0

Views: 112

Answers (0)

Related Questions