FWIW, it’s possible to implement this purely in CMake, based on the string(HEX)
command. This works for me:
function(xxd outVar text)
string(HEX "${text}" hex)
string(LENGTH ${hex} hexLen)
math(EXPR hexLen "${hexLen} - 1")
set(result "")
foreach(idx RANGE 0 ${hexLen} 2)
string(SUBSTRING ${hex} ${idx} 2 char)
list(APPEND result "0x${char}")
endforeach()
list(JOIN result ", " result)
set(${outVar} ${result} PARENT_SCOPE)
endfunction()