Skip to content

Commit 59386eb

Browse files
committed
EmbedText: split embedded source lines just in case if an editor or debugger opens it
1 parent 9af0bec commit 59386eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cmake/EmbedText.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
file(READ ${INPUT_FILE} contents HEX)
1010

11+
# Translate the file content.
1112
if ("${FILE_FORMAT}" STREQUAL "TEXT")
1213
# Strip \r for consistency.
1314
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents "${contents}")
@@ -17,4 +18,18 @@ else()
1718
message(FATAL_ERROR "Unknown file format: ${FILE_FORMAT}")
1819
endif()
1920

20-
file(WRITE ${OUTPUT_FILE} "const unsigned char ${VARIABLE_NAME}[] = {${contents}};\n")
21+
# Split long lines.
22+
string(REGEX REPLACE
23+
"(0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,0x..,)" "\\1\n"
24+
contents "${contents}"
25+
)
26+
27+
# A bit more of beautification.
28+
string(REGEX REPLACE ",$" ",\n" contents "${contents}")
29+
30+
file(WRITE ${OUTPUT_FILE}
31+
"const unsigned char ${VARIABLE_NAME}[] =\n"
32+
"{\n"
33+
"${contents}"
34+
"};\n"
35+
)

0 commit comments

Comments
 (0)