diff options
author | Olivier Chafik <ochafik@users.noreply.github.com> | 2024-04-21 18:48:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-21 18:48:53 +0100 |
commit | 5cf5e7d490dfdd2e70bface2d35dfd14aa44b4fb (patch) | |
tree | 9af269d3fa30667bbaefc6978db94013d68b3f22 /scripts/xxd.cmake | |
parent | 40f74e4d739e9250431cf339ae7588b28d8d0663 (diff) |
`build`: generate hex dump of server assets during build (#6661)
* `build`: generate hex dumps of server assets on the fly
* build: workaround lack of -n on gnu xxd
* build: don't use xxd in cmake
* build: don't call xxd from build.zig
* build: more idiomatic hexing
* build: don't use xxd in Makefile (od hackery instead)
* build: avoid exceeding max cmd line limit in makefile hex dump
* build: hex dump assets at cmake build time (not config time)
Diffstat (limited to 'scripts/xxd.cmake')
-rw-r--r-- | scripts/xxd.cmake | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/scripts/xxd.cmake b/scripts/xxd.cmake new file mode 100644 index 00000000..f5ad6ab9 --- /dev/null +++ b/scripts/xxd.cmake @@ -0,0 +1,16 @@ +# CMake equivalent of `xxd -i ${INPUT} ${OUTPUT}` +# Usage: cmake -DINPUT=examples/server/public/index.html -DOUTPUT=examples/server/index.html.hpp -P scripts/xxd.cmake + +SET(INPUT "" CACHE STRING "Input File") +SET(OUTPUT "" CACHE STRING "Output File") + +get_filename_component(filename "${INPUT}" NAME) +string(REGEX REPLACE "\\.|-" "_" name "${filename}") + +file(READ "${INPUT}" hex_data HEX) +string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," hex_sequence "${hex_data}") + +string(LENGTH ${hex_data} hex_len) +math(EXPR len "${hex_len} / 2") + +file(WRITE "${OUTPUT}" "unsigned char ${name}[] = {${hex_sequence}};\nunsigned int ${name}_len = ${len};\n") |