build: embed ui.toml and banlist with INCBIN instead of a configure loop

ui.toml and the default banlist were embedded by a CMake function that
read each file and emitted a C array header one byte at a time in a
configure-time loop. That is slow to configure, and because the result
is a header, editing either resource recompiled every translation unit
that included it.

- Both files are now embedded with INCBIN from a small generated
  translation unit, the same pattern already used for the fonts. There
  is no generated header, so editing a resource re-assembles one tiny
  object file instead of triggering a wide recompile, and configure does
  no per-byte work.
- Consumers include a hand-written header declaring the symbols and
  always use the embedded data (the __has_include fallback is gone). The
  data is not NUL-terminated, so every consumer passes an explicit size.
- The old EmbedResources.cmake script is removed, and the generated unit
  is added to the app and test builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 22:03:00 -05:00
co-authored by Claude Opus 4.8
parent 3fd52fbdaf
commit e77b960cc5
7 changed files with 41 additions and 99 deletions
-42
View File
@@ -1,42 +0,0 @@
# CMake script to embed binary files as C arrays
function(embed_resource RESOURCE_FILE OUTPUT_FILE VAR_NAME)
file(READ "${RESOURCE_FILE}" HEX_CONTENT HEX)
# Convert hex to C array format
string(LENGTH "${HEX_CONTENT}" HEX_LENGTH)
math(EXPR BYTE_COUNT "${HEX_LENGTH} / 2")
set(ARRAY_CONTENT "")
set(INDEX 0)
while(INDEX LESS HEX_LENGTH)
string(SUBSTRING "${HEX_CONTENT}" ${INDEX} 2 BYTE)
string(APPEND ARRAY_CONTENT "0x${BYTE},")
math(EXPR INDEX "${INDEX} + 2")
math(EXPR BYTE_NUM "${INDEX} / 2")
math(EXPR MOD "${BYTE_NUM} % 16")
if(MOD EQUAL 0)
string(APPEND ARRAY_CONTENT "\n ")
endif()
endwhile()
# Generate header file
set(HEADER_CONTENT "// Auto-generated embedded resource - DO NOT EDIT
#pragma once
#include <cstddef>
#include <cstdint>
namespace embedded {
inline constexpr unsigned char ${VAR_NAME}_data[] = {
${ARRAY_CONTENT}
};
inline constexpr size_t ${VAR_NAME}_size = ${BYTE_COUNT};
} // namespace embedded
")
file(WRITE "${OUTPUT_FILE}" "${HEADER_CONTENT}")
message(STATUS "Embedded ${RESOURCE_FILE} -> ${OUTPUT_FILE} (${BYTE_COUNT} bytes)")
endfunction()