Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b03f5b2
commit a042edd
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
cmake_minimum_required (VERSION 2.8.12) | ||
|
||
# Create header for C file | ||
file(WRITE ${OUTPUT_C} "/* Autogenerated by bin2c */\n\n") | ||
file(APPEND ${OUTPUT_C} "#include <stdint.h>\n\n") | ||
|
||
# Create header of H file | ||
file(WRITE ${OUTPUT_H} "/* Autogenerated by bin2c */\n\n") | ||
file(APPEND ${OUTPUT_H} "#pragma once\n") | ||
file(APPEND ${OUTPUT_H} "#include <stdint.h>\n\n") | ||
|
||
string(REPLACE "," ";" INPUT_LIST ${INPUT_FILES}) | ||
|
||
|
||
# Iterate through binary files files | ||
foreach(bin ${INPUT_LIST}) | ||
# Get short filename | ||
string(REGEX MATCH "([^/]+)$" filename ${bin}) | ||
# Replace filename spaces & extension separator for C compatibility | ||
string(REGEX REPLACE "\\.| |-" "_" filename ${filename}) | ||
# Convert to lower case | ||
string(TOLOWER ${filename} filename) | ||
# Read hex data from file | ||
file(READ ${bin} filedata HEX) | ||
# Convert hex data for C compatibility | ||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) | ||
# Append data to c file | ||
file(APPEND ${OUTPUT_C} "uint8_t ${filename}[] = {${filedata}};\n\nuint32_t ${filename}_size = sizeof(${filename});\n\n") | ||
# Append extern definitions to h file | ||
file(APPEND ${OUTPUT_H} "extern uint8_t ${filename}[];\n\nextern uint32_t ${filename}_size;\n\n") | ||
endforeach() |