Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: Cross-compiling with ARM cross-compiler #188

Merged
merged 16 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ includes:
emscripten:
taskfile: ./tests/emscripten/Taskfile.yml
dir: ./tests/emscripten
rpi3:
taskfile: ./tests/rpi3/Taskfile.yml
dir: ./tests/rpi3
rpi4:
taskfile: ./tests/rpi4/Taskfile.yml
dir: ./tests/rpi4
rpi4-vcpkg:
taskfile: ./tests/rpi4-vcpkg/Taskfile.yml
dir: ./tests/rpi4-vcpkg
pico:
taskfile: ./tests/pico/Taskfile.yml
dir: ./tests/pico

vars:
CWD:
Expand All @@ -35,6 +47,10 @@ tasks:
- task: install:lint
- task: minimal:lint
- task: emscripten:lint
- task: rpi3:lint
- task: rpi4:lint
- task: rpi4-vcpkg:lint
- task: pico:lint
- npx -y cspell lint --no-progress --show-suggestions

clean:
Expand Down
42 changes: 41 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,44 @@ services:
target: build-minimal
environment:
- CROSS_CC=i686-w64-mingw32-gcc
- CROSS_CXX=i686-w64-mingw32-g++
- CROSS_CXX=i686-w64-mingw32-g++
build-rpi3:
build:
context: .
dockerfile: ./docker/Dockerfile.arm
target: build
build-rpi3-release:
build:
context: .
dockerfile: ./docker/Dockerfile.arm
target: build-release
build-rpi4:
build:
context: .
dockerfile: ./docker/Dockerfile.aarch64
target: build
build-rpi4-release:
build:
context: .
dockerfile: ./docker/Dockerfile.aarch64
target: build-release
test-rpi4:
build:
context: .
dockerfile: ./docker/Dockerfile.aarch64
target: test
build-rpi4-vcpkg:
build:
context: .
dockerfile: ./docker/Dockerfile.aarch64
target: build-vcpkg
build-rpi4-custom:
build:
context: .
dockerfile: ./docker/Dockerfile.aarch64
target: build-custom
build-pico:
build:
context: .
dockerfile: ./docker/Dockerfile.pico
target: build
52 changes: 52 additions & 0 deletions docker/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM ubuntu:22.04 AS base

ARG setup_cpp_linux_version="0.24.1"

# add setup_cpp https://github.com/aminya/setup-cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux



FROM base AS setup

# install cmake, ninja, and ccache
RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true

RUN apt-get update && apt-get install -y \
g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

COPY ./docker/entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]


FROM setup AS build
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi4:build.cross"]

FROM setup AS build-release
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi4:build.cross.release"]

FROM setup AS build-vcpkg
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi4-vcpkg:build.cross"]

FROM setup AS build-custom
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi4:build.cross.custom-toolchain"]


