Improve Build System

This commit is contained in:
TheBrokenRail 2021-09-16 22:00:40 -04:00
parent 0465dc75a7
commit db64afc550
9 changed files with 49 additions and 87 deletions

View File

@ -25,26 +25,18 @@ else()
endif() endif()
# Use Clang By Default # Use Clang By Default
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()
# Setup ARM Cross Compilation # Setup ARM Cross Compilation
if(USE_ARM32_TOOLCHAIN) if(USE_ARM32_TOOLCHAIN)
include(cmake/arm-toolchain.cmake) include(cmake/arm-toolchain.cmake)
endif() endif()
# Use LLD When Using Clang
if(CMAKE_C_COMPILER STREQUAL "clang")
add_link_options("-fuse-ld=lld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") # Fix try_compile()
endif()
# Utility Functions # Utility Functions
include(cmake/util.cmake) include(cmake/util.cmake)
@ -92,6 +84,11 @@ add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
# Use LLD When Using Clang
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_link_options("-fuse-ld=lld")
endif()
# Specify Constants # Specify Constants
if(MCPI_SERVER_MODE) if(MCPI_SERVER_MODE)
add_definitions(-DMCPI_SERVER_MODE) add_definitions(-DMCPI_SERVER_MODE)

View File

@ -1,8 +1,8 @@
# Compile For ARM # Compile For ARM
if(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(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8l")
# Force 32-Bit Compile # Force 32-Bit Compile
add_compile_options("-m32") add_compile_options("-m32")
elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm") elseif(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm")
# Use ARM Cross-Compiler # Use ARM Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("arm-linux-gnueabihf") setup_toolchain("arm-linux-gnueabihf")

View File

@ -1,5 +1,5 @@
# 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_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8l"))
# Use ARM64 Cross-Compiler # Use ARM64 Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake") include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("aarch64-linux-gnu") setup_toolchain("aarch64-linux-gnu")

View File

@ -0,0 +1,8 @@
# Compile For x86_64
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
# Use x86_64 Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("x86_64-linux-gnu")
endif()
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -137,8 +137,7 @@ int main(int argc, char *argv[]) {
// Minecraft Folder // Minecraft Folder
{ {
char *minecraft_folder = NULL; char *minecraft_folder = NULL;
asprintf(&minecraft_folder, "%s/.minecraft-pi", getenv("HOME")); safe_asprintf(&minecraft_folder, "%s/.minecraft-pi", getenv("HOME"));
ALLOC_CHECK(minecraft_folder);
{ {
// Check Minecraft Folder // Check Minecraft Folder
struct stat obj; struct stat obj;

View File

@ -6,9 +6,9 @@ set -e
rm -rf out rm -rf out
# Build # Build
./scripts/build.sh native client ./scripts/build.sh client x86_64
./scripts/build.sh native server ./scripts/build.sh server x86_64
./scripts/build.sh arm64 client ./scripts/build.sh client arm64
./scripts/build.sh arm64 server ./scripts/build.sh server arm64
./scripts/build.sh arm client ./scripts/build.sh client arm
./scripts/build.sh arm server ./scripts/build.sh server arm

View File

@ -2,21 +2,22 @@
set -e set -e
# This Script Assumes An x86_64 Host # Build
if [ "$(uname -m)" != "x86_64" ]; then build() {
echo 'Invalid Host Architecture' > /dev/stderr # Find Toolchain
local toolchain_file="$(pwd)/cmake/$2-toolchain.cmake"
if [ ! -f "${toolchain_file}" ]; then
echo "Invalid Architecture: $1" > /dev/stderr
exit 1 exit 1
fi fi
# Build For x86_64
native_build() {
# Create Build Dir # Create Build Dir
rm -rf build/$1-x86_64 rm -rf "build/$1-$2"
mkdir -p build/$1-x86_64 mkdir -p "build/$1-$2"
cd build/$1-x86_64 cd "build/$1-$2"
# Create Prefix # Create Prefix
local prefix="$(cd ../../; pwd)/out/$1-x86_64" local prefix="$(cd ../../; pwd)/out/$1-$2"
rm -rf "${prefix}" rm -rf "${prefix}"
mkdir -p "${prefix}" mkdir -p "${prefix}"
@ -37,45 +38,7 @@ native_build() {
# Build Native Components # Build Native Components
mkdir native mkdir native
cd native cd native
cmake -DMCPI_BUILD_MODE=native "${extra_arg}" ../../.. cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native "${extra_arg}" ../../..
make -j$(nproc)
make install DESTDIR="${prefix}"
cd ../
# Exit
cd ../../
}
# Build For ARM64
arm64_build() {
# Create Build Dir
rm -rf build/$1-arm64
mkdir -p build/$1-arm64
cd build/$1-arm64
# Create Prefix
local prefix="$(cd ../../; pwd)/out/$1-arm64"
rm -rf "${prefix}"
mkdir -p "${prefix}"
# Prepare
local extra_arg='-DMCPI_USE_MEDIA_LAYER_PROXY=ON'
if [ "$1" = "server" ]; then
extra_arg='-DMCPI_SERVER_MODE=ON'
fi
# Build ARM Components
mkdir arm
cd arm
cmake -DMCPI_BUILD_MODE=arm "${extra_arg}" ../../..
make -j$(nproc)
make install DESTDIR="${prefix}"
cd ../
# Build Native Components
mkdir native
cd native
cmake -DCMAKE_TOOLCHAIN_FILE="$(cd ../../../; pwd)/cmake/arm64-toolchain.cmake" -DMCPI_BUILD_MODE=native "${extra_arg}" ../../..
make -j$(nproc) make -j$(nproc)
make install DESTDIR="${prefix}" make install DESTDIR="${prefix}"
cd ../ cd ../
@ -87,9 +50,9 @@ arm64_build() {
# Build For ARM # Build For ARM
arm_build() { arm_build() {
# Create Build Dir # Create Build Dir
rm -rf build/$1-arm rm -rf "build/$1-arm"
mkdir -p build/$1-arm mkdir -p "build/$1-arm"
cd build/$1-arm cd "build/$1-arm"
# Create Prefix # Create Prefix
local prefix="$(cd ../../; pwd)/out/$1-arm" local prefix="$(cd ../../; pwd)/out/$1-arm"
@ -112,19 +75,14 @@ arm_build() {
} }
# Verify Mode # Verify Mode
if [ "$2" != "client" ] && [ "$2" != "server" ]; then if [ "$1" != "client" ] && [ "$1" != "server" ]; then
echo "Invalid Mode: $2" > /dev/stderr echo "Invalid Mode: $2" > /dev/stderr
exit 1 exit 1
fi fi
# Build # Build
if [ "$1" = "native" ]; then if [ "$2" = "arm" ]; then
native_build "$2" arm_build "$1"
elif [ "$1" = "arm64" ]; then
arm64_build "$2"
elif [ "$1" = "arm" ]; then
arm_build "$2"
else else
echo "Invalid Architecture: $1" > /dev/stderr build "$1" "$2"
exit 1
fi fi

View File

@ -26,7 +26,7 @@ package() {
# Find And Package # Find And Package
for dir in out/*; do for dir in out/*; do
# Check If Directory # Check If Directory Exists
if [ -d "${dir}" ]; then if [ -d "${dir}" ]; then
# Check If Debian Package Exists # Check If Debian Package Exists
pkg="$(basename ${dir})" pkg="$(basename ${dir})"