From 647a482fbdd14e13cbc5abeda517b1f4c202292c Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 14 Sep 2021 18:10:32 -0400 Subject: [PATCH] Build Using Clang --- CMakeLists.txt | 4 ++-- cmake/arm-toolchain.cmake | 6 ++---- cmake/arm64-toolchain.cmake | 6 ++---- cmake/base-toolchain.cmake | 34 ++++++++++++++++++++++++++++++++++ media-layer/core/src/media.c | 2 ++ scripts/build-all.sh | 14 ++++++++++++++ scripts/build.sh | 20 ++++++-------------- scripts/ci/run.sh | 2 +- 8 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 cmake/base-toolchain.cmake create mode 100755 scripts/build-all.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ca206e3d..9fc3d4a47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,10 +27,10 @@ endif() # Use Clang By Default if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) if(NOT DEFINED CMAKE_C_COMPILER) - set(CMAKE_C_COMPILER clang) + set(CMAKE_C_COMPILER "clang") endif() if(NOT DEFINED CMAKE_CXX_COMPILER) - set(CMAKE_CXX_COMPILER clang++) + set(CMAKE_CXX_COMPILER "clang++") endif() endif() diff --git a/cmake/arm-toolchain.cmake b/cmake/arm-toolchain.cmake index fd87143b2..64610965f 100644 --- a/cmake/arm-toolchain.cmake +++ b/cmake/arm-toolchain.cmake @@ -4,10 +4,8 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_SYSTEM_PROCESSOR STREQU add_compile_options("-m32") elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") # Use ARM Cross-Compiler - set(TARGET "arm-linux-gnueabihf") - set(CMAKE_C_COMPILER "${TARGET}-gcc") - set(CMAKE_CXX_COMPILER "${TARGET}-g++") - set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}") + include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") + setup_toolchain("arm-linux-gnueabihf") endif() set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_PROCESSOR "arm") diff --git a/cmake/arm64-toolchain.cmake b/cmake/arm64-toolchain.cmake index 5f39b83d9..ee72cc7df 100644 --- a/cmake/arm64-toolchain.cmake +++ b/cmake/arm64-toolchain.cmake @@ -1,10 +1,8 @@ # Compile For ARM64 if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8l")) # Use ARM64 Cross-Compiler - set(TARGET "aarch64-linux-gnu") - set(CMAKE_C_COMPILER "${TARGET}-gcc") - set(CMAKE_CXX_COMPILER "${TARGET}-g++") - set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}") + include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") + setup_toolchain("aarch64-linux-gnu") endif() set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_PROCESSOR "aarch64") diff --git a/cmake/base-toolchain.cmake b/cmake/base-toolchain.cmake new file mode 100644 index 000000000..a424bacaa --- /dev/null +++ b/cmake/base-toolchain.cmake @@ -0,0 +1,34 @@ +# Pick GCC Version +macro(pick_gcc_version gcc_root gcc_version) + file(GLOB children RELATIVE "${gcc_root}" "${gcc_root}/*") + set("${gcc_version}" "") + foreach(child IN LISTS children) + if(IS_DIRECTORY "${gcc_root}/${child}" AND ("${${gcc_version}}" STREQUAL "" OR "${child}" GREATER_EQUAL "${${gcc_version}}")) + set("${gcc_version}" "${child}") + endif() + endforeach() + if("${${gcc_version}}" STREQUAL "") + message(FATAL_ERROR "Unable To Pick GCC Version") + endif() + message(STATUS "Using GCC Version: ${${gcc_version}}") +endmacro() + +# Setup Toolchain +macro(setup_toolchain target) + # Use ARM Cross-Compiler + set(CMAKE_C_COMPILER "clang") + set(CMAKE_C_COMPILER_TARGET "${target}") + set(CMAKE_CXX_COMPILER "clang++") + set(CMAKE_CXX_COMPILER_TARGET "${target}") + set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}") + # Include Directories + set(NEW_FLAGS "-nostdinc -nostdinc++ -Wno-unused-command-line-argument") + set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${NEW_FLAGS}") + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${NEW_FLAGS}") + pick_gcc_version("/usr/lib/gcc-cross/${target}" GCC_VERSION) + include_directories(SYSTEM "/usr/lib/gcc-cross/${target}/${GCC_VERSION}/include" "/usr/${target}/include/c++/${GCC_VERSION}" "/usr/${target}/include/c++/${GCC_VERSION}/${target}" "/usr/${target}/include") + # Extra + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endmacro() diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 3fa4889f9..d2143784f 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -12,7 +12,9 @@ #include #include +#ifndef MCPI_HEADLESS_MODE #include "audio/engine.h" +#endif // #ifndef MCPI_HEADLESS_MODE // GLFW Code Not Needed In Headless Mode #ifndef MCPI_HEADLESS_MODE diff --git a/scripts/build-all.sh b/scripts/build-all.sh new file mode 100755 index 000000000..4ecd3cf75 --- /dev/null +++ b/scripts/build-all.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +# Clean Prefix +rm -rf out + +# Build +./scripts/build.sh native client +./scripts/build.sh native server +./scripts/build.sh arm64_build client +./scripts/build.sh arm64 server +./scripts/build.sh arm client +./scripts/build.sh arm server diff --git a/scripts/build.sh b/scripts/build.sh index fd1b68984..ba4f9de95 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -111,19 +111,11 @@ arm_build() { cd ../../ } -# Clean Prefix -rm -rf out - # Build -native_build client -native_build server -if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then - # Requires ARM Versions Of GLFW And FreeImage - arm64_build client +if [ "$1" = "native" ]; then + native_build "$2" +elif [ "$1" = "arm64" ]; then + arm64_build "$2" +elif [ "$1" = "arm" ]; then + arm_build "$2" fi -arm64_build server -if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then - # Requires ARM Versions Of GLFW And FreeImage - arm_build client -fi -arm_build server diff --git a/scripts/ci/run.sh b/scripts/ci/run.sh index 99e0fff05..937904f5a 100755 --- a/scripts/ci/run.sh +++ b/scripts/ci/run.sh @@ -15,7 +15,7 @@ echo '==== Installing Dependencies ====' # Build echo '==== Building ====' -./scripts/build.sh +./scripts/build-all.sh # Test echo '==== Testing ===='