From f3a7563f677409f7f84de5e9ab849024707126ce Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 14 Aug 2022 16:14:52 +0000 Subject: [PATCH] WIP: Build system tweaks to enable cross/distcc/clang/mold --- .gitignore | 1 + README | 4 +++ build.sh | 26 +++++++------------ compile-config.sample | 12 +++++++++ compiler | 5 ++++ src/CMakeLists.txt | 7 +++-- ...hainRPi.txt => CMakeToolChainRPiClang.txt} | 15 +++-------- src/CMakeToolChainRPiGCC.txt | 17 ++++++++++++ 8 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 README create mode 100644 compile-config.sample create mode 100755 compiler rename src/{CMakeToolChainRPi.txt => CMakeToolChainRPiClang.txt} (51%) create mode 100644 src/CMakeToolChainRPiGCC.txt diff --git a/.gitignore b/.gitignore index 0974245..28337fa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .#* config.json build +compile-config diff --git a/README b/README new file mode 100644 index 0000000..95f53bb --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +How to set up a build: + +Copy compile-config.sample to compile-config + diff --git a/build.sh b/build.sh index 6567297..340edcd 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,15 @@ #!/bin/bash -NATIVE=no - -if grep -q BCM2708 /proc/cpuinfo ; then - NATIVE=yes -elif grep -q BCM2709 /proc/cpuinfo ; then - NATIVE=yes -elif grep -q BCM2835 /proc/cpuinfo ; then - NATIVE=yes -else - NATIVE=no -fi - -if [ $NATIVE == "no" ]; then - CROSS_COMPILE_INSERT=-DCMAKE_TOOLCHAIN_FILE=../src/CMakeToolChainRPi.txt - CROSS_COMPILE_J=-j8 +source compile-config + +if [ $CROSS_COMPILE == "yes" ]; then + if [ $CROSS_COMPILER == "gcc" ]; then + CROSS_COMPILE_INSERT=-DCMAKE_TOOLCHAIN_FILE=../src/CMakeToolChainRPiGCC.txt + elif [ $CROSS_COMPILER == "clang" ]; then + CROSS_COMPILE_INSERT=-DCMAKE_TOOLCHAIN_FILE=../src/CMakeToolChainRPiClang.txt + fi fi mkdir build -cmake $CROSS_COMPILE_INSERT -S src -B build && make -C build $CROSS_COMPILE_J +cmake $CROSS_COMPILE_INSERT -DENABLE_MOLD=${ENABLE_MOLD} -DMOLD_BIN=${MOLD_BIN} \ + -S src -B build && make -C build -j$MAKE_J diff --git a/compile-config.sample b/compile-config.sample new file mode 100644 index 0000000..ee9000a --- /dev/null +++ b/compile-config.sample @@ -0,0 +1,12 @@ +# Set the number of concurrent threads for compiling (make's -j option): +MAKE_J=1 + +# Enable cross-compiling +CROSS_COMPILE=no + +# Set cross compiler. Options: gcc clang +CROSS_COMPILER=gcc + +# Use mold for linker? (Only possible if compiler is clang) +ENABLE_MOLD=no +MOLD_BIN=/opt/mold/bin/mold diff --git a/compiler b/compiler new file mode 100755 index 0000000..afff73d --- /dev/null +++ b/compiler @@ -0,0 +1,5 @@ +#!/bin/bash + +/usr/bin/distcc /usr/bin/clang-11 "$@" +#/usr/bin/clang-11 "$@" + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 964af00..d34a97a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,8 +68,11 @@ set (PNG_FILES project(vomp) add_executable(vomp ${VOMP_OBJ_COMMON} ${VOMP_OBJ_RASPBERRY} pngs.o) -# Enable next line to use mold linker. Only available when using clang -target_link_options(vomp PRIVATE "-fuse-ld=/opt/mold/bin/mold") +# set(CMAKE_CXX_COMPILER_LAUNCHER "distcc") - not until cmake 3.17! + +if (${ENABLE_MOLD}) + target_link_options(vomp PRIVATE "-fuse-ld=${MOLD_BIN}") +endif() set(CMAKE_BUILD_TYPE Debug) target_compile_options(vomp PRIVATE -O0) diff --git a/src/CMakeToolChainRPi.txt b/src/CMakeToolChainRPiClang.txt similarity index 51% rename from src/CMakeToolChainRPi.txt rename to src/CMakeToolChainRPiClang.txt index d437ad9..063e2fe 100644 --- a/src/CMakeToolChainRPi.txt +++ b/src/CMakeToolChainRPiClang.txt @@ -3,18 +3,11 @@ set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_FIND_ROOT_PATH /pi-root) set(CMAKE_SYSROOT /pi-root) - -# GCC -#set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc) -#set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++) -#set(CMAKE_C_FLAGS "-Wno-psabi -mtune=cortex-a7 -mfloat-abi=hard -fopenmp") -#set(CMAKE_CXX_FLAGS "-Wno-psabi -mtune=cortex-a7 -mfloat-abi=hard -fopenmp") - -# Pi1: -mtune=arm1176jzf-s Pi2: -mtune=cortex-a7 Pi3: -mtune=cortex-a53 - # Clang -set(CMAKE_C_COMPILER /usr/bin/clang-11) -set(CMAKE_CXX_COMPILER /usr/bin/clang++-11) +#set(CMAKE_C_COMPILER "/usr/bin/clang-11") +#set(CMAKE_CXX_COMPILER "/usr/bin/clang++-11") +set(CMAKE_C_COMPILER "/opt/vompclient/compiler") +set(CMAKE_CXX_COMPILER "/opt/vompclient/compiler") set(CMAKE_LINKER /usr/bin/arm-linux-gnueabihf-ld) set(CMAKE_C_FLAGS "-target arm-linux-gnueabihf -mfloat-abi=hard -mcpu=cortex-a7") set(CMAKE_CXX_FLAGS "-target arm-linux-gnueabihf -mfloat-abi=hard -mcpu=cortex-a7") diff --git a/src/CMakeToolChainRPiGCC.txt b/src/CMakeToolChainRPiGCC.txt new file mode 100644 index 0000000..4a14672 --- /dev/null +++ b/src/CMakeToolChainRPiGCC.txt @@ -0,0 +1,17 @@ +set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_FIND_ROOT_PATH /pi-root) +set(CMAKE_SYSROOT /pi-root) + +# GCC +set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc) +set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++) +set(CMAKE_C_FLAGS "-Wno-psabi -mtune=cortex-a7 -mfloat-abi=hard -fopenmp") +set(CMAKE_CXX_FLAGS "-Wno-psabi -mtune=cortex-a7 -mfloat-abi=hard -fopenmp") + +# Pi1: -mtune=arm1176jzf-s Pi2: -mtune=cortex-a7 Pi3: -mtune=cortex-a53 + + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -- 2.39.5