Allow Cross-Compile with latest Ubuntu and Raspbian versions

This commit is contained in:
LordGrey 2019-06-10 15:19:08 +02:00
parent 4aab0ad55c
commit ba3762e865
8 changed files with 147 additions and 77 deletions

View File

@ -255,6 +255,24 @@ if (UNIX AND NOT APPLE)
endif ()
# add QT5 dependency
IF ( CMAKE_CROSSCOMPILING )
file(GLOB QT_BIN ${QT_BIN_PATH})
set(QT_MOC_EXECUTABLE ${QT_BIN}/moc)
add_executable(Qt5::moc IMPORTED)
set_property(TARGET Qt5::moc PROPERTY IMPORTED_LOCATION ${QT_MOC_EXECUTABLE})
set(QT_RCC_EXECUTABLE ${QT_BIN}/rcc)
add_executable(Qt5::rcc IMPORTED)
set_property(TARGET Qt5::rcc PROPERTY IMPORTED_LOCATION ${QT_RCC_EXECUTABLE})
message(STATUS "QT_BIN_PATH = ${QT_BIN}")
message(STATUS "QT_MOC_EXECUTABLE = ${QT_MOC_EXECUTABLE}")
message(STATUS "QT_RCC_EXECUTABLE = ${QT_RCC_EXECUTABLE}")
ENDIF()
SET(QT_MIN_VERSION "5.5.0")
find_package(Qt5 COMPONENTS Core Gui Network SerialPort REQUIRED)
message( STATUS "Found Qt Version: ${Qt5Core_VERSION}" )
@ -268,11 +286,6 @@ find_package(libusb-1.0 REQUIRED)
find_package(Threads REQUIRED)
add_definitions(${QT_DEFINITIONS})
# TODO[TvdZ]: This linking directory should only be added if we are cross compiling
#if(NOT APPLE)
# link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
#endif()
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreGraphics")
endif()

View File

