Files
bongo/cmake/EmbedFile.cmake
T
2026-07-16 14:26:58 +02:00

19 lines
576 B
CMake

if(NOT DEFINED INPUT OR NOT DEFINED OUTPUT OR NOT DEFINED SYMBOL)
message(FATAL_ERROR "EmbedFile.cmake requires INPUT, OUTPUT and SYMBOL")
endif()
file(READ "${INPUT}" content HEX)
string(REGEX MATCHALL ".." bytes "${content}")
set(source "unsigned char ${SYMBOL}[] = {\n")
set(column 0)
foreach(byte IN LISTS bytes)
string(APPEND source "0x${byte},")
math(EXPR column "${column} + 1")
if(column EQUAL 16)
string(APPEND source "\n")
set(column 0)
endif()
endforeach()
string(APPEND source "0x00\n};\n")
file(WRITE "${OUTPUT}" "${source}")