forked from aminya/project_options
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cross compiler detection (aminya#140)
* add mingw toolchains * add docker for testing
- Loading branch information
Showing
14 changed files
with
310 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM ubuntu:20.04 AS base | ||
|
||
# add setup_cpp | ||
ADD https://github.com/aminya/setup-cpp/releases/download/v0.21.0/setup_cpp_linux /setup_cpp_linux | ||
RUN chmod +x /setup_cpp_linux | ||
|
||
|
||
FROM base AS setup | ||
|
||
ARG compiler="gcc" | ||
# install cmake, ninja, and ccache | ||
RUN /setup_cpp_linux --compiler $compiler --llvm true --cmake true --ninja true --ccache true --doxygen true --cppcheck true --vcpkg true --conan true --task true | ||
|
||
# update vcpkg | ||
#WORKDIR /root/vcpkg | ||
#RUN git pull origin master | ||
#RUN ./vcpkg update | ||
#WORKDIR / | ||
|
||
COPY ./docker/entrypoint.sh /docker-entrypoint.sh | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
|
||
|
||
FROM setup AS build | ||
COPY . /home/project_options | ||
WORKDIR /home/project_options/test | ||
CMD ["/home/project_options/docker/build.sh"] | ||
|
||
|
||
FROM setup AS test | ||
COPY . /home/project_options | ||
WORKDIR /home/project_options/test | ||
CMD ["/home/project_options/docker/test.sh"] | ||
|
||
|
||
FROM gcr.io/distroless/cc AS runner | ||
COPY --from=build /home/project_options/test/build/Release/ /home/app/ | ||
WORKDIR /home/app/ | ||
ENTRYPOINT ["./build/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM ubuntu:20.04 AS base | ||
|
||
# add setup_cpp | ||
ADD https://github.com/aminya/setup-cpp/releases/download/v0.21.0/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 --llvm true --cmake true --ninja true --ccache true --doxygen true --cppcheck true --vcpkg true --conan true --task true | ||
|
||
# TODO: install cross-compiler with setup_cpp_linux | ||
# NOTE: install mingw by hand, waiting for setup-cpp to have mingw cross-compiler support | ||
RUN apt-get update && apt-get install -y \ | ||
mingw-w64 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# update vcpkg | ||
#WORKDIR /root/vcpkg | ||
#RUN git pull origin master | ||
#RUN ./vcpkg update | ||
#WORKDIR / | ||
|
||
COPY ./docker/entrypoint.sh /docker-entrypoint.sh | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
|
||
|
||
FROM setup AS build | ||
COPY . /home/project_options | ||
WORKDIR /home/project_options/test | ||
CMD ["/home/project_options/docker/build.mingw.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# setup compiler | ||
export CC=${CROSS_CC:-x86_64-w64-mingw32-gcc} | ||
export CXX=${CROSS_CXX:-x86_64-w64-mingw32-g++} | ||
|
||
mkdir build | ||
cd build | ||
|
||
cmake -B . -G "Ninja" -DCMAKE_BUILD_TYPE:STRING=Release \ | ||
-DENABLE_CROSS_COMPILING:BOOL=ON .. | ||
cmake --build . --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
mkdir build | ||
cd build | ||
|
||
cmake -B . -G "Ninja" -DCMAKE_BUILD_TYPE:STRING=Release .. | ||
cmake --build . --config Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
source ~/.cpprc | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
mkdir build | ||
cd build | ||
|
||
cmake -B . -G "Ninja" -DCMAKE_BUILD_TYPE:STRING=Debug .. | ||
cmake --build . --config Debug | ||
ctest -C Debug --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
include_guard() | ||
|
||
macro(enable_cross_compiler) | ||
include("${ProjectOptions_SRC_DIR}/Utilities.cmake") | ||
detect_architecture(_arch) | ||
if(NOT DEFINED TARGET_ARCHITECTURE) | ||
if($ENV{CC} MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR $ENV{CXX} MATCHES "x86_64(-w64)?-mingw32-[gc]..?") | ||
set(TARGET_ARCHITECTURE "x64") | ||
elseif($ENV{CC} MATCHES "i686(-w64)?-mingw32-[gc]..?" OR $ENV{CXX} MATCHES "i686(-w64)?-mingw32-[gc]..?") | ||
set(TARGET_ARCHITECTURE "x86") | ||
elseif($ENV{CC} MATCHES "emcc" OR $ENV{CXX} MATCHES "em++") | ||
set(TARGET_ARCHITECTURE "wasm32") | ||
else() | ||
# TODO: check for arm compiler | ||
set(TARGET_ARCHITECTURE ${_arch}) | ||
endif() | ||
endif() | ||
|
||
if (NOT DEFINED HOST_TRIPLET) | ||
if(WIN32) | ||
set(HOST_TRIPLET "${_arch}-windows") | ||
elseif(APPLE) | ||
set(HOST_TRIPLET "${_arch}-osx") | ||
elseif(UNIX AND NOT APPLE) | ||
set(HOST_TRIPLET "${_arch}-linux") | ||
endif() | ||
endif() | ||
|
||
if($ENV{CC} MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?" OR $ENV{CXX} MATCHES "(x86_64|i686)(-w64)?-mingw32-[gc]..?") | ||
set(MINGW TRUE) | ||
elseif($ENV{CC} MATCHES "emcc" OR $ENV{CXX} MATCHES "em++") | ||
set(EMSCRIPTEN TRUE) | ||
endif() | ||
|
||
set(LIBRARY_LINKAGE) | ||
if(BUILD_SHARED_LIBS) | ||
set(LIBRARY_LINKAGE "dynamic") | ||
else() | ||
set(LIBRARY_LINKAGE "static") | ||
endif() | ||
|
||
if (NOT DEFINED CROSS_ROOT) | ||
if($ENV{CC} MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR $ENV{CXX} MATCHES "x86_64(-w64)?-mingw32-[gc]..?") | ||
set(CROSS_ROOT "/usr/x86_64-w64-mingw32") | ||
elseif($ENV{CC} MATCHES "i686(-w64)?-mingw32-[gc]..?" OR $ENV{CXX} MATCHES "i686(-w64)?-mingw32-[gc]..?") | ||
set(CROSS_ROOT "/usr/i686-w64-mingw32") | ||
endif() | ||
# TODO: check if path is right, check for header files or something | ||
endif() | ||
|
||
set(_toolchain_file) | ||
get_toolchain_file(_toolchain_file) | ||
set(CMAKE_TOOLCHAIN_FILE ${_toolchain_file}) | ||
set(CROSSCOMPILING TRUE) | ||
endmacro() | ||
|
||
function(get_toolchain_file value) | ||
include("${ProjectOptions_SRC_DIR}/Utilities.cmake") | ||
detect_architecture(_arch) | ||
if(DEFINED TARGET_ARCHITECTURE) | ||
set(_arch ${TARGET_ARCHITECTURE}) | ||
endif() | ||
if("${_arch}" MATCHES "x64") | ||
set(_arch "x86_64") | ||
elseif("${_arch}" MATCHES "x86") | ||
set(_arch "x86_64") | ||
endif() | ||
|
||
if (MINGW) | ||
set(${value} | ||
${ProjectOptions_SRC_DIR}/toolchains/${_arch}-w64-mingw32.toolchain.cmake | ||
PARENT_SCOPE) | ||
elseif(EMSCRIPTEN) | ||
set(${value} | ||
"/usr/lib/emscripten/cmake/Modules/Platform/Emscripten.cmake" | ||
PARENT_SCOPE) | ||
endif() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(CMAKE_SYSTEM_NAME Windows) | ||
set(CMAKE_SYSTEM_PROCESSOR "i686") | ||
|
||
if ($ENV{CROSS_ROOT}) | ||
#set(CMAKE_SYSROOT $ENV{CROSS_ROOT}) | ||
set(CMAKE_FIND_ROOT_PATH $ENV{CROSS_ROOT}) | ||
elseif (DEFINED CROSS_ROOT) | ||
#set(CMAKE_SYSROOT ${CROSS_ROOT}) | ||
set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) | ||
else() | ||
#set(CMAKE_SYSROOT /usr/i686-w64-mingw32) | ||
set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) | ||
endif() | ||
|
||
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) | ||
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) | ||
set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) | ||
|
||
# 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) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | ||
|
||
# override boost thread component suffix as mingw-w64-boost is compiled with threadapi=win32 | ||
set(Boost_THREADAPI win32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
set(CMAKE_SYSTEM_NAME Windows) | ||
set(CMAKE_SYSTEM_PROCESSOR "x64") | ||
|
||
if ($ENV{CROSS_ROOT}) | ||
#set(CMAKE_SYSROOT $ENV{CROSS_ROOT}) | ||
set(CMAKE_FIND_ROOT_PATH $ENV{CROSS_ROOT}) | ||
elseif (DEFINED CROSS_ROOT) | ||
#set(CMAKE_SYSROOT ${CROSS_ROOT}) | ||
set(CMAKE_FIND_ROOT_PATH ${CROSS_ROOT}) | ||
else() | ||
#set(CMAKE_SYSROOT /usr/x86_64-w64-mingw32) | ||
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) | ||
endif() | ||
|
||
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) | ||
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) | ||
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) | ||
|
||
# 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) | ||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) | ||
|
||
# override boost thread component suffix as mingw-w64-boost is compiled with threadapi=win32 | ||
set(Boost_THREADAPI win32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters