minecraft-pi-reborn/CMakeLists.txt

176 lines
4.7 KiB
CMake
Raw Normal View History

2024-01-16 08:08:34 +00:00
cmake_minimum_required(VERSION 3.17.0)
2021-06-17 21:32:24 +00:00
2022-09-26 00:56:45 +00:00
# Avoid Warning About DOWNLOAD_EXTRACT_TIMESTAMP
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0)
cmake_policy(SET CMP0135 NEW)
endif()
2024-01-16 06:45:52 +00:00
# Core Options
2024-01-20 07:10:18 +00:00
include(cmake/options/core-options.cmake)
2022-07-07 04:37:53 +00:00
2022-03-11 05:00:13 +00:00
# Build Mode
2024-02-04 02:07:53 +00:00
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
2021-06-17 21:32:24 +00:00
endif()
# Start Project
project(minecraft-pi-reborn)
2022-07-07 22:55:43 +00:00
# Utility Functions
2024-01-20 07:10:18 +00:00
include(cmake/util/util.cmake)
2022-07-07 22:55:43 +00:00
# Sanity Checks
2023-11-09 23:41:10 +00:00
string(CONCAT ARM_SANITY_CHECK
2024-01-16 06:45:52 +00:00
"include(CheckSymbolExists)\n"
2024-01-20 07:10:18 +00:00
"check_symbol_exists(\"__arm__\" \"\" IS_ARM_TARGETING)"
2023-11-09 23:41:10 +00:00
)
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-06 00:08:13 +00:00
endif()
2023-11-09 23:41:10 +00:00
cmake_language(EVAL CODE "${ARM_SANITY_CHECK}")
2021-12-17 23:19:23 +00:00
2024-01-16 06:45:52 +00:00
# Extra Options
2024-01-20 07:10:18 +00:00
include(cmake/options/extra-options.cmake)
2024-01-16 06:45:52 +00:00
2024-01-20 07:10:18 +00:00
# Paths
include(cmake/options/paths.cmake)
2021-06-17 21:32:24 +00:00
2022-08-01 23:56:35 +00:00
# Required Compile Flags
string(CONCAT COMPILE_FLAGS_SETUP
# Optimizations
"if(CMAKE_BUILD_TYPE STREQUAL \"Release\")\n"
2024-02-12 01:35:41 +00:00
" add_compile_options(-O3)\n"
" add_link_options(-s)\n"
2022-08-01 23:56:35 +00:00
"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"
2024-07-14 09:06:27 +00:00
"set(CMAKE_CXX_STANDARD 20)\n"
2022-08-01 23:56:35 +00:00
# Skip RPath
"set(CMAKE_SKIP_BUILD_RPATH TRUE)"
)
cmake_language(EVAL CODE "${COMPILE_FLAGS_SETUP}")
2022-03-11 05:00:13 +00:00
2022-08-03 17:08:20 +00:00
# Fast Math
add_compile_options(-ffast-math)
# Warnings
add_compile_options(-Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference)
2024-01-23 23:20:14 +00:00
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
2022-08-03 17:08:20 +00:00
# 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-10 02:23:41 +00:00
# Buld Dependencies
add_subdirectory(dependencies)
2021-06-17 21:32:24 +00: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-12 03:18:12 +00:00
# Include Symbols
if(BUILD_ARM_COMPONENTS)
add_subdirectory(symbols)
endif()
2021-06-17 21:32:24 +00:00
# Build Mods
if(BUILD_ARM_COMPONENTS)
add_subdirectory(mods)
endif()
2022-04-22 23:38:15 +00:00
# Include Images
if(BUILD_NATIVE_COMPONENTS)
add_subdirectory(images)
endif()
2022-06-25 21:30:08 +00:00
2024-01-16 06:45:52 +00:00
# Install Prebuilt ARMHF Toolchain Sysroot
2024-05-09 05:38:57 +00:00
if(BUILD_NATIVE_COMPONENTS AND MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
2024-01-16 06:45:52 +00:00
install_arm_sysroot()
endif()
2022-06-25 21:30:08 +00:00
# Install SDK
if(BUILD_ARM_COMPONENTS)
2022-08-01 23:56:35 +00:00
install(EXPORT sdk DESTINATION "${MCPI_SDK_DIR}" FILE "sdk-targets.cmake" EXPORT_LINK_INTERFACE_LIBRARIES)
2022-08-09 22:38:48 +00:00
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdk.cmake"
2022-08-01 23:56:35 +00:00
# Compile Flags
"${COMPILE_FLAGS_SETUP}\n"
2023-11-09 23:41:10 +00:00
# Snaity Check
"${ARM_SANITY_CHECK}\n"
2022-08-01 23:56:35 +00: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 21:30:08 +00:00
endif()
2024-01-20 07:10:18 +00:00
# Packaging
if(BUILD_NATIVE_COMPONENTS)
include(cmake/cpack/packaging.cmake)
endif()
# Superbuild
if(BUILD_NATIVE_COMPONENTS)
include(ExternalProject)
# Arguments
set(ARM_OPTIONS "${MCPI_OPTIONS}")
list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm")
list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER")
2024-05-10 22:58:39 +00:00
list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>")
2024-01-20 07:10:18 +00:00
if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}")
endif()
else()
2024-05-09 05:38:57 +00:00
list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${MCPI_CMAKE_TOOLCHAIN_FILE}")
2024-01-20 07:10:18 +00:00
endif()
2024-02-12 01:35:41 +00:00
list(APPEND ARM_OPTIONS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}")
2024-01-20 07:10:18 +00:00
# Build
ExternalProject_Add(arm-components
DOWNLOAD_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
CMAKE_CACHE_ARGS ${ARM_OPTIONS}
2024-05-10 22:58:39 +00:00
INSTALL_COMMAND
"${CMAKE_COMMAND}" "-E"
"rm" "-rf" "<INSTALL_DIR>/${MCPI_INSTALL_DIR}"
2024-01-20 07:10:18 +00:00
COMMAND
"${CMAKE_COMMAND}" "-E" "env"
"DESTDIR="
"${CMAKE_COMMAND}" "--install" "<BINARY_DIR>"
USES_TERMINAL_CONFIGURE TRUE
USES_TERMINAL_BUILD TRUE
USES_TERMINAL_INSTALL TRUE
BUILD_ALWAYS TRUE
)
# Install
ExternalProject_Get_Property(arm-components INSTALL_DIR)
2024-05-10 22:58:39 +00:00
install(DIRECTORY "${INSTALL_DIR}/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}")
2024-01-20 07:10:18 +00:00
endif()