Build Using Clang

This commit is contained in:
TheBrokenRail 2021-09-14 18:10:32 -04:00
parent 6c791d6c9d
commit 647a482fbd
8 changed files with 63 additions and 25 deletions

View File

@ -27,10 +27,10 @@ endif()
# Use Clang By Default # Use Clang By Default
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(NOT DEFINED CMAKE_C_COMPILER) if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER clang) set(CMAKE_C_COMPILER "clang")
endif() endif()
if(NOT DEFINED CMAKE_CXX_COMPILER) if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER clang++) set(CMAKE_CXX_COMPILER "clang++")
endif() endif()
endif() endif()

View File

@ -4,10 +4,8 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_SYSTEM_PROCESSOR STREQU
add_compile_options("-m32") add_compile_options("-m32")
elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
# Use ARM Cross-Compiler # Use ARM Cross-Compiler
set(TARGET "arm-linux-gnueabihf") include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
set(CMAKE_C_COMPILER "${TARGET}-gcc") setup_toolchain("arm-linux-gnueabihf")
set(CMAKE_CXX_COMPILER "${TARGET}-g++")
set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}")
endif() endif()
set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm") set(CMAKE_SYSTEM_PROCESSOR "arm")

View File

@ -1,10 +1,8 @@
# Compile For ARM64 # 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")) 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 # Use ARM64 Cross-Compiler
set(TARGET "aarch64-linux-gnu") include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
set(CMAKE_C_COMPILER "${TARGET}-gcc") setup_toolchain("aarch64-linux-gnu")
set(CMAKE_CXX_COMPILER "${TARGET}-g++")
set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}")
endif() endif()
set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "aarch64") set(CMAKE_SYSTEM_PROCESSOR "aarch64")

View File

@ -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()

View File

@ -12,7 +12,9 @@
#include <media-layer/core.h> #include <media-layer/core.h>
#include <media-layer/internal.h> #include <media-layer/internal.h>
#ifndef MCPI_HEADLESS_MODE
#include "audio/engine.h" #include "audio/engine.h"
#endif // #ifndef MCPI_HEADLESS_MODE
// GLFW Code Not Needed In Headless Mode // GLFW Code Not Needed In Headless Mode
#ifndef MCPI_HEADLESS_MODE #ifndef MCPI_HEADLESS_MODE

14
scripts/build-all.sh Executable file
View File

@ -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

View File

@ -111,19 +111,11 @@ arm_build() {
cd ../../ cd ../../
} }
# Clean Prefix
rm -rf out
# Build # Build
native_build client if [ "$1" = "native" ]; then
native_build server native_build "$2"
if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then elif [ "$1" = "arm64" ]; then
# Requires ARM Versions Of GLFW And FreeImage arm64_build "$2"
arm64_build client elif [ "$1" = "arm" ]; then
arm_build "$2"
fi fi
arm64_build server
if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then
# Requires ARM Versions Of GLFW And FreeImage
arm_build client
fi
arm_build server

View File

@ -15,7 +15,7 @@ echo '==== Installing Dependencies ===='
# Build # Build
echo '==== Building ====' echo '==== Building ===='
./scripts/build.sh ./scripts/build-all.sh
# Test # Test
echo '==== Testing ====' echo '==== Testing ===='