Porting QT5.9.8 to the HiSilicon 3521 Platform

Downloading QT Source Code and Preparing Cross-Compilation Tools

Modifying QT’s mkspecs

For compiling QT on the HiSilicon 3521 platform, navigate to the qtbase/mkspecs subdirectory within the QT source root. Copy and rename the linux-arm-gnueabi-g++ directory to hisi3521-linux-gnueabi-g++, then modify its qmake.conf file as follows:

#
# qmake configuration for building with arm-linux-gnueabi-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM = linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-a

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = arm-hisiv500-linux-uclibcgnueabi-gcc
QMAKE_CXX               = arm-hisiv500-linux-uclibcgnueabi-g++
QMAKE_LINK              = arm-hisiv500-linux-uclibcgnueabi-g++
QMAKE_LINK_SHLIB        = arm-hisiv500-linux-uclibcgnueabi-g++
QMAKE_CFLAGS +=-DEGL_FBDEV -std=c++11
QMAKE_CXXFLAGS +=-DEGL_FBDEV -std=c++11

# modifications to linux.conf
QMAKE_AR                = arm-hisiv500-linux-uclibcgnueabi-ar cqs
QMAKE_OBJCOPY           = arm-hisiv500-linux-uclibcgnueabi-objcopy
QMAKE_NM                = arm-hisiv500-linux-uclibcgnueabi-nm -P
QMAKE_STRIP             = arm-hisiv500-linux-uclibcgnueabi-strip
load(qt_config)
  • For QT cross-compilation, modifying mkspecs according to your specific cross-compilation platform and toolchain is the first step. Later, when configuring QT, you will need to pass your platform type via xplatform.

Cross-Compilation Configuration Script

Create a build configuration script buildsetup.sh in the QT directory as follows:

#!/bin/sh

PWD=`pwd`

export QT_SRC_DIR=$PWD
export QT_INSTALL_DIR=$QT_SRC_DIR/Qt_5.9.8
export SYSROOT=/home/pavel/hisi-linux/x86-arm/arm-hisiv500-linux/target
export PATH=/home/pavel/hisi-linux/x86-arm/arm-hisiv500-linux/bin:$PATH
export CROSS_COMPILE=/home/pavel/hisi-linux/x86-arm/arm-hisiv500-linux
export CPLUS_INCLUDE_PATH=$PWD/qtbase/src/3rdparty/angle/include:$CPLUS_INCLUDE_PATH

QT_ENV_CFG=qtenv.sh

sed -i '/^export  QTDIR*/d' $QT_ENV_CFG
sed -i '1 a \export  QTDIR='$QT_RUN_DIR'' $QT_ENV_CFG

cpu_cores=`cat /proc/cpuinfo | grep "processor" | wc -l`
if [ ${cpu_cores} -le 8 ] ; then
    LICHEE_JLEVEL=${cpu_cores}
else
    LICHEE_JLEVEL=${cpu_cores}
fi

function cdqtroot
{
cd $QT_SRC_DIR
}

function qtmakeconfig
{
    mkdir -p $QT_INSTALL_DIR

    $QT_SRC_DIR/configure \
        -opensource \
        -confirm-license \
        -sysroot $SYSROOT \
        -extprefix $QT_INSTALL_DIR \
        -platform linux-g++-64 \
        -xplatform hisi3521-linux-gnueabi-g++ \
        -device-option CROSS_COMPILE=$CROSS_COMPILE \
        -R /usr/lib \
        -no-strip \
        -c++std c++11 \
        -shared \
        -nomake examples \
        -accessibility \
        -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci \
        -no-sql-odbc -no-sql-psql -no-sql-sqlite2  -no-sql-tds \
        -no-sql-sqlite -plugin-sql-sqlite \
        -no-qml-debug \
        -no-sse2 \
        -no-sse3 \
        -no-ssse3 \
        -no-sse4.1 \
        -no-sse4.2 \
        -no-avx \
        -no-avx2 \
        -no-mips_dsp \
        -no-mips_dspr2 \
        -qt-zlib \
        -no-journald \
        -qt-libpng \
        -qt-libjpeg \
        -qt-freetype \
        -qt-harfbuzz \
        -no-openssl \
        -no-opengl \
        -no-xcb-xlib \
        -no-glib \
        -no-pulseaudio \
        -gui \
        -widgets \
        -v \
        -optimized-qmake \
        -no-cups \
        -no-iconv \
        -evdev \
        -no-icu \
        -no-fontconfig \
        -no-strip \
        -pch \
        -dbus \
        -no-use-gold-linker \
        -no-directfb \
        -linuxfb \
        -no-kms \
        -no-system-proxies \
        -no-slog2 \
        -no-pps \
        -no-imf \
        -no-lgmon \
        -no-tslib
}

