navid/haze / ac578357f89bfff0d2087db83762869fe1d638168c4f02a75aeafcd8f45cc5de / cmake/embed_runtime.cmake
embed_runtime.cmake
← cmake · 811 bytes · raw · download
# Generate a C++ source file containing the runtime archive as a byte array.
# Invoked from CMakeLists.txt as a build-time script.
if(NOT DEFINED INPUT OR NOT DEFINED OUTPUT)
message(FATAL_ERROR "embed_runtime.cmake requires INPUT and OUTPUT")
endif()
file(SIZE "${INPUT}" archive_size)
file(READ "${INPUT}" archive_hex HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," archive_bytes "${archive_hex}")
string(REGEX REPLACE "((0x[0-9a-f][0-9a-f],){16})" "\\1\n" archive_bytes "${archive_bytes}")
file(WRITE "${OUTPUT}" "extern \"C\" const unsigned char haze_embedded_runtime_archive[] = {\n")
file(APPEND "${OUTPUT}" "${archive_bytes}\n")
file(APPEND "${OUTPUT}" "};\n")
file(APPEND "${OUTPUT}"
"extern \"C\" const unsigned long long haze_embedded_runtime_archive_size = ${archive_size}ull;\n")