@ -1,38 +1,38 @@
#!/bin/bash
#Updated: 18 August 2016, by brindosch
#Just use a clean Ubunut 14.04 and run this script
#Updated: 5 Mai 2019, by Lordgrey
#Just use a clean Raspbian Stretch Lite and Ubunut 18/19 and run this script
##############
#ON TARGET
#--------------
#sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev python-dev rsync
sudo apt-get install qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev aptitude show qt5-default rsync
#############
#ON HOST
#---------
sudo apt-get update
sudo apt-get upgrade
#TO-DO verify what is really required
#blacklist: lib32z1 lib32ncurses5 lib32bz2-1.0 zlib1g-dev
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev
# !!! TO-DO verify aptitude gcc-multilib
echo 'PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin' >> .bashrc
sudo apt-get -qq -y install git rsync cmake build-essential qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python3-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev
#---------
export TARGET_IP=192.168.0.103
export TARGET_IP=x.x.x.x
export TARGET_USER=pi
export RASCROSS_DIR="$HOME/raspberrypi"
export CROSSROOT="$HOME/crosscompile"
export RASCROSS_DIR="$CROSSROOT/raspberrypi"
export ROOTFS_DIR="$RASCROSS_DIR/rootfs"
export HYPERION_DIR="$HOME/hyperion"
#export IMX6_DIR="$HOME/hummingboard"
export TOOLCHAIN_FILE="$HYPERION_DIR/Toolchain-RaspberryPi.cmake"
export TOOLCHAIN_DIR="$RASCROSS_DIR/tools"
export QT5_DIR="$CROSSROOT/Qt5"
export NATIVE_BUILD_DIR="$HYPERION_DIR/build"
export TARGET_BUILD_DIR="$HYPERION_DIR/build-rpi"
export HYPERION_DIR="$HOME/hyperion.ng"
mkdir -p "$ROOTFS_DIR"
rsync -rl --delete-after --copy-unsafe-links $TARGET_USER@$TARGET_IP:/{lib,usr} "$ROOTFS_DIR"
mkdir -p "$ROOTFS_DIR/lib"
mkdir -p "$ROOTFS_DIR/usr"
rsync -rl --delete-after --copy-unsafe-links $TARGET_USER@$TARGET_IP:/lib "$ROOTFS_DIR"
rsync -rl --delete-after --copy-unsafe-links $TARGET_USER@$TARGET_IP:/usr/include "$ROOTFS_DIR/usr"
rsync -rl --delete-after --copy-unsafe-links $TARGET_USER@$TARGET_IP:/usr/lib "$ROOTFS_DIR/usr"
######## RPi specific #########
@ -40,41 +40,40 @@ mkdir -p "$RASCROSS_DIR/firmware"
git clone --depth 1 https://github.com/raspberrypi/firmware.git "$RASCROSS_DIR/firmware"
ln -s "$RASCROSS_DIR/firmware/hardfp/opt" "$ROOTFS_DIR/opt"
git clone --depth 1 git://github.com/raspberrypi/tools.git "$RASCROSS_DIR/tools"
cd $TOOLCHAIN_DIR
wget -c hhttps://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz --no-check-certificate
tar -xvzf gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
##### End of RPi specific ######
######## NOT TESTED ONLY INFOs #########
######## IMX6 specific #########
#export IMX6_DIR="$HOME/hummingboard"
#mkdir -p "$IMX6_Dir"
#cd "$IMX6_Dir"
#wget https://launchpad.net/linaro-toolchain-binaries/trunk/2013.10/+download/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux.tar.bz2
#tar -xvjf gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux.tar.bz2
#cd
##### End of IMX6 specific ######
######## NOT TESTED #########
######## Qt5 specific #########
mkdir -p "$QT5_DIR"
cd "$QT5_DIR"
wget -c http://download.qt.io/archive/qt/5.7/5.7.1/qt-opensource-linux-x64-5.7.1.run
chmod +x "$QT5_DIR/*.run"
qt-opensource-linux-x64-5.7.1.run
#Display absolute installation directory
echo $HOME/crosscompile/Qt5
./qt-opensource-linux-x64-5.7.1.run
#Follow the dialogs and install in absolute directory of $HOME/crosscompile/Qt5 (copy from above)
##### End of Qt5 specific ######
# get the Hyperion sources
git clone --recursive https://github.com/hyperion-project/hyperion.ng.git "$HYPERION_DIR"
# do a native build (to build the flatbuffers compiler for the native platform)
mkdir -p "$NATIVE_BUILD_DIR"
cmake -DENABLE_DISPMANX=OFF --build "$NATIVE_BUILD_DIR" "$HYPERION_DIR"
# do the cross build
# specify the protoc export file to import the flatbuffers compiler from the native build
mkdir -p "$TARGET_BUILD_DIR"
cmake -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DIMPORT_PROTOC=$NATIVE_BUILD_DIR/protoc_export.cmake --build "$TARGET_BUILD_DIR" "$HYPERION_DIR"
# get requried submodules
cd "$HYPERION_DIR"
git fetch --recurse-submodules -j2
#compile
cd "$HYPERION_DIR/bin"
chmod +x *
cp "$HYPERION_DIR/bin/create_all_releases.sh" "$HYPERION_DIR"
cd "$HYPERION_DIR"
./create_all_releases.sh
chmod +x "$HYPERION_DIR/bin/"*.sh
./bin/create_all_releases.sh
######END
#------------------------------------------------------------------------------
#These instructions are based on tvdzwan and on the guide given by:
#http://airwiki.ws.dei.polimi.it/index.php/Cross-compiling_for_the_RaspberryPi

18
bin/create_all_releases.sh Normal file → Executable file
View File

