diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index b0e6b936ce0..50bbab9eed9 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -725,3 +725,31 @@ macro(set_lib_path set(${lvar} ${LIBDIR}/${lproj}) endif() endmacro() + + +# not highly optimal, may replace with generated C program like makesdna +function(data_to_c + file_from file_to var_name) + + file(READ ${file_from} file_from_string HEX) + string(LENGTH ${file_from_string} _max_index) + math(EXPR size_on_disk ${_max_index}/2) + + file(REMOVE ${file_to}) + + file(APPEND ${file_to} "int ${var_name}_size = ${size_on_disk};\n") + file(APPEND ${file_to} "char ${var_name}[] = {") + + set(_index 0) + + while(NOT _index EQUAL _max_index) + string(SUBSTRING "${file_from_string}" ${_index} 2 _pair) + file(APPEND ${file_to} "0x${_pair},") + math(EXPR _index ${_index}+2) + endwhile() + file(APPEND ${file_to} "};\n") +endfunction() + +# eg +# data_to_c("/home/guest/test.txt" "/home/guest/test.txt.h" "this_is_data") +