Skip to content

Commit c68fde2

Browse files
committed
Add CMake with toolchain file
1 parent 57cb8a9 commit c68fde2

File tree

9 files changed

+76
-5
lines changed

9 files changed

+76
-5
lines changed

.github/workflows/docker-push.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
- name: Build and push Docker image
4343
uses: docker/build-push-action@v3
4444
with:
45-
context: ${{ matrix.name }}
45+
context: .
46+
file: ${{ matrix.name }}/Dockerfile
4647
push: true
4748
tags: ${{ steps.meta.outputs.tags }}
4849
labels: ${{ steps.meta.outputs.labels }}

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ Docker containers are pushed to the GitHub container registry (ghcr.io) by a bui
66
All dockerfiles support these build tools:
77
- GNU make
88
- Python 3
9+
- CMake (with Ninja)
910

1011
To cross-compile something, mount the working directory to `/work` and run your make command like this:
1112
```shell
1213
docker run --rm -v $(pwd):/work ghcr.io/considerit/cross-linux-armhf-debian11 make $target
1314
```
1415

16+
To cross-compile with CMake, a toolchain file is used which expects libraries in `$CROSS_SYSROOT/lib` and includes in `$CROSS_SYSROOT/include`.
17+
```shell
18+
# add -DCMAKE_TOOLCHAIN_FILE=/var/cross-sysroot/toolchain.cmake to your cmake call or use wrapper script on config step
19+
docker run --rm -v $(pwd):/work ghcr.io/considerit/cross-linux-armhf-debian11 cmake-cross -B ./build-armhf
20+
21+
docker run --rm -v $(pwd):/work ghcr.io/considerit/cross-linux-armhf-debian11 cmake --build ./build-armhf
22+
```
23+
1524
If you want to build the images yourself, run `docker build` on the individual dockerfiles like this:
1625
```shell
1726
cd linux-gnueabihf-debian11

cmake-cross.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
echo "cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE $@"
3+
cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE $@

linux-aarch64-debian11/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM debian:11-slim
22

33
ARG workdir=/work
4+
ENV CROSS_SYSROOT=/var/cross-sysroot
45

56
# install basic utilities
67
RUN apt update && apt -y install git rsync python3
@@ -12,6 +13,13 @@ RUN git config --global --add safe.directory $workdir
1213
RUN apt -y install g++-aarch64-linux-gnu
1314

1415
# install basic build tools
15-
RUN apt -y install build-essential make ccache
16+
RUN apt -y install build-essential make ccache cmake ninja-build
17+
18+
# setup CMake for cross-compiling
19+
RUN mkdir -p ${CROSS_SYSROOT}/include/
20+
RUN mkdir -p ${CROSS_SYSROOT}/lib/
21+
ENV CMAKE_TOOLCHAIN_FILE=${CROSS_SYSROOT}/toolchain.cmake
22+
COPY linux-aarch64-tc.cmake ${CMAKE_TOOLCHAIN_FILE}
23+
COPY cmake-cross.sh /usr/bin/cmake-cross
1624

1725
WORKDIR $workdir

linux-aarch64-tc.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(CMAKE_SYSTEM_NAME Linux)
2+
set(CMAKE_SYSTEM_PROCESSOR aarch64)
3+
4+
set(CMAKE_SYSROOT $ENV{CROSS_SYSROOT})
5+
set(cross_tripe "aarch64-linux-gnu")
6+
7+
set(CMAKE_C_COMPILER ${cross_tripe}-gcc)
8+
set(CMAKE_CXX_COMPILER ${cross_tripe}-g++)
9+
10+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

linux-armhf-debian10/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM debian:10-slim
22

33
ARG workdir=/work
4+
ENV CROSS_SYSROOT=/var/cross-sysroot
45

56
# install basic utilities
67
RUN apt update && apt -y install git rsync python3
@@ -12,6 +13,13 @@ RUN git config --global --add safe.directory $workdir
1213
RUN apt -y install g++-arm-linux-gnueabihf
1314

1415
# install basic build tools
15-
RUN apt -y install build-essential make ccache
16+
RUN apt -y install build-essential make ccache cmake ninja-build
17+
18+
# setup CMake for cross-compiling
19+
RUN mkdir -p ${CROSS_SYSROOT}/include/
20+
RUN mkdir -p ${CROSS_SYSROOT}/lib/
21+
ENV CMAKE_TOOLCHAIN_FILE=${CROSS_SYSROOT}/toolchain.cmake
22+
COPY linux-armhf-tc.cmake ${CMAKE_TOOLCHAIN_FILE}
23+
COPY cmake-cross.sh /usr/bin/cmake-cross
1624

1725
WORKDIR $workdir

linux-armhf-debian11/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM debian:11-slim
22

33
ARG workdir=/work
4+
ENV CROSS_SYSROOT=/var/cross-sysroot
45

56
# install basic utilities
67
RUN apt update && apt -y install git rsync python3
@@ -12,6 +13,13 @@ RUN git config --global --add safe.directory $workdir
1213
RUN apt -y install g++-arm-linux-gnueabihf
1314

1415
# install basic build tools
15-
RUN apt -y install build-essential make ccache
16+
RUN apt -y install build-essential make ccache cmake ninja-build
17+
18+
# setup CMake for cross-compiling
19+
RUN mkdir -p ${CROSS_SYSROOT}/include/
20+
RUN mkdir -p ${CROSS_SYSROOT}/lib/
21+
ENV CMAKE_TOOLCHAIN_FILE=${CROSS_SYSROOT}/toolchain.cmake
22+
COPY linux-armhf-tc.cmake ${CMAKE_TOOLCHAIN_FILE}
23+
COPY cmake-cross.sh /usr/bin/cmake-cross
1624

1725
WORKDIR $workdir

linux-armhf-tc.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(CMAKE_SYSTEM_NAME Linux)
2+
set(CMAKE_SYSTEM_PROCESSOR armhf)
3+
4+
set(CMAKE_SYSROOT $ENV{CROSS_SYSROOT})
5+
set(cross_tripe "arm-linux-gnueabihf")
6+
7+
set(CMAKE_C_COMPILER ${cross_tripe}-gcc)
8+
set(CMAKE_CXX_COMPILER ${cross_tripe}-g++)
9+
10+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
11+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
12+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
13+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

linux-armhf-ubuntu18/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM ubuntu:18.04
22

33
ARG workdir=/work
4+
ENV CROSS_SYSROOT=/var/cross-sysroot
45

56
# install basic utilities
67
RUN apt update && apt -y install git rsync python3
@@ -12,6 +13,13 @@ RUN git config --global --add safe.directory $workdir
1213
RUN apt -y install g++-arm-linux-gnueabihf
1314

1415
# install basic build tools
15-
RUN apt -y install build-essential make ccache
16+
RUN apt -y install build-essential make ccache cmake ninja-build
17+
18+
# setup CMake for cross-compiling
19+
RUN mkdir -p ${CROSS_SYSROOT}/include/
20+
RUN mkdir -p ${CROSS_SYSROOT}/lib/
21+
ENV CMAKE_TOOLCHAIN_FILE=${CROSS_SYSROOT}/toolchain.cmake
22+
COPY linux-armhf-tc.cmake ${CMAKE_TOOLCHAIN_FILE}
23+
COPY cmake-cross.sh /usr/bin/cmake-cross
1624

1725
WORKDIR $workdir

0 commit comments

Comments
 (0)