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