Improve Build System
All checks were successful
minecraft-pi-reborn/pipeline/head This commit looks good

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,13 +25,11 @@ else()
endif()
# Use Clang By Default
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "clang")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "clang++")
endif()
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "clang")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "clang++")
endif()
# Setup ARM Cross Compilation
@ -39,12 +37,6 @@ if(USE_ARM32_TOOLCHAIN)
include(cmake/arm-toolchain.cmake)
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
include(cmake/util.cmake)
@ -92,6 +84,11 @@ add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_STANDARD 99)
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
if(MCPI_SERVER_MODE)
add_definitions(-DMCPI_SERVER_MODE)

View File

@ -1,8 +1,8 @@
# 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
add_compile_options("-m32")
elseif(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
elseif(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm")
# Use ARM Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("arm-linux-gnueabihf")

View File

@ -1,5 +1,5 @@
# 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
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
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
{
char *minecraft_folder = NULL;
asprintf(&minecraft_folder, "%s/.minecraft-pi", getenv("HOME"));
ALLOC_CHECK(minecraft_folder);
safe_asprintf(&minecraft_folder, "%s/.minecraft-pi", getenv("HOME"));
{
// Check Minecraft Folder
struct stat obj;

View File

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

View File

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

View File

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