diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-17 10:00:52 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-17 10:01:12 +0300 |
commit | 9aa25106b76b0e9ab77fe405c9a0039efd67f016 (patch) | |
tree | 39cbf46d6a5717b47f516703573dd74aed2ebe21 | |
parent | 6a550da2b01921e66f49badff11ac6ab9b88cd21 (diff) |
CMake: Support older CMake for checking file sizes
-rw-r--r-- | Embed.cmake | 11 |
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}") |
48 | endfunction (embed_write) | 48 | endfunction (embed_write) |
49 | 49 | ||
50 | function (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) | ||
55 | endfunction (embed_filesize) | ||
56 | |||
50 | function (embed_make) | 57 | function (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") |