minecraft-pi-reborn/CMakeLists.txt

241 lines
7.1 KiB
CMake
Raw Normal View History

2022-06-09 21:31:40 -04:00
cmake_minimum_required(VERSION 3.16.0)
2021-06-17 17:32:24 -04:00
2022-09-25 20:56:45 -04:00
# Avoid Warning About DOWNLOAD_EXTRACT_TIMESTAMP
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0)
cmake_policy(SET CMP0135 NEW)
endif()
# Build Mode
2022-07-02 18:14:23 -04:00
set(MCPI_BUILD_MODE "native" CACHE STRING "\"arm\" = Build Only Code That Must Be ARM; \"native\" = Build Architecture-Independent Code")
set_property(CACHE MCPI_BUILD_MODE PROPERTY STRINGS "arm" "native")
if(MCPI_BUILD_MODE STREQUAL "arm")
set(BUILD_ARM_COMPONENTS TRUE)
set(BUILD_NATIVE_COMPONENTS FALSE)
elseif(MCPI_BUILD_MODE STREQUAL "native")
set(BUILD_ARM_COMPONENTS FALSE)
set(BUILD_NATIVE_COMPONENTS TRUE)
else()
message(FATAL_ERROR "Invalid Mode")
endif()
# Specify Options
option(MCPI_IS_MIXED_BUILD "Whether The Architecture-Independent And ARM Code Are Different Architecture" FALSE)
2022-06-09 21:31:40 -04:00
option(MCPI_OPEN_SOURCE_ONLY "Only Install Open-Source Code (Will Result In Broken Install)" FALSE)
option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE)
2023-11-24 03:28:17 -05:00
option(MCPI_IS_FLATPAK_BUILD "Flatpak Build" FALSE)
2022-07-07 00:37:53 -04:00
2022-06-09 21:31:40 -04:00
# Server/Headless Builds
2021-06-17 17:32:24 -04:00
option(MCPI_SERVER_MODE "Server Mode" FALSE)
2021-08-26 22:52:18 -04:00
option(MCPI_HEADLESS_MODE "Headless Mode" ${MCPI_SERVER_MODE})
2022-07-07 00:37:53 -04:00
2022-06-09 21:31:40 -04:00
# Media Layer
if(MCPI_HEADLESS_MODE)
set(DEFAULT_USE_MEDIA_LAYER_PROXY FALSE)
else()
set(DEFAULT_USE_MEDIA_LAYER_PROXY ${MCPI_IS_MIXED_BUILD})
endif()
option(MCPI_USE_MEDIA_LAYER_PROXY "Whether To Enable The Media Layer Proxy" ${DEFAULT_USE_MEDIA_LAYER_PROXY})
if(NOT MCPI_HEADLESS_MODE)
option(MCPI_USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" TRUE)
endif()
2023-11-11 00:44:26 -05:00
if(MCPI_USE_MEDIA_LAYER_PROXY)
set(BUILD_MEDIA_LAYER_CORE "${BUILD_NATIVE_COMPONENTS}")
else()
set(BUILD_MEDIA_LAYER_CORE "${BUILD_ARM_COMPONENTS}")
endif()
2022-07-07 00:37:53 -04:00
2022-06-09 21:31:40 -04:00
# App ID
set(DEFAULT_APP_ID "com.thebrokenrail.MCPIReborn")
if(MCPI_SERVER_MODE)
string(APPEND DEFAULT_APP_ID "Server")
else()
string(APPEND DEFAULT_APP_ID "Client")
endif()
set(MCPI_APP_ID "${DEFAULT_APP_ID}" CACHE STRING "App ID")
2022-07-07 00:37:53 -04:00
2022-06-09 21:31:40 -04:00
# App Title
2022-10-01 19:29:11 -04:00
set(MCPI_APP_BASE_TITLE "Minecraft: Pi Edition: Reborn" CACHE STRING "Base App Title")
set(DEFAULT_APP_TITLE "${MCPI_APP_BASE_TITLE}")
2022-06-09 21:31:40 -04:00
if(MCPI_SERVER_MODE)
string(APPEND DEFAULT_APP_TITLE " (Server)")
else()
string(APPEND DEFAULT_APP_TITLE " (Client)")
endif()
set(MCPI_APP_TITLE "${DEFAULT_APP_TITLE}" CACHE STRING "App Title")
2021-06-17 17:32:24 -04:00
# Specify Variant Name
set(MCPI_VARIANT_NAME "minecraft-pi-reborn")
if(MCPI_SERVER_MODE)
2022-06-09 21:31:40 -04:00
string(APPEND MCPI_VARIANT_NAME "-server")
2021-06-17 17:32:24 -04:00
else()
2022-06-09 21:31:40 -04:00
string(APPEND MCPI_VARIANT_NAME "-client")
2021-06-17 17:32:24 -04:00
endif()
2023-10-19 01:23:34 -04:00
# Skin Server
2023-10-19 20:53:38 -04:00
set(MCPI_SKIN_SERVER "https://raw.githubusercontent.com/MCPI-Revival/Skins/data" CACHE STRING "Skin Server")
2023-10-19 01:23:34 -04:00
2021-06-17 17:32:24 -04:00
# Specify Installation Paths
2021-12-17 19:07:58 -05:00
set(MCPI_INSTALL_DIR "lib/${MCPI_VARIANT_NAME}")
2022-03-11 20:02:38 -05:00
set(MCPI_BIN_DIR "${MCPI_INSTALL_DIR}/bin")
2022-07-13 16:46:33 -04:00
set(MCPI_LEGAL_DIR "${MCPI_INSTALL_DIR}/legal") # For Software Licenses
2022-06-25 17:30:08 -04:00
set(MCPI_SDK_DIR "${MCPI_INSTALL_DIR}/sdk")
set(MCPI_SDK_LIB_DIR "${MCPI_SDK_DIR}/lib")
set(MCPI_SDK_INCLUDE_DIR "${MCPI_SDK_DIR}/include")
2021-06-17 17:32:24 -04:00
2022-07-02 18:14:23 -04:00
# Library Directory
set(MCPI_LIB_DIR "${MCPI_INSTALL_DIR}/lib")
if(BUILD_ARM_COMPONENTS)
string(APPEND MCPI_LIB_DIR "/arm")
elseif(BUILD_NATIVE_COMPONENTS)
string(APPEND MCPI_LIB_DIR "/native")
endif()
2022-07-07 00:37:53 -04:00
# Share Directory
set(MCPI_SHARE_DIR "share")
if(MCPI_IS_APPIMAGE_BUILD)
string(PREPEND MCPI_SHARE_DIR "usr/")
endif()
2022-03-11 00:00:13 -05:00
# Build Mode
2021-06-17 17:32:24 -04:00
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Prebuilt ARMHF Toolchain
option(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN "Whether To Use A Prebuilt ARMHF Toolchain For Building ARM Components" ${MCPI_IS_MIXED_BUILD})
2022-07-07 18:54:11 -04:00
if(BUILD_ARM_COMPONENTS AND MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
include(cmake/prebuilt-armhf-toolchain.cmake)
endif()
2021-06-17 17:32:24 -04:00
# Start Project
project(minecraft-pi-reborn)
2022-07-07 18:55:43 -04:00
# Utility Functions
include(cmake/util.cmake)
# Sanity Checks
2023-11-09 18:41:10 -05:00
string(CONCAT ARM_SANITY_CHECK
"set(IS_ARM_TARGETING FALSE)\n"
"if(CMAKE_SYSTEM_PROCESSOR STREQUAL \"arm\" OR CMAKE_SYSTEM_PROCESSOR STREQUAL \"armv7l\")\n"
" set(IS_ARM_TARGETING TRUE)\n"
"endif()"
)
if(BUILD_ARM_COMPONENTS)
string(CONCAT ARM_SANITY_CHECK
"${ARM_SANITY_CHECK}\n"
"if(NOT IS_ARM_TARGETING)\n"
" message(FATAL_ERROR \"ARM-Targeting Compiler Required\")\n"
"endif()"
)
2022-08-05 20:08:13 -04:00
endif()
2023-11-09 18:41:10 -05:00
cmake_language(EVAL CODE "${ARM_SANITY_CHECK}")
2022-08-05 20:08:13 -04:00
if(BUILD_NATIVE_COMPONENTS AND NOT IS_ARM_TARGETING AND NOT MCPI_IS_MIXED_BUILD)
2022-05-11 18:24:03 -04:00
message(FATAL_ERROR "Project is configured as a mixed-buld, but MCPI_IS_MIXED_BUILD is disabled.")
endif()
2021-12-17 18:19:23 -05:00
2021-06-17 17:32:24 -04:00
# Specify Default Installation Prefix
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(DEFAULT_PREFIX "/usr")
if(MCPI_IS_APPIMAGE_BUILD)
set(DEFAULT_PREFIX "/")
2023-11-24 03:28:17 -05:00
elseif(MCPI_IS_FLATPAK_BUILD)
set(DEFAULT_PREFIX "/app")
endif()
set(CMAKE_INSTALL_PREFIX "${DEFAULT_PREFIX}" CACHE PATH "" FORCE)
2022-09-25 15:47:36 -04:00
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
2021-06-17 17:32:24 -04:00
endif()
2022-08-01 19:56:35 -04:00
# Required Compile Flags
string(CONCAT COMPILE_FLAGS_SETUP
# Optimizations
"if(CMAKE_BUILD_TYPE STREQUAL \"Release\")\n"
" add_compile_options(-O3 -s)\n"
"else()\n"
" add_compile_options(-g)\n"
"endif()\n"
# PIC
"set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)\n"
# Warnings
"add_link_options(-Wl,--no-undefined)\n"
# C Standard
"add_definitions(-D_GNU_SOURCE)\n"
"set(CMAKE_C_STANDARD 99)\n"
"set(CMAKE_CXX_STANDARD 11)\n"
# Skip RPath
"set(CMAKE_SKIP_BUILD_RPATH TRUE)"
)
cmake_language(EVAL CODE "${COMPILE_FLAGS_SETUP}")
2022-03-11 00:00:13 -05:00
2022-08-03 13:08:20 -04:00
# Fast Math
add_compile_options(-ffast-math)
# Warnings
add_compile_options(-Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference)
if(CMAKE_C_COMPILER_ID STREQUAL \"GNU\")
# Prevents False Positives
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 10.0)
add_compile_options(-Wno-stringop-overflow)
endif()
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 11.0)
add_compile_options(-Wno-array-bounds -Wno-stringop-overread)
endif()
endif()
2022-03-09 21:23:41 -05:00
# Buld Dependencies
add_subdirectory(dependencies)
2021-06-17 17:32:24 -04:00
2021-06-28 16:00:52 -04:00
# Version
2022-05-02 22:52:52 -04:00
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS VERSION
)
2022-06-09 21:31:40 -04:00
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" MCPI_VERSION)
file(TIMESTAMP "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" MCPI_VERSION_DATE "%Y-%m-%d" UTC)
2021-06-28 16:00:52 -04:00
2021-06-17 17:32:24 -04:00
# Build libreborn
add_subdirectory(libreborn)
# Build Media Layer
add_subdirectory(media-layer)
# Build Launcher
if(BUILD_NATIVE_COMPONENTS)
add_subdirectory(launcher)
endif()
2021-09-11 23:18:12 -04:00
# Include Symbols
if(BUILD_ARM_COMPONENTS)
add_subdirectory(symbols)
endif()
2021-06-17 17:32:24 -04:00
# Build Mods
if(BUILD_ARM_COMPONENTS)
add_subdirectory(mods)
endif()
2022-04-22 19:38:15 -04:00
# Include Images
if(BUILD_NATIVE_COMPONENTS)
add_subdirectory(images)
endif()
2022-06-25 17:30:08 -04:00
# Install SDK
if(BUILD_ARM_COMPONENTS)
2022-08-01 19:56:35 -04:00
install(EXPORT sdk DESTINATION "${MCPI_SDK_DIR}" FILE "sdk-targets.cmake" EXPORT_LINK_INTERFACE_LIBRARIES)
2022-08-09 18:38:48 -04:00
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdk.cmake"
2022-08-01 19:56:35 -04:00
# Compile Flags
"${COMPILE_FLAGS_SETUP}\n"
2023-11-09 18:41:10 -05:00
# Snaity Check
"${ARM_SANITY_CHECK}\n"
2022-08-01 19:56:35 -04:00
# Log
"message(STATUS \"Using Reborn SDK v${MCPI_VERSION}\")\n"
# Include Targets
"include(\"\${CMAKE_CURRENT_LIST_DIR}/sdk-targets.cmake\")\n"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sdk.cmake" DESTINATION "${MCPI_SDK_DIR}")
2022-06-25 17:30:08 -04:00
endif()