logo

Cross compile Domoticz

updated Mon April 27th 2020
origin Sat March 28th 2020

update for 2020.2: the 2020.2 version required some extra libraries, I could no longer drop Python and compiling libmosquitto faild. Workarounds added in the text.

A new version of domoticz turned up, the 2020.1 However since I’m running voidlinux on my home automation RPI2 I had to find a way to compile since voidlinux uses libressl instead of openssl

A rpi2 did not give much change of compiling domoticz and since I have a capable desktop machine I wanted to compile there. But without messing up this machine .. Took some effort but there it is, a very simple walk through. This should work similar - although with different commands and packages - on any distro. But that’s up to you.

So

  • cross compile domoticz
  • from x86_64 to armv7l
  • in a chroot

Steps

# as root
mkdir chroot
xbps-install -S -R http://alpha.de.repo.voidlinux.org/current -r chroot base-chroot

# set resolver
cp /etc/resolv.conf chroot/etc/
# chroot into chroot
chroot chroot 
cd

# install cross compiler and tools
xbps-install -Su cross-armv7l-linux-gnueabihf git cmake

# install additional required libraries in target arch
# 2020.1
XBPS_ARCH=armv7l xbps-install -S -R http://alpha.de.repo.voidlinux.org/current -r /usr/armv7l-linux-gnueabihf libressl-devel libcurl-devel libusb-devel libusb-compat python3-devel zlib-devel boost-devel

# update for 2020.2 I added lua-devel and cereal, had to add python-devel because it failed otherwise and had to add libmosquitto-devel because compiling failed. So command as above for 2020.2:
XBPS_ARCH=armv7l xbps-install -S -R http://alpha.de.repo.voidlinux.org/current -r /usr/armv7l-linux-gnueabihf libressl-devel libcurl-devel libusb-devel libusb-compat python3-devel zlib-devel boost-devel lua-devel cereal python-devel libmosquitto-devel

# add toolchain cmake config
cat <<EOF > Toolchain-armv7l.cmake
# target arch
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR armv7l)

# target tools
SET(CMAKE_C_COMPILER /usr/bin/armv7l-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/armv7l-linux-gnueabihf-g++)

# Where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /usr/armv7l-linux-gnueabihf)

# Search for programs in the build host directories
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)
EOF

# build domoticz
git clone https://github.com/domoticz/domoticz.git dev-domoticz
cd dev-domoticz

# 2020.1
cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-armv7l.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHON="NO" -DUSE_OPENSSL_STATIC="NO" CMakeLists.txt

# update for 2020.2 skip USE_PYTHON (and USE_OPENSSL_STATIC because NO is the default)
cmake -DCMAKE_TOOLCHAIN_FILE=../Toolchain-armv7l.cmake -DCMAKE_BUILD_TYPE=Release -DUSE_BUILTIN_MQTT=NO CMakeLists.txt

# should end without errors

# make with cores+1
make -j13 

# strip binary
/usr/armv7l-linux-gnueabihf/bin/strip domoticz

# verify
file domoticz
# should show: domoticz: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=dd83fc347de29cee1d400408bc6cc3fa565916d8, for GNU/Linux 3.2.0, stripped

# finally copy domoticz file to your remote pc replace domoticz file in your domoticz application directory
# and for 2020.2 add  libmosquitto to your rpi
xbps-install libmosquitto

exit

# easy cleanup
rm -rf chroot

Done, updated domoticz with just minutes compile time ;-)