if(NOT DEFINED INPUT OR NOT DEFINED OUTPUT OR NOT DEFINED SYMBOL) message(FATAL_ERROR "embed_spirv.cmake requires INPUT, OUTPUT, and SYMBOL") endif() file(READ "${INPUT}" bytes HEX) string(LENGTH "${bytes}" length) math(EXPR remainder "${length} % 8") if(NOT remainder EQUAL 0) message(FATAL_ERROR "SPIR-V byte count is not a multiple of four: ${INPUT}") endif() set(contents "#pragma once\n#include \ninline constexpr uint32_t ${SYMBOL}[] = {\n") set(column 0) while(length GREATER 0) string(SUBSTRING "${bytes}" 0 8 word) string(SUBSTRING "${word}" 0 2 b0) string(SUBSTRING "${word}" 2 2 b1) string(SUBSTRING "${word}" 4 2 b2) string(SUBSTRING "${word}" 6 2 b3) string(APPEND contents "0x${b3}${b2}${b1}${b0}u,") math(EXPR column "${column} + 1") if(column EQUAL 8) string(APPEND contents "\n") set(column 0) endif() string(SUBSTRING "${bytes}" 8 -1 bytes) math(EXPR length "${length} - 8") endwhile() string(APPEND contents "\n};\n") file(WRITE "${OUTPUT}" "${contents}")