summaryrefslogtreecommitdiff
path: root/Embed.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Embed.cmake')
-rw-r--r--Embed.cmake11
1 files changed, 9 insertions, 2 deletions
diff --git a/Embed.cmake b/Embed.cmake
index ce2c5ff8..4d51f418 100644
--- a/Embed.cmake
+++ b/Embed.cmake
@@ -47,6 +47,13 @@ const iBlock ${name} = { &data_${name}_ };
47 file (APPEND ${fnHeader} "${header}") 47 file (APPEND ${fnHeader} "${header}")
48endfunction (embed_write) 48endfunction (embed_write)
49 49
50function (embed_filesize path sizeVar)
51 file (READ ${path} data HEX)
52 string (LENGTH ${data} fsize)
53 math (EXPR fsize "${fsize}/2")
54 set (${sizeVar} ${fsize} PARENT_SCOPE)
55endfunction (embed_filesize)
56
50function (embed_make) 57function (embed_make)
51 set (EMB_H ${CMAKE_CURRENT_BINARY_DIR}/embedded.h) 58 set (EMB_H ${CMAKE_CURRENT_BINARY_DIR}/embedded.h)
52 set (EMB_C ${CMAKE_CURRENT_BINARY_DIR}/embedded.c) 59 set (EMB_C ${CMAKE_CURRENT_BINARY_DIR}/embedded.c)
@@ -85,7 +92,7 @@ function (embed_make)
85 set (offsets) 92 set (offsets)
86 set (fpos 0) 93 set (fpos 0)
87 foreach (fn ${ARGV}) 94 foreach (fn ${ARGV})
88 file (SIZE ${CMAKE_SOURCE_DIR}/${fn} fileSize) 95 embed_filesize (${CMAKE_SOURCE_DIR}/${fn} fileSize)
89 list (APPEND offsets "${fpos}") 96 list (APPEND offsets "${fpos}")
90 math (EXPR fpos "${fpos} + ${fileSize}") 97 math (EXPR fpos "${fpos} + ${fileSize}")
91 endforeach (fn) 98 endforeach (fn)
@@ -108,7 +115,7 @@ static const iEmbedChunk chunks_Embed_[] = {
108]]) 115]])
109 set (index 0) 116 set (index 0)
110 foreach (fn ${ARGV}) 117 foreach (fn ${ARGV})
111 file (SIZE ${CMAKE_SOURCE_DIR}/${fn} fileSize) 118 embed_filesize (${CMAKE_SOURCE_DIR}/${fn} fileSize)
112 list (GET offsets ${index} fpos) 119 list (GET offsets ${index} fpos)
113 file (APPEND ${EMB_C} " { ${fpos}, ${fileSize} },\n") 120 file (APPEND ${EMB_C} " { ${fpos}, ${fileSize} },\n")
114 math (EXPR index "${index} + 1") 121 math (EXPR index "${index} + 1")