mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-11-23 01:44:35 +08:00
fe590801a1
Use CMake to read file and convert to C array of hex values
17 lines
530 B
CMake
17 lines
530 B
CMake
function(file_to_hex_array FILE DATA)
|
|
# Read the ASCII file as hex.
|
|
file(READ "${FILE}" HEX_CONTENTS HEX)
|
|
|
|
# Separate into individual bytes.
|
|
string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" SEPARATED_HEX "${HEX_CONTENTS}")
|
|
|
|
# Append the "0x" to each byte.
|
|
list(JOIN SEPARATED_HEX ", 0x" FORMATTED_HEX)
|
|
|
|
# JOIN misses the first byte's "0x", so add it here.
|
|
string(PREPEND FORMATTED_HEX "0x")
|
|
|
|
# Set the variable named by DATA argument to the formatted hex string.
|
|
set(${DATA} ${FORMATTED_HEX} PARENT_SCOPE)
|
|
endfunction()
|