Merging r49775 through r49807 from trunk into soc-2011-tomato
[blender.git] / build_files / cmake / macros.cmake
index 522a07ff7b23e59a3c1f43f770f333c6979ccab0..959107d684bc1762c86188fccbf686fce5ad098c 100644 (file)
@@ -644,7 +644,7 @@ macro(blender_project_hack_post)
        # --------------
        # MINGW HACK END
        if (_reset_standard_libraries)
-               # Must come after project(...)
+               # Must come after projecINCt(...)
                #
                # MINGW workaround for -ladvapi32 being included which surprisingly causes
                # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
@@ -733,29 +733,48 @@ macro(set_lib_path
 endmacro()
 
 
-# not highly optimal, may replace with generated C program like makesdna
-function(data_to_c
-         file_from file_to var_name)
+# TODO, create a C binary and call it instead!, doing this in cmake its slow
+macro(data_to_c
+      file_from file_to var_name
+      list_to_add)
 
-       file(READ ${file_from} file_from_string HEX)
-       string(LENGTH ${file_from_string} _max_index)
-       math(EXPR size_on_disk ${_max_index}/2)
+       list(APPEND ${list_to_add} ${file_to})
 
-       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")
+       add_custom_command(
+               OUTPUT ${file_to}
+               COMMAND ${CMAKE_COMMAND}
+                               -DFILE_FROM=${file_from}
+                               -DFILE_TO=${file_to}
+                               -DVAR_NAME=${var_name}
+                               -P ${CMAKE_SOURCE_DIR}/build_files/cmake/data_to_c.cmake
+               DEPENDS ${file_from})
+endmacro()
 
+# same as above but generates the var name and output automatic.
+macro(data_to_c_simple
+      file_from
+      list_to_add)
+
+    # get var name automatic from name
+    get_filename_component(_file_from_only ${file_from} NAME)
+    string(REPLACE "." "_" _file_from_only ${_file_from_only})
+    set(_var_name "datatoc_${_file_from_only}")
+
+    # only to avoid confusion
+    set(_file_to ${file_from}.c)
+
+       list(APPEND ${list_to_add} ${CMAKE_CURRENT_BINARY_DIR}/${_file_to})
+
+       add_custom_command(
+               OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file_to}
+               COMMAND ${CMAKE_COMMAND}
+                               -DFILE_FROM=${CMAKE_CURRENT_SOURCE_DIR}/${file_from}
+                               -DFILE_TO=${CMAKE_CURRENT_BINARY_DIR}/${_file_to}
+                               -DVAR_NAME=${_var_name}
+                               -P ${CMAKE_SOURCE_DIR}/build_files/cmake/data_to_c.cmake
+               DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file_from})
+
+    unset(_file_from_only)
+    unset(_var_name)
+    unset(_file_to)
+endmacro()