navid/haze / 90400c3cb2eb4f37a299a5eb96dbf6c3ad2fda3fc79b7a824ce800f18386f55d / 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")