diff --git a/cmake/module/GenerateHeaders.cmake b/cmake/module/GenerateHeaders.cmake deleted file mode 100644 index c69007acb6849..0000000000000 --- a/cmake/module/GenerateHeaders.cmake +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2023-present The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or https://opensource.org/license/mit/. - -function(generate_header_from_json json_source_relpath) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${json_source_relpath}.h - COMMAND ${CMAKE_COMMAND} -DJSON_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${json_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${json_source_relpath}.h -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${json_source_relpath} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake - VERBATIM - ) -endfunction() - -function(generate_header_from_raw raw_source_relpath raw_namespace) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h - COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h -DRAW_NAMESPACE=${raw_namespace} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake - VERBATIM - ) -endfunction() diff --git a/cmake/module/TargetDataSources.cmake b/cmake/module/TargetDataSources.cmake new file mode 100644 index 0000000000000..e10abe9e51f4a --- /dev/null +++ b/cmake/module/TargetDataSources.cmake @@ -0,0 +1,36 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +function(target_data_sources target) + set(options "") + set(one_value_args RAW_NAMESPACE) + set(multi_value_keywords JSON_FILES RAW_FILES) + cmake_parse_arguments( + PARSE_ARGV 1 + ARG + "${options}" "${one_value_args}" "${multi_value_keywords}" + ) + + foreach(json_file IN LISTS ARG_JSON_FILES) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${json_file}.h + COMMAND ${CMAKE_COMMAND} -DJSON_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${json_file} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${json_file}.h -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${json_file} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${json_file} + VERBATIM + ) + target_sources(${target} PRIVATE ${json_file}) + endforeach() + + foreach(raw_file IN LISTS ARG_RAW_FILES) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${raw_file}.h + COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_file} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${raw_file}.h -DRAW_NAMESPACE=${ARG_RAW_NAMESPACE} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_file} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${raw_file} + VERBATIM + ) + target_sources(${target} PRIVATE ${raw_file}) + endforeach() +endfunction() diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt index 4589ef177c331..b148303f6a134 100644 --- a/src/bench/CMakeLists.txt +++ b/src/bench/CMakeLists.txt @@ -2,14 +2,10 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://opensource.org/license/mit/. -include(GenerateHeaders) -generate_header_from_raw(data/block413567.raw benchmark::data) - add_executable(bench_bitcoin bench_bitcoin.cpp bench.cpp nanobench.cpp - ${CMAKE_CURRENT_BINARY_DIR}/data/block413567.raw.h # Benchmarks: addrman.cpp base58.cpp @@ -56,6 +52,13 @@ add_executable(bench_bitcoin xor.cpp ) +include(TargetDataSources) +target_data_sources(bench_bitcoin + RAW_FILES + data/block413567.raw + RAW_NAMESPACE benchmark::data +) + target_link_libraries(bench_bitcoin core_interface test_util diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 859b913206782..0589ab6c2109f 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -2,32 +2,10 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or https://opensource.org/license/mit/. -include(GenerateHeaders) -generate_header_from_json(data/base58_encode_decode.json) -generate_header_from_json(data/bip341_wallet_vectors.json) -generate_header_from_json(data/blockfilters.json) -generate_header_from_json(data/key_io_invalid.json) -generate_header_from_json(data/key_io_valid.json) -generate_header_from_json(data/script_tests.json) -generate_header_from_json(data/sighash.json) -generate_header_from_json(data/tx_invalid.json) -generate_header_from_json(data/tx_valid.json) -generate_header_from_raw(data/asmap.raw test::data) - # Do not use generator expressions in test sources because the # SOURCES property is processed to gather test suite macros. add_executable(test_bitcoin main.cpp - ${CMAKE_CURRENT_BINARY_DIR}/data/asmap.raw.h - ${CMAKE_CURRENT_BINARY_DIR}/data/base58_encode_decode.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/bip341_wallet_vectors.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/blockfilters.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/key_io_invalid.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/key_io_valid.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/script_tests.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/sighash.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/tx_invalid.json.h - ${CMAKE_CURRENT_BINARY_DIR}/data/tx_valid.json.h addrman_tests.cpp allocator_tests.cpp amount_tests.cpp @@ -145,6 +123,23 @@ add_executable(test_bitcoin versionbits_tests.cpp ) +include(TargetDataSources) +target_data_sources(test_bitcoin + JSON_FILES + data/base58_encode_decode.json + data/bip341_wallet_vectors.json + data/blockfilters.json + data/key_io_invalid.json + data/key_io_valid.json + data/script_tests.json + data/sighash.json + data/tx_invalid.json + data/tx_valid.json + RAW_FILES + data/asmap.raw + RAW_NAMESPACE test::data +) + target_link_libraries(test_bitcoin core_interface test_util diff --git a/src/univalue/CMakeLists.txt b/src/univalue/CMakeLists.txt index c31e82cadcc17..53e45f6ef47aa 100644 --- a/src/univalue/CMakeLists.txt +++ b/src/univalue/CMakeLists.txt @@ -15,120 +15,68 @@ target_include_directories(univalue target_link_libraries(univalue PRIVATE core_interface) if(BUILD_TESTS) - include(GenerateHeaders) - generate_header_from_json(test/fail1.json) - generate_header_from_json(test/fail10.json) - generate_header_from_json(test/fail11.json) - generate_header_from_json(test/fail12.json) - generate_header_from_json(test/fail13.json) - generate_header_from_json(test/fail14.json) - generate_header_from_json(test/fail15.json) - generate_header_from_json(test/fail16.json) - generate_header_from_json(test/fail17.json) - generate_header_from_json(test/fail18.json) - generate_header_from_json(test/fail19.json) - generate_header_from_json(test/fail2.json) - generate_header_from_json(test/fail20.json) - generate_header_from_json(test/fail21.json) - generate_header_from_json(test/fail22.json) - generate_header_from_json(test/fail23.json) - generate_header_from_json(test/fail24.json) - generate_header_from_json(test/fail25.json) - generate_header_from_json(test/fail26.json) - generate_header_from_json(test/fail27.json) - generate_header_from_json(test/fail28.json) - generate_header_from_json(test/fail29.json) - generate_header_from_json(test/fail3.json) - generate_header_from_json(test/fail30.json) - generate_header_from_json(test/fail31.json) - generate_header_from_json(test/fail32.json) - generate_header_from_json(test/fail33.json) - generate_header_from_json(test/fail34.json) - generate_header_from_json(test/fail35.json) - generate_header_from_json(test/fail36.json) - generate_header_from_json(test/fail37.json) - generate_header_from_json(test/fail38.json) - generate_header_from_json(test/fail39.json) - generate_header_from_json(test/fail4.json) - generate_header_from_json(test/fail40.json) - generate_header_from_json(test/fail41.json) - generate_header_from_json(test/fail42.json) - generate_header_from_json(test/fail44.json) - generate_header_from_json(test/fail45.json) - generate_header_from_json(test/fail5.json) - generate_header_from_json(test/fail6.json) - generate_header_from_json(test/fail7.json) - generate_header_from_json(test/fail8.json) - generate_header_from_json(test/fail9.json) - generate_header_from_json(test/pass1.json) - generate_header_from_json(test/pass2.json) - generate_header_from_json(test/pass3.json) - generate_header_from_json(test/pass4.json) - generate_header_from_json(test/round1.json) - generate_header_from_json(test/round2.json) - generate_header_from_json(test/round3.json) - generate_header_from_json(test/round4.json) - generate_header_from_json(test/round5.json) - generate_header_from_json(test/round6.json) - generate_header_from_json(test/round7.json) add_executable(unitester - ${CMAKE_CURRENT_BINARY_DIR}/test/fail1.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail10.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail11.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail12.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail13.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail14.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail15.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail16.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail17.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail18.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail19.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail2.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail20.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail21.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail22.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail23.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail24.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail25.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail26.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail27.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail28.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail29.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail3.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail30.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail31.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail32.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail33.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail34.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail35.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail36.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail37.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail38.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail39.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail4.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail40.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail41.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail42.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail44.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail45.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail5.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail6.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail7.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail8.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/fail9.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/pass1.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/pass2.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/pass3.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/pass4.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round1.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round2.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round3.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round4.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round5.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round6.json.h - ${CMAKE_CURRENT_BINARY_DIR}/test/round7.json.h test/unitester.cpp ) + include(TargetDataSources) + target_data_sources(unitester + JSON_FILES + test/fail1.json + test/fail10.json + test/fail11.json + test/fail12.json + test/fail13.json + test/fail14.json + test/fail15.json + test/fail16.json + test/fail17.json + test/fail18.json + test/fail19.json + test/fail2.json + test/fail20.json + test/fail21.json + test/fail22.json + test/fail23.json + test/fail24.json + test/fail25.json + test/fail26.json + test/fail27.json + test/fail28.json + test/fail29.json + test/fail3.json + test/fail30.json + test/fail31.json + test/fail32.json + test/fail33.json + test/fail34.json + test/fail35.json + test/fail36.json + test/fail37.json + test/fail38.json + test/fail39.json + test/fail4.json + test/fail40.json + test/fail41.json + test/fail42.json + test/fail44.json + test/fail45.json + test/fail5.json + test/fail6.json + test/fail7.json + test/fail8.json + test/fail9.json + test/pass1.json + test/pass2.json + test/pass3.json + test/pass4.json + test/round1.json + test/round2.json + test/round3.json + test/round4.json + test/round5.json + test/round6.json + test/round7.json + ) target_link_libraries(unitester PRIVATE core_interface