function qtmakeall
{
    make  -j${LICHEE_JLEVEL} -C $QT_SRC_DIR
}

function qtmakeinstall
{
    make  -j${LICHEE_JLEVEL} -C $QT_SRC_DIR install

    #cp fonts to Install directory
    cp -rf fonts $QT_INSTALL_DIR
    
    #Remove redundant files
    rm -rf $QT_INSTALL_DIR/bin
    rm -rf $QT_INSTALL_DIR/include
    rm -rf $QT_INSTALL_DIR/doc
    rm -rf $QT_INSTALL_DIR/mkspecs
    rm -rf $QT_INSTALL_DIR/lib/cmake
    rm -rf $QT_INSTALL_DIR/lib/pkgconfig
    rm -rf $QT_INSTALL_DIR/lib/*.a
    rm -rf $QT_INSTALL_DIR/lib/*.prl
    rm -rf $QT_INSTALL_DIR/lib/*.la
}

function qtmakecleanall
{
    cd $QT_SRC_DIR
    make distclean -j${LICHEE_JLEVEL}
    make -C $QT_SRC_DIR clean -j${LICHEE_JLEVEL}
    rm -rf $QT_INSTALL_DIR
}


echo "  "
echo "********************** useage ***************************"
echo "        please use:"
echo "        qtmakeconfig:         config qt env."
echo "        qtmakeall:            build qt"
echo "        qtmakeinstall:        install qt-lib and cp to target dir."
echo "        qtmakecleanall:       clean qt and rm all target."
echo "        QT_INSTALL_DIR:       " $QT_INSTALL_DIR
echo "        qtmakecleanall:       clean qt and rm all target."
echo "  "

The script above primarily performs four tasks:

  • Sets up necessary environment variables;
  • Encapsulates the QT cross-compilation configure process in qtmakeconfig;
  • Encapsulates the complete QT cross-compilation build process in qtmakeall;
  • Encapsulates the QT cross-compilation installation process in qtmakeinstall;

Cross-Compilation Process and Problem Resolution

With the help of the above build configuration script, QT cross-compilation becomes very straightforward:

source ./buildsetup.sh
qtmakeconfig
qtmakeall
qtmakeinstall
  • The libraries, plugins, and other directories generated after compilation are located in Qt_5.9.8 under the QT root directory. Copy these directories to /usr/local/Qt_5.9.8 on the target board and set the corresponding environment variables to use them.

1. Error ‘You cannot configure qt separately within a top-level build.’ occurred when compiling qmake

The full error message is as follows:

pavel@debian:~/qt-everywhere-opensource-src-5.9.8$ qtmakeconfig
+ cd qtbase
+ /home/pavel/qt-everywhere-opensource-src-5.9.8/qtbase/configure -top-level -opensource -confirm-license -sysroot /home/pavel/hisi-linux/x86-arm/arm-hisiv500-linux/target -extprefix /home/pavel/qt-everywhere-opensource-src-5.9.8/Qt_5.12.5 -platform linux-g++-64 -xplatform hisi-linux-gnueabi-g++ -device-option CROSS_COMPILE=/home/pavel/hisi-linux/x86-arm/arm-hisiv500-linux -R /usr/lib -no-strip -c++std c++11 -shared -nomake examples -accessibility -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc -no-sql-psql -no-sql-sqlite2 -no-sql-tds -no-sql-sqlite -plugin-sql-sqlite -no-qml-debug -no-sse2 -no-sse3 -no-ssse3 -no-sse4.1 -no-sse4.2 -no-avx -no-avx2 -no-mips_dsp -no-mips_dspr2 -qt-zlib -no-journald -qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz -no-openssl -no-opengl -no-xcb-xlib -no-glib -no-pulseaudio -gui -widgets -v -optimized-qmake -no-cups -no-iconv -evdev -no-icu -no-fontconfig -no-strip -pch -dbus -no-use-gold-linker -no-directfb -linuxfb -no-kms -no-system-proxies -no-slog2 -no-pps -no-imf -no-lgmon -no-tslib
Creating qmake...
make: 对“first”无需做任何事。
Project ERROR: You cannot configure qt separately within a top-level build.

Solution: