Skip to content

Commit 5fc3b82

Browse files
committed
WIP: raw data header with _hex
1 parent c652332 commit 5fc3b82

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

cmake/script/GenerateHeaderFromRaw.cmake

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
cmake_path(GET RAW_SOURCE_PATH STEM raw_source_basename)
66

77
file(READ ${RAW_SOURCE_PATH} hex_content HEX)
8-
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
9-
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}," formatted_bytes "${formatted_bytes}")
8+
string(STRIP "${hex_content}" hex_content)
109

1110
set(header_content
12-
"#include <cstddef>
11+
"#include <util/strencodings.h>
12+
13+
#include <cstddef>
1314
#include <span>
1415
16+
using namespace util::hex_literals;
17+
1518
namespace ${RAW_NAMESPACE} {
16-
inline constexpr std::byte detail_${raw_source_basename}_raw[] {
17-
${formatted_bytes}
18-
};
1919
20-
inline constexpr std::span ${raw_source_basename}{detail_${raw_source_basename}_raw};
21-
}
20+
inline constexpr auto ${raw_source_basename} = \"${hex_content}\"_hex;
21+
inline constexpr std::span<const std::byte> ${raw_source_basename}_span{${raw_source_basename}};
22+
23+
} // namespace ${RAW_NAMESPACE}
2224
")
25+
2326
file(WRITE ${HEADER_PATH} "${header_content}")

0 commit comments

Comments
 (0)