@ -10,25 +10,31 @@ make_release()
PLATFORM=$2
shift 2
rm -r build-${RELEASE}
mkdir -p build-${RELEASE}
rm -r deploy/${RELEASE}
mkdir -p deploy/${RELEASE}
cd build-${RELEASE}
cmake -DCMAKE_INSTALL_PREFIX=/usr -DPLATFORM=${PLATFORM} $@ -DCMAKE_BUILD_TYPE=Release -Wno-dev .. || exit 1
make -j $(nproc) || exit 1
#strip bin/*
make package -j $(nproc)
mv hyperion-*-ambilight.* ../deploy/${RELEASE}
mv Hyperion-*.* ../deploy/${RELEASE}
cd ..
bin/create_release.sh . ${RELEASE}
}
export PATH="$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin"
CMAKE_PROTOC_FLAG="-DIMPORT_PROTOC=../build-x86x64/protoc_export.cmake"
CMAKE_FLATC_FLAG="-DIMPORT_FLATC=../build-x86x64/flatc_export.cmake"
export CFLAGS=-m32
export CXXFLAGS=-m32
make_release x86x64 x86
#make_release x32 x86 ${CMAKE_PROTOC_FLAG}
make_release rpi rpi -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-rpi.cmake" ${CMAKE_PROTOC_FLAG}
make_release wetek wetek -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-rpi.cmake" ${CMAKE_PROTOC_FLAG}
#make_release imx6 imx6 -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-imx6.cmake" ${CMAKE_PROTOC_FLAG}
#make_release x32 x86 -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-x32.cmake" ${CMAKE_PROTOC_FLAG} ${CMAKE_FLATC_FLAG}
make_release rpi rpi -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-rpi.cmake" ${CMAKE_PROTOC_FLAG} ${CMAKE_FLATC_FLAG}
#make_release wetek wetek -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-rpi.cmake" ${CMAKE_PROTOC_FLAG} ${CMAKE_FLATC_FLAG}
#make_release imx6 imx6 -DCMAKE_TOOLCHAIN_FILE="../cmake/Toolchain-imx6.cmake" ${CMAKE_PROTOC_FLAG} ${CMAKE_FLATC_FLAG}

8
bin/create_release.sh Normal file → Executable file
View File

@ -27,8 +27,8 @@ tar --create --gzip --absolute-names --show-transformed-names --ignore-failed-re
--transform "s:$repodir/bin/service/hyperion.initctl.sh:hyperion/services/hyperion.initctl.sh:" \
--transform "s://:/:g" \
"$builddir/bin/hyperion"* \
"$repodir/bin/service/hyperion.init.sh" \
"$repodir/bin/service/hyperion.systemd.sh" \
"$repodir/bin/service/hyperion.initctl.sh" \
"$repodir/config/hyperion.config.json.example"
"$repodir/bin/service/hyperion.init" \
"$repodir/bin/service/hyperion.systemd" \
"$repodir/bin/service/hyperion.initctl" \
"$repodir/config/hyperion.config.json.default"

View File

