2018-11-18 18:35:03 -08:00
|
|
|
# Parameters: input output prefix namespace
|
2023-11-30 19:52:21 -05:00
|
|
|
file(READ ${input} fileHex HEX)
|
|
|
|
|
string(LENGTH "${fileHex}" fileHexSize)
|
|
|
|
|
math(EXPR fileSize "${fileHexSize} / 2")
|
2018-11-18 18:35:03 -08:00
|
|
|
|
2023-11-30 19:52:21 -05:00
|
|
|
get_filename_component(inputBase ${input} NAME)
|
|
|
|
|
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" funcName "${inputBase}")
|
|
|
|
|
set(funcName "GetResource_${funcName}")
|
2018-11-18 18:35:03 -08:00
|
|
|
|
2023-11-30 19:52:21 -05:00
|
|
|
file(
|
2026-03-13 13:15:01 -07:00
|
|
|
WRITE "${output}"
|
2023-11-30 19:52:21 -05:00
|
|
|
"#include <stddef.h>\n#include <string_view>\nextern \"C\" {\nstatic const unsigned char contents[] = {"
|
|
|
|
|
)
|
2018-11-18 18:35:03 -08:00
|
|
|
|
2023-11-30 19:52:21 -05:00
|
|
|
string(REGEX MATCHALL ".." outputData "${fileHex}")
|
|
|
|
|
string(REGEX REPLACE ";" ", 0x" outputData "${outputData}")
|
|
|
|
|
file(APPEND "${output}" " 0x${outputData} };\n")
|
|
|
|
|
file(
|
2026-03-13 13:15:01 -07:00
|
|
|
APPEND "${output}"
|
2023-11-30 19:52:21 -05:00
|
|
|
"const unsigned char* ${prefix}${funcName}(size_t* len) {\n *len = ${fileSize};\n return contents;\n}\n}\n"
|
|
|
|
|
)
|
2018-11-18 18:35:03 -08:00
|
|
|
|
2023-11-30 19:52:21 -05:00
|
|
|
if(NOT namespace STREQUAL "")
|
|
|
|
|
file(APPEND "${output}" "namespace ${namespace} {\n")
|
|
|
|
|
endif()
|
|
|
|
|
file(
|
2026-03-13 13:15:01 -07:00
|
|
|
APPEND "${output}"
|
2023-11-30 19:52:21 -05:00
|
|
|
"std::string_view ${funcName}() {\n return std::string_view(reinterpret_cast<const char*>(contents), ${fileSize});\n}\n"
|
|
|
|
|
)
|
|
|
|
|
if(NOT namespace STREQUAL "")
|
|
|
|
|
file(APPEND "${output}" "}\n")
|
|
|
|
|
endif()
|