FROM setup AS test
RUN apt-get update && apt-get install -y \
qemu-user \
&& rm -rf /var/lib/apt/lists/*
COPY . /home/project_options
WORKDIR /home/project_options
ENV QEMU_LD_PREFIX /usr/aarch64-linux-gnu
CMD ["/bin/bash", "-c", "task rpi4:build.cross.release && qemu-aarch64 /home/project_options/tests/rpi4/build/Release/example"]
33 changes: 33 additions & 0 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:22.04 AS base

ARG setup_cpp_linux_version="0.24.1"

# add setup_cpp https://github.com/aminya/setup-cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux



FROM base AS setup

# install cmake, ninja, and ccache
RUN /setup_cpp_linux --clangtidy true --clangformat true --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true

RUN apt-get update && apt-get install -y \
gcc-arm-none-eabi binutils-arm-none-eabi \
&& rm -rf /var/lib/apt/lists/*

COPY ./docker/entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]


FROM setup AS build
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi3:build.cross"]


FROM setup AS build-release
COPY . /home/project_options
WORKDIR /home/project_options
CMD ["/bin/bash", "-c", "task rpi3:build.cross.release"]
37 changes: 37 additions & 0 deletions docker/Dockerfile.pico
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:22.04 AS base

ARG setup_cpp_linux_version="0.24.1"

# add setup_cpp https://github.com/aminya/setup-cpp
ADD https://github.com/aminya/setup-cpp/releases/download/v${setup_cpp_linux_version}/setup_cpp_linux /setup_cpp_linux
RUN chmod +x /setup_cpp_linux



FROM base AS setup

# install cmake, ninja, and ccache
RUN /setup_cpp_linux --cmake true --ninja true --ccache true --cppcheck true --vcpkg true --conan true --task true

RUN apt-get update && apt-get install -y \
gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib \
&& rm -rf /var/lib/apt/lists/*

# https://github.com/raspberrypi/pico-sdk
RUN git clone https://github.com/raspberrypi/pico-sdk /home/pico-sdk
ENV PICO_SDK_PATH /home/pico-sdk
WORKDIR /home/pico-sdk
RUN git submodule update --init
WORKDIR /

COPY ./docker/entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]


FROM setup AS build
COPY . /home/project_options
RUN cp -rf /home/pico-sdk/external/pico_sdk_import.cmake /home/project_options/tests/pico/pico_sdk_import.cmake
WORKDIR /home/project_options
ENV PROJECT_DIR /home/project_options
CMD ["/bin/bash", "-c", "task pico:build"]

32 changes: 32 additions & 0 deletions docker/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,36 @@ tasks:

emscripten:
- docker-compose up --build build-emscripten
- docker-compose down

rpi3:
- docker-compose up --build build-rpi3
- docker-compose down

rpi3.release:
- docker-compose up --build build-rpi3-release
- docker-compose down

rpi4:
- docker-compose up --build build-rpi4
- docker-compose down

rpi4.release:
- docker-compose up --build build-rpi4-release
- docker-compose down

rpi4.test:
- docker-compose up --build test-rpi4
- docker-compose down

rpi4.vcpkg:
- docker-compose up --build build-rpi4-vcpkg
- docker-compose down

rpi4.custom:
- docker-compose up --build build-rpi4-custom
- docker-compose down

pico:
- docker-compose up --build build-pico
- docker-compose down
52 changes: 51 additions & 1 deletion src/CrossCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ macro(enable_cross_compiler)
set(_cc "emcc")
set(_cxx "em++")
set(TARGET_ARCHITECTURE "wasm32-emscripten")
elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux")
set(TARGET_ARCHITECTURE "arm-linux")
elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux")
set(TARGET_ARCHITECTURE "arm64-linux")
endif()

if("${TARGET_ARCHITECTURE}" STREQUAL "")
Expand All @@ -48,6 +52,7 @@ macro(enable_cross_compiler)
set(TARGET_ARCHITECTURE "wasm32-emscripten")
else()
# TODO: check for arm compiler
message(WARNING "if you are using arm cross-compiler, please set DEFAULT_TRIPLET")
set(TARGET_ARCHITECTURE ${_arch})
endif()
endif()
Expand All @@ -64,11 +69,20 @@ macro(enable_cross_compiler)

set(USE_CROSSCOMPILER_MINGW)
set(USE_CROSSCOMPILER_EMSCRIPTEN)
set(USE_CROSSCOMPILER_ARM)
set(USE_CROSSCOMPILER_ARM64)
set(USE_CROSSCOMPILER_AARCH64)
if(_cc MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?")
set(MINGW TRUE)
set(USE_CROSSCOMPILER_MINGW TRUE)
elseif(_cc MATCHES "emcc" OR _cxx MATCHES "em\\+\\+")
set(USE_CROSSCOMPILER_EMSCRIPTEN TRUE)
elseif(_cc MATCHES "aarch64-linux-gnu-gcc" OR _cxx MATCHES "aarch64-linux-gnu-g\\+\\+")
set(USE_CROSSCOMPILER_AARCH64 TRUE)
elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux")
set(USE_CROSSCOMPILER_ARM TRUE)
elseif("${DEFAULT_TRIPLET}" STREQUAL "arm64-linux")
set(USE_CROSSCOMPILER_ARM64 TRUE)
endif()

set(LIBRARY_LINKAGE)
Expand All @@ -92,6 +106,26 @@ macro(enable_cross_compiler)
set(CROSS_ROOT "/usr/x86_64-w64-mingw32")
elseif(_cc MATCHES "i686(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "i686(-w64)?-mingw32-[gc]..?")
set(CROSS_ROOT "/usr/i686-w64-mingw32")
elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabi-[gc]..?")
set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabi")
if(NOT DEFINED CROSS_TRIPLET)
set(CROSS_TRIPLET "arm-linux-gnueabi")
endif()
elseif(_cc MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-linux-gnueabihf-[gc]..?")
set(CROSS_ROOT "/usr/gcc-arm-linux-gnueabihf")
if(NOT DEFINED CROSS_TRIPLET)
set(CROSS_TRIPLET "arm-linux-gnueabihf")
endif()
elseif(_cc MATCHES "(gcc-)?arm-none-eabi-[gc]..?" OR _cxx MATCHES "(gcc-)?arm-none-eabi-[gc]..?")
set(CROSS_ROOT "/usr/gcc-arm-none-eabi")
if(NOT DEFINED CROSS_TRIPLET)
set(CROSS_TRIPLET "arm-none-eabi")
endif()
elseif(_cc MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?" OR _cxx MATCHES "(gcc-)?aarch64-linux-gnu-[gc]..?")
set(CROSS_ROOT "/usr/gcc-aarch64-linux-gnu")
if(NOT DEFINED CROSS_TRIPLET)
set(CROSS_TRIPLET "gcc-aarch64-linux-gnu")
endif()
endif()
# TODO: check if path is right, check for header files or something
endif()
Expand Down Expand Up @@ -133,7 +167,9 @@ macro(enable_cross_compiler)

set(_toolchain_file)
get_toolchain_file(_toolchain_file)
set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file})
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file})
endif()
set(CROSSCOMPILING TRUE)

message(STATUS "enable cross-compiling")
Expand Down Expand Up @@ -183,5 +219,19 @@ function(get_toolchain_file value)
else()
message(ERROR "EMSCRIPTEN_ROOT is not set, please define EMSCRIPTEN_ROOT (emscripten repo)")
endif()
elseif(USE_CROSSCOMPILER_AARCH64)
set(${value}
${ProjectOptions_SRC_DIR}/toolchains/aarch64.toolchain.cmake
PARENT_SCOPE)
elseif(USE_CROSSCOMPILER_ARM)
set(${value}
${ProjectOptions_SRC_DIR}/toolchains/arm.toolchain.cmake
PARENT_SCOPE)
elseif(USE_CROSSCOMPILER_ARM64)
set(${value}
${ProjectOptions_SRC_DIR}/toolchains/arm64.toolchain.cmake
PARENT_SCOPE)
elseif("${DEFAULT_TRIPLET}" STREQUAL "arm-linux" OR "${DEFAULT_TRIPLET}" STREQUAL "arm64-linux")
message(STATUS "Don't forget to provide an cmake-toolchain file (for ${DEFAULT_TRIPLET})")
endif()
endfunction()
3 changes: 2 additions & 1 deletion src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ macro(project_options)
GCC_WARNINGS
CUDA_WARNINGS
CPPCHECK_OPTIONS
CLANG_TIDY_EXTRA_ARGUMENTS
PCH_HEADERS
CONAN_OPTIONS)
cmake_parse_arguments(
Expand Down Expand Up @@ -219,7 +220,7 @@ macro(project_options)
endif()

if(${ProjectOptions_ENABLE_CLANG_TIDY})
enable_clang_tidy()
enable_clang_tidy("${ProjectOptions_CLANG_TIDY_EXTRA_ARGUMENTS}")
endif()

if(${ProjectOptions_ENABLE_VS_ANALYSIS})
Expand Down
5 changes: 4 additions & 1 deletion src/StaticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ macro(enable_cppcheck CPPCHECK_OPTIONS)
endmacro()

# Enable static analysis with clang-tidy
macro(enable_clang_tidy)
macro(enable_clang_tidy CLANG_TIDY_EXTRA_ARGUMENTS)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)

Expand Down Expand Up @@ -114,6 +114,9 @@ macro(enable_clang_tidy)
endif()
endif()

set(CMAKE_C_CLANG_TIDY ${CMAKE_C_CLANG_TIDY} ${CLANG_TIDY_EXTRA_ARGUMENTS})
set(CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY} ${CLANG_TIDY_EXTRA_ARGUMENTS})

else()
message(${WARNING_MESSAGE} "clang-tidy requested but executable not found")
endif()
Expand Down
Loading