diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-08 20:03:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-08 20:03:42 +0400 |
commit | c953ca11ac20fd90fea5a6235fc38d2aa9ec631c (patch) | |
tree | c03667e5633d06913baca6022ad89797f7ac2008 | |
parent | a35420eee576ffbc597c22c0c9ee947e6649ec85 (diff) |
data_to_c in cmake, not used yet.
-rw-r--r-- | build_files/cmake/macros.cmake | 28 |
1 files changed, 28 insertions, 0 deletions
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") + |