data_to_c in cmake, not used yet.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 8 Aug 2012 16:03:42 +0000 (16:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 8 Aug 2012 16:03:42 +0000 (16:03 +0000)
build_files/cmake/macros.cmake

index b0e6b936ce0c50c6f5cc3c0b71615c244f13adfb..50bbab9eed9b61849d1d9f5ed6395a37595229d3 100644 (file)
@@ -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")
+