GenerateHeaderFromRaw.cmake raw
1 # Copyright (c) 2023-present The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or https://opensource.org/license/mit/.
4
5 cmake_path(GET RAW_SOURCE_PATH STEM raw_source_basename)
6
7 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}")
10
11 set(header_content
12 "#include <cstddef>
13 #include <span>
14
15 namespace ${RAW_NAMESPACE} {
16 inline constexpr std::byte detail_${raw_source_basename}_raw[] {
17 ${formatted_bytes}
18 };
19
20 inline constexpr std::span ${raw_source_basename}{detail_${raw_source_basename}_raw};
21 }")
22 file(WRITE ${HEADER_PATH} "${header_content}")
23