[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49698] trunk/blender/build_files/cmake/ macros.cmake: data_to_c in cmake, not used yet.

Campbell Barton ideasman42 at gmail.com
Wed Aug 8 18:03:43 CEST 2012


Revision: 49698
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49698
Author:   campbellbarton
Date:     2012-08-08 16:03:42 +0000 (Wed, 08 Aug 2012)
Log Message:
-----------
data_to_c in cmake, not used yet.

Modified Paths:
--------------
    trunk/blender/build_files/cmake/macros.cmake

Modified: trunk/blender/build_files/cmake/macros.cmake
===================================================================
--- trunk/blender/build_files/cmake/macros.cmake	2012-08-08 14:02:44 UTC (rev 49697)
+++ trunk/blender/build_files/cmake/macros.cmake	2012-08-08 16:03:42 UTC (rev 49698)
@@ -725,3 +725,31 @@
 		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")
+




More information about the Bf-blender-cvs mailing list