From 513628d91f264e44eb40da6f4ed52c391254e614 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 5 Aug 2022 20:08:13 -0400 Subject: [PATCH] More CMake Tweaks --- .gitignore | 1 - CMakeLists.txt | 8 +++- cmake/embed-resource.cmake | 12 ++++++ cmake/prebuilt-armhf-toolchain.cmake | 42 +++++++++++++------ cmake/util.cmake | 19 ++++----- dependencies/zenity/src | 2 +- example-mods/README.md | 2 +- media-layer/core/gles/CMakeLists.txt | 4 +- .../core/gles/src/compatibility-layer/draw.c | 10 ++--- .../shaders/{main.frag => main.fsh} | 0 .../shaders/{main.vert => main.vsh} | 0 11 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 cmake/embed-resource.cmake rename media-layer/core/gles/src/compatibility-layer/shaders/{main.frag => main.fsh} (100%) rename media-layer/core/gles/src/compatibility-layer/shaders/{main.vert => main.vsh} (100%) diff --git a/.gitignore b/.gitignore index 98e233ca..05aa6e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ /*.AppImage /core* /qemu_* -/cmake/.prebuilt-armhf-toolchain diff --git a/CMakeLists.txt b/CMakeLists.txt index 28d296e9..12d6b8a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,10 +99,14 @@ project(minecraft-pi-reborn) include(cmake/util.cmake) # 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.") 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") endif() diff --git a/cmake/embed-resource.cmake b/cmake/embed-resource.cmake new file mode 100644 index 00000000..63379f05 --- /dev/null +++ b/cmake/embed-resource.cmake @@ -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 \nconst unsigned char ${name}[] = {${data}};\nconst size_t ${name}_len = sizeof (${name});\n") diff --git a/cmake/prebuilt-armhf-toolchain.cmake b/cmake/prebuilt-armhf-toolchain.cmake index 955a9f4e..fdb83ca1 100644 --- a/cmake/prebuilt-armhf-toolchain.cmake +++ b/cmake/prebuilt-armhf-toolchain.cmake @@ -9,20 +9,32 @@ set(CMAKE_SYSTEM_NAME "Linux") set(CMAKE_SYSTEM_PROCESSOR "arm") unset(CMAKE_TOOLCHAIN_FILE CACHE) +# Pick URL +execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE) +if(arch STREQUAL "x86_64") + set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf.tar.xz") + set(toolchain_sha256 "aa074fa8371a4f73fecbd16bd62c8b1945f23289e26414794f130d6ccdf8e39c") +elseif(arch STREQUAL "aarch64" OR arch STREQUAL "armv8b" OR arch STREQUAL "armv8l") + set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-linux-gnueabihf.tar.xz") + set(toolchain_sha256 "fccd7af76988da2b077f939eb2a78baa9935810918d2bf3f837bc74f52efa825") +else() + message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain") +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}") - # Pick URL - execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE) - if(arch STREQUAL "x86_64") - set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf.tar.xz") - set(toolchain_sha256 "aa074fa8371a4f73fecbd16bd62c8b1945f23289e26414794f130d6ccdf8e39c") - elseif(arch STREQUAL "aarch64" OR arch STREQUAL "armv8b" OR arch STREQUAL "armv8l") - set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-arm-none-linux-gnueabihf.tar.xz") - set(toolchain_sha256 "fccd7af76988da2b077f939eb2a78baa9935810918d2bf3f837bc74f52efa825") - else() - message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain") - endif() - # Download message(STATUS "Downloading Prebuilt ARMHF Toolchain...") file(REMOVE_RECURSE "${toolchain_dir}") @@ -36,6 +48,12 @@ if(NOT EXISTS "${CMAKE_C_COMPILER}") ) 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 file(REMOVE_RECURSE "${sysroot_dir}") endif() diff --git a/cmake/util.cmake b/cmake/util.cmake index 10e9ae2a..20d4f71e 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -10,22 +10,17 @@ function(install_symlink target link) endfunction() # Embed Resources +set(util_list_dir "${CMAKE_CURRENT_LIST_DIR}") 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_filename_component(name "${file}" NAME) string(MAKE_C_IDENTIFIER "${name}" name) - # Write Data - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" "#include \nconst unsigned char ${name}[] = {${data}};\nconst size_t ${name}_len = sizeof (${name});\n") + # Add Command + 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 target_sources("${target}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") - # Mark Dependency - set_property( - DIRECTORY - APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS "${file}" - ) endfunction() diff --git a/dependencies/zenity/src b/dependencies/zenity/src index d673e9aa..7dc886e7 160000 --- a/dependencies/zenity/src +++ b/dependencies/zenity/src @@ -1 +1 @@ -Subproject commit d673e9aab842d7151d92eb9164872dc05e748db2 +Subproject commit 7dc886e7d217bb2ecaa2d771e08443b92c36fe28 diff --git a/example-mods/README.md b/example-mods/README.md index 926f6126..223da960 100644 --- a/example-mods/README.md +++ b/example-mods/README.md @@ -1,5 +1,5 @@ # 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). * **Chat Commands Mod**: This specific mod makes an chat message starting with a ``/`` handled by the MCPI API. diff --git a/media-layer/core/gles/CMakeLists.txt b/media-layer/core/gles/CMakeLists.txt index 3f17dcb9..881623bf 100644 --- a/media-layer/core/gles/CMakeLists.txt +++ b/media-layer/core/gles/CMakeLists.txt @@ -16,8 +16,8 @@ if(NOT MCPI_HEADLESS_MODE) target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m) # Shaders 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.frag) + embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.vsh) + embed_resource(GLESv1_CM src/compatibility-layer/shaders/main.fsh) endif() endif() diff --git a/media-layer/core/gles/src/compatibility-layer/draw.c b/media-layer/core/gles/src/compatibility-layer/draw.c index 68b4b5ec..336498c1 100644 --- a/media-layer/core/gles/src/compatibility-layer/draw.c +++ b/media-layer/core/gles/src/compatibility-layer/draw.c @@ -78,14 +78,14 @@ static GLuint compile_shader(const char *vertex_shader_text, const int vertex_sh } // Shader -extern unsigned char main_vert[]; -extern size_t main_vert_len; -extern unsigned char main_frag[]; -extern size_t main_frag_len; +extern unsigned char main_vsh[]; +extern size_t main_vsh_len; +extern unsigned char main_fsh[]; +extern size_t main_fsh_len; static GLuint get_shader() { static GLuint 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; } diff --git a/media-layer/core/gles/src/compatibility-layer/shaders/main.frag b/media-layer/core/gles/src/compatibility-layer/shaders/main.fsh similarity index 100% rename from media-layer/core/gles/src/compatibility-layer/shaders/main.frag rename to media-layer/core/gles/src/compatibility-layer/shaders/main.fsh diff --git a/media-layer/core/gles/src/compatibility-layer/shaders/main.vert b/media-layer/core/gles/src/compatibility-layer/shaders/main.vsh similarity index 100% rename from media-layer/core/gles/src/compatibility-layer/shaders/main.vert rename to media-layer/core/gles/src/compatibility-layer/shaders/main.vsh