From f8fe445623af2ca9ba421b3241c8d020d5f533ed Mon Sep 17 00:00:00 2001
From: Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
Date: Tue, 17 Sep 2019 12:32:54 +0200
Subject: [PATCH] fixes for multiarch: - install cmake 3.15.3. binaries from
 github (older version in buster has a bug!) - use CMAKE_OPTS flag for
 compiling fmt and spdlog - use the cmake TOOLCHAIN file and INSTALL_LIBDIR
 fitting to the architecture in build stage

---
 .gitlab-ci.yml                                  |  4 ++--
 .../docker/Dockerfile.dev-debian-multiarch      | 17 +++++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 35ea2d488..0c21162a8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -104,13 +104,13 @@ build:debian-multiarch:armhf:
   extends: build:base
   variables:
     DOCKER_IMAGE_DEV: villas/node-dev-debian-armhf
-    CMAKE_OPTS: -DCMAKE_MODULE_PATH=/usr/local/lib64/cmake -DCMAKE_PREFIX_PATH=/usr/local
+    CMAKE_OPTS: -DCMAKE_TOOLCHAIN_FILE=/debian-armhf.cmake -DCMAKE_INSTALL_LIBDIR=/usr/lib/arm-linux-gnueabihf
 
 build:debian-multiarch:arm64:
   extends: build:base
   variables:
     DOCKER_IMAGE_DEV: villas/node-dev-debian-arm64
-    CMAKE_OPTS: -DCMAKE_MODULE_PATH=/usr/local/lib64/cmake -DCMAKE_PREFIX_PATH=/usr/local
+    CMAKE_OPTS: -DCMAKE_TOOLCHAIN_FILE=/debian-arm64.cmake -DCMAKE_INSTALL_LIBDIR=/usr/lib/aarch64-linux-gnu
 
 build:docs:
   stage: build
diff --git a/packaging/docker/Dockerfile.dev-debian-multiarch b/packaging/docker/Dockerfile.dev-debian-multiarch
index 86aff02cd..a04855684 100644
--- a/packaging/docker/Dockerfile.dev-debian-multiarch
+++ b/packaging/docker/Dockerfile.dev-debian-multiarch
@@ -47,8 +47,8 @@ RUN dpkg --add-architecture ${ARCH}
 # Toolchain
 RUN apt-get update && apt-get install -y \
 	crossbuild-essential-${ARCH} \
-	pkg-config cmake make ninja-build \
-	texinfo git curl tar \
+	pkg-config make ninja-build \
+	texinfo git curl tar wget\
 	protobuf-compiler protobuf-c-compiler
 
 # Dependencies
@@ -71,6 +71,13 @@ RUN apt-get update && apt-get install -y \
 	libre-dev:${ARCH} \
 	libusb-1.0-0-dev:${ARCH}
 
+# Install cmake (version from buster has a bug)
+RUN cd /tmp && \
+    wget https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.sh && \
+    chmod +x cmake-3.15.3-Linux-x86_64.sh && \
+    ./cmake-3.15.3-Linux-x86_64.sh --skip-license --prefix=/usr && \
+    rm -rf /tmp/*
+
 ADD cmake/toolchains/debian-${ARCH}.cmake /
 
 ENV PKG_CONFIG_PATH=/usr/lib/${TRIPLET}/pkgconfig:/usr/local/lib/pkgconfig:/usr/share/pkgconfig
@@ -84,7 +91,7 @@ RUN cd /tmp && \
    git clone --recursive https://github.com/fmtlib/fmt.git && \
    mkdir -p fmt/build && cd fmt/build && \
    git checkout 5.2.0 && \
-   cmake -DBUILD_SHARED_LIBS=1 .. && make -j$(nproc) install && \
+   cmake ${CMAKE_OPTS} -DBUILD_SHARED_LIBS=1 .. && make -j$(nproc) install && \
    rm -rf /tmp/*
 			   
 # Build & Install spdlog
@@ -92,7 +99,7 @@ RUN cd /tmp && \
    git clone --recursive https://github.com/gabime/spdlog.git && \
    mkdir -p spdlog/build && cd spdlog/build && \
    git checkout v1.3.1 && \
-   cmake -DCMAKE_BUILD_TYPE=Release -DSPDLOG_FMT_EXTERNAL=1 -DSPDLOG_BUILD_BENCH=OFF .. && make -j$(nproc) install && \
+   cmake ${CMAKE_OPTS} -DCMAKE_BUILD_TYPE=Release -DSPDLOG_FMT_EXTERNAL=1 -DSPDLOG_BUILD_BENCH=OFF .. && make -j$(nproc) install && \
    rm -rf /tmp/*
 
 # Build & Install libwebsockets
@@ -118,8 +125,6 @@ RUN cd /tmp && \
 	../configure --host=${TRIPLET} && make -j$(nproc) install && \
 	rm -rf /tmp/*
 
-ENV LD_LIBRARY_PATH /usr/local/lib:/usr/lib:/usr/lib/${TRIPLET}
-
 WORKDIR /villas
 ENTRYPOINT bash