More CMake Tweaks

This commit is contained in:
TheBrokenRail 2022-08-05 20:08:13 -04:00
parent 9a521ebca2
commit 513628d91f
11 changed files with 64 additions and 36 deletions

1
.gitignore vendored
View File

@ -12,4 +12,3 @@
/*.AppImage /*.AppImage
/core* /core*
/qemu_* /qemu_*
/cmake/.prebuilt-armhf-toolchain

View File

@ -99,10 +99,14 @@ project(minecraft-pi-reborn)
include(cmake/util.cmake) include(cmake/util.cmake)
# Sanity Checks # Sanity Checks
if(BUILD_NATIVE_COMPONENTS AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND NOT MCPI_IS_MIXED_BUILD) set(IS_ARM_TARGETING FALSE)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(IS_ARM_TARGETING TRUE)
endif()
if(BUILD_NATIVE_COMPONENTS AND NOT IS_ARM_TARGETING AND NOT MCPI_IS_MIXED_BUILD)
message(FATAL_ERROR "Project is configured as a mixed-buld, but MCPI_IS_MIXED_BUILD is disabled.") message(FATAL_ERROR "Project is configured as a mixed-buld, but MCPI_IS_MIXED_BUILD is disabled.")
endif() endif()
if(BUILD_ARM_COMPONENTS AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") if(BUILD_ARM_COMPONENTS AND NOT IS_ARM_TARGETING)
message(FATAL_ERROR "ARM-Targeting Compiler Required") message(FATAL_ERROR "ARM-Targeting Compiler Required")
endif() endif()

View File

@ -0,0 +1,12 @@
# Read Hex Data
file(READ "${EMBED_IN}" data HEX)
# Convert Hex Data For C Compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data "${data}")
# Get C Name
get_filename_component(name "${EMBED_IN}" NAME)
string(MAKE_C_IDENTIFIER "${name}" name)
# Write Data
file(WRITE "${EMBED_OUT}" "#include <stddef.h>\nconst unsigned char ${name}[] = {${data}};\nconst size_t ${name}_len = sizeof (${name});\n")

View File

@ -9,8 +9,6 @@ set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm") set(CMAKE_SYSTEM_PROCESSOR "arm")
unset(CMAKE_TOOLCHAIN_FILE CACHE) unset(CMAKE_TOOLCHAIN_FILE CACHE)
# Download If Needed
if(NOT EXISTS "${CMAKE_C_COMPILER}")
# Pick URL # Pick URL
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(arch STREQUAL "x86_64") if(arch STREQUAL "x86_64")
@ -23,6 +21,20 @@ if(NOT EXISTS "${CMAKE_C_COMPILER}")
message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain") message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain")
endif() endif()
# Check Toolchain
set(toolchain_valid FALSE)
if(EXISTS "${toolchain_dir}/.last_sha256")
file(STRINGS "${toolchain_dir}/.last_sha256" toolchain_last_sha256)
if(toolchain_last_sha256 STREQUAL toolchain_sha256)
set(toolchain_valid TRUE)
endif()
endif()
if(NOT toolchain_valid)
file(REMOVE_RECURSE "${toolchain_dir}")
endif()
# Download If Needed
if(NOT EXISTS "${CMAKE_C_COMPILER}")
# Download # Download
message(STATUS "Downloading Prebuilt ARMHF Toolchain...") message(STATUS "Downloading Prebuilt ARMHF Toolchain...")
file(REMOVE_RECURSE "${toolchain_dir}") file(REMOVE_RECURSE "${toolchain_dir}")
@ -36,6 +48,12 @@ if(NOT EXISTS "${CMAKE_C_COMPILER}")
) )
FetchContent_Populate(prebuilt-armhf-toolchain) FetchContent_Populate(prebuilt-armhf-toolchain)
# Write Last SHA256
file(WRITE "${toolchain_dir}/.last_sha256" "${toolchain_sha256}")
# Write .gitignore
file(WRITE "${toolchain_dir}/.gitignore" "/*\n")
# Force Sysroot Rebuild # Force Sysroot Rebuild
file(REMOVE_RECURSE "${sysroot_dir}") file(REMOVE_RECURSE "${sysroot_dir}")
endif() endif()

View File

@ -10,22 +10,17 @@ function(install_symlink target link)
endfunction() endfunction()
# Embed Resources # Embed Resources
set(util_list_dir "${CMAKE_CURRENT_LIST_DIR}")
function(embed_resource target file) function(embed_resource target file)
# Read Hex Data
file(READ "${file}" data HEX)
# Convert Hex Data For C Compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data "${data}")
# Get C Name # Get C Name
get_filename_component(name "${file}" NAME) get_filename_component(name "${file}" NAME)
string(MAKE_C_IDENTIFIER "${name}" name) string(MAKE_C_IDENTIFIER "${name}" name)
# Write Data # Add Command
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" "#include <stddef.h>\nconst unsigned char ${name}[] = {${data}};\nconst size_t ${name}_len = sizeof (${name});\n") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.c"
COMMAND "${CMAKE_COMMAND}"
ARGS "-DEMBED_IN=${CMAKE_CURRENT_SOURCE_DIR}/${file}" "-DEMBED_OUT=${CMAKE_CURRENT_BINARY_DIR}/${name}.c" "-P" "${util_list_dir}/embed-resource.cmake"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${file}" "${util_list_dir}/embed-resource.cmake"
)
# Add To Target # Add To Target
target_sources("${target}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") target_sources("${target}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c")
# Mark Dependency
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS "${file}"
)
endfunction() endfunction()

@ -1 +1 @@
Subproject commit d673e9aab842d7151d92eb9164872dc05e748db2 Subproject commit 7dc886e7d217bb2ecaa2d771e08443b92c36fe28

View File

@ -1,5 +1,5 @@
# Example Mods # Example Mods
This is an example of a mod that cane be built using the modding SDK. This is an example of a mod that can be built using the modding SDK.
* **Expanded Creative Mod**: This specific mod adds even more items and blocks to the Creative Inventory. It was originally by [@Bigjango13](https://github.com/bigjango13). * **Expanded Creative Mod**: This specific mod adds even more items and blocks to the Creative Inventory. It was originally by [@Bigjango13](https://github.com/bigjango13).
* **Chat Commands Mod**: This specific mod makes an chat message starting with a ``/`` handled by the MCPI API. * **Chat Commands Mod**: This specific mod makes an chat message starting with a ``/`` handled by the MCPI API.

View File

@ -16,8 +16,8 @@ if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m) target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m)
# Shaders # Shaders
if(MCPI_USE_GLES1_COMPATIBILITY_LAYER) if(MCPI_USE_GLES1_COMPATIBILITY_LAYER)
embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.vert) embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.vsh)
embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.frag) embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.fsh)
endif() endif()
endif() endif()

View File

@ -78,14 +78,14 @@ static GLuint compile_shader(const char *vertex_shader_text, const int vertex_sh
} }
// Shader // Shader
extern unsigned char main_vert[]; extern unsigned char main_vsh[];
extern size_t main_vert_len; extern size_t main_vsh_len;
extern unsigned char main_frag[]; extern unsigned char main_fsh[];
extern size_t main_frag_len; extern size_t main_fsh_len;
static GLuint get_shader() { static GLuint get_shader() {
static GLuint program = 0; static GLuint program = 0;
if (program == 0) { if (program == 0) {
program = compile_shader((const char *) main_vert, main_vert_len, (const char *) main_frag, main_frag_len); program = compile_shader((const char *) main_vsh, main_vsh_len, (const char *) main_fsh, main_fsh_len);
} }
return program; return program;
} }