GenerateHeaderFromJson.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 JSON_SOURCE_PATH STEM json_source_basename)
6
7 file(READ ${JSON_SOURCE_PATH} hex_content HEX)
8 string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
9 string(REGEX REPLACE "[^\n][^\n]" "'\\\\x\\0'," formatted_bytes "${formatted_bytes}")
10
11 set(header_content
12 "#include <string_view>
13
14 namespace json_tests {
15 inline constexpr char detail_${json_source_basename}_bytes[] {
16 ${formatted_bytes}
17 };
18
19 inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)};
20 }
21 ")
22 file(WRITE ${HEADER_PATH} "${header_content}")
23