diff options
Diffstat (limited to 'build_files/cmake/data_to_c.cmake')
-rw-r--r-- | build_files/cmake/data_to_c.cmake | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/build_files/cmake/data_to_c.cmake b/build_files/cmake/data_to_c.cmake new file mode 100644 index 00000000000..b8b18269dc8 --- /dev/null +++ b/build_files/cmake/data_to_c.cmake @@ -0,0 +1,25 @@ +# cmake script, to be called on its own with 3 defined args +# +# - FILE_FROM +# - FILE_TO +# - VAR_NAME + +# not highly optimal, may replace with generated C program like makesdna +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() +# null terminator not essential but good if we want plane strings encoded +file(APPEND ${FILE_TO} "0x00};\n") |