@ -1,16 +1,20 @@
SET(CUBIXCROSS_DIR $ENV{HOME}/hummingboard)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${CUBIXCROSS_DIR}/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${CUBIXCROSS_DIR}/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard")
SET(CROSSROOT $ENV{HOME}/crosscompile)
SET(DEVROOT ${CROSSROOT}/hummingboard)
SET(CUBIXROOT ${DEVROOT}/rootfs)
SET(CUBIXCROSS_DIR ${DEVROOT}/tools)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH ${CUBIXCROSS_DIR}/rootfs)
SET(TOOLROOT ${CUBIXCROSS_DIR}/gcc-linaro-arm-linux-gnueabihf-4.8-2013.10_linux/ )
# specify the cross compiler
SET(CMAKE_C_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-g++)
SET(CUBIX_FLAGS "-march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard")
SET(CMAKE_SYSROOT ${CUBIXROOT})
SET(CMAKE_FIND_ROOT_PATH ${CUBIXROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
@ -18,5 +22,17 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGES ONLY)
include_directories(${CMAKE_FIND_ROOT_PATH}/usr/include)
#SET Flags for linking as dynamic linker config file is not being properly parsed by the toolchain
# see https://solderspot.wordpress.com/2016/02/04/cross-compiling-for-raspberry-pi-part-ii/
SET(FLAGS "${CUBIX_FLAGS} -Wl,-rpath-link,${CUBIXROOT}/opt/vc/lib -Wl,-rpath-link,${CUBIXROOT}/lib/arm-linux-gnueabihf -Wl,-rpath-link,${CUBIXROOT}/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,${CUBIXROOT}/usr/local/lib")
UNSET(CMAKE_C_FLAGS CACHE)
UNSET(CMAKE_CXX_FLAGS CACHE)
SET(CMAKE_CXX_FLAGS ${FLAGS} CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS ${FLAGS} CACHE STRING "" FORCE)
link_directories(${CUBIXROOT}/lib/arm-linux-gnueabihf)

View File

@ -1,14 +1,20 @@
SET(RASPCROSS_DIR $ENV{HOME}/raspberrypi)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${RASPCROSS_DIR}/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${RASPCROSS_DIR}/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++)
SET(CROSSROOT $ENV{HOME}/crosscompile)
SET(DEVROOT ${CROSSROOT}/raspberrypi)
SET(PIROOT ${DEVROOT}/rootfs)
SET(PITOOLCHAIN ${DEVROOT}/tools)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH ${RASPCROSS_DIR}/rootfs)
SET(TOOLROOT ${PITOOLCHAIN}/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf )
SET(QT_BIN_PATH ${CROSSROOT}/Qt5/Qt5.7.1/5.7/gcc_64/bin)
# specify the cross compiler
SET(CMAKE_C_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLROOT}/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_SYSROOT ${PIROOT})
SET(CMAKE_FIND_ROOT_PATH ${PIROOT})
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
@ -16,4 +22,19 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGES ONLY)
#SET Flags for linking as dynamic linker config file is not being properly parsed by the toolchain
# see https://solderspot.wordpress.com/2016/02/04/cross-compiling-for-raspberry-pi-part-ii/
SET(FLAGS "-Wl,-rpath-link,${PIROOT}/opt/vc/lib -Wl,-rpath-link,${PIROOT}/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/lib/arm-linux-gnueabihf -Wl,-rpath-link,${PIROOT}/usr/local/lib")
UNSET(CMAKE_C_FLAGS CACHE)
UNSET(CMAKE_CXX_FLAGS CACHE)
SET(CMAKE_CXX_FLAGS ${FLAGS} CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS ${FLAGS} CACHE STRING "" FORCE)
link_directories(${PIROOT}/lib/arm-linux-gnueabihf)

View File

@ -1,7 +1,13 @@
# toolchain file for building a 32bit version on a 64bit host
# use it like this:
# cmake -DCMAKE_TOOLCHAIN_FILE=Toolchain-x32.cmake <sourcedir>
# Add additional 32-bit libraries
# sudo apt-get install g++-multilib libc6-dev-i386
#TO-DO
# Install QT5 32bit
SET(CROSSROOT $ENV{HOME}/crosscompile)
SET(QT_BIN_PATH ${CROSSROOT}/x86_32-linux-gnu/qt5/bin)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
@ -10,3 +16,6 @@ set(CMAKE_SYSTEM_PROCESSOR "i686")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags")

View File

@ -41,8 +41,14 @@ else ()
set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIRS} PARENT_SCOPE)
# define the flatc executable at the parent scope
get_property(FLATBUFFERS_FLATC_EXECUTABLE TARGET flatc PROPERTY LOCATION)
#get_property(FLATBUFFERS_FLATC_EXECUTABLE TARGET flatc PROPERTY LOCATION)
#Workaround, set flatc comiplier directory hard, as cmake definitions of flatc do not cater for crosscompile correctly.
#Includ of flatc_export.cmake detects that flatc target is defined aand returns before using the definitions written by export
set ( FLATBUFFERS_FLATC_EXECUTABLE "${CMAKE_BINARY_DIR}/../build-x86x64/bin/flatc")
set(FLATBUFFERS_FLATC_EXECUTABLE ${FLATBUFFERS_FLATC_EXECUTABLE} PARENT_SCOPE)
endif()
message(STATUS "Using flatbuffers compiler: " ${FLATBUFFERS_FLATC_EXECUTABLE})