From dd6d737a432fc8e12282fb2c28514213fd860334 Mon Sep 17 00:00:00 2001 From: bjorn Date: Thu, 9 Jan 2020 21:57:13 -0800 Subject: [PATCH] CMake: compile binary resources earlier; --- CMakeLists.txt | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0eb007..3c9deeac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,6 +297,25 @@ endif() # LÖVR +# Resources +file(GLOB LOVR_RESOURCES "src/resources/*.ttf" "src/resources/*.json" "src/resources/*.lua") +foreach(path ${LOVR_RESOURCES}) + + # Turn the absolute path into a C variable like src_resources_boot_lua + file(RELATIVE_PATH identifier ${CMAKE_CURRENT_SOURCE_DIR} ${path}) + string(MAKE_C_IDENTIFIER ${identifier} identifier) + + # Read the file and turn the bytes into comma-separated hex literals + file(READ ${path} data HEX) + string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data ${data}) + + # Generate the output filename by adding .h to the input filename + string(CONCAT output ${path} ".h") + + # Write some xxd-compatible C code! + file(WRITE ${output} "const unsigned char ${identifier}[] = {${data}};\nconst unsigned int ${identifier}_len = sizeof(${identifier});\n") +endforeach() + set(LOVR_SRC src/main.c src/core/arr.c @@ -590,22 +609,3 @@ elseif(UNIX) target_sources(lovr PRIVATE src/core/os_linux.c) target_compile_definitions(lovr PRIVATE -DLOVR_GL) endif() - -# Resources -file(GLOB LOVR_RESOURCES "src/resources/*.ttf" "src/resources/*.json" "src/resources/*.lua") -foreach(path ${LOVR_RESOURCES}) - - # Turn the absolute path into a C variable like src_resources_boot_lua - file(RELATIVE_PATH identifier ${CMAKE_CURRENT_SOURCE_DIR} ${path}) - string(MAKE_C_IDENTIFIER ${identifier} identifier) - - # Read the file and turn the bytes into comma-separated hex literals - file(READ ${path} data HEX) - string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," data ${data}) - - # Generate the output filename by adding .h to the input filename - string(CONCAT output ${path} ".h") - - # Write some xxd-compatible C code! - file(WRITE ${output} "const unsigned char ${identifier}[] = {${data}};\nconst unsigned int ${identifier}_len = sizeof(${identifier});\n") -endforeach()