mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-31 19:31:02 +02:00
Merge bitcoin/bitcoin#30901: cmake: Revamp handling of data files
ecf54a32ed
cmake: Add support for builtin `codegen` target (Hennadii Stepanov)a8c78a0574
cmake: Revamp handling of data files (Hennadii Stepanov) Pull request description: This PR leverages the approach from the https://github.com/chaincodelabs/libmultiprocess project and introduces a new functions `target_json_data_sources()` and `target_raw_data_sources()`, which minimize the amount of code required to assign to assign a `*.json` or `*.raw` data file to the `test_bitcoin`, `bench_bitcoin` or `unitester` targets. As requested in https://github.com/bitcoin/bitcoin/pull/30901#issuecomment-2654622689, the `codegen` build target is now supported, if available: ``` $ cmake --version cmake version 3.31.5 CMake suite maintained and supported by Kitware (kitware.com/cmake). $ cmake -G "Ninja" -B build $ cmake --build build --target codegen ``` ACKs for top commit: fjahr: re-ACKecf54a32ed
Sjors: re-tACKecf54a32ed
theuni: ACKecf54a32ed
Tree-SHA512: bab92df6b81c47d9d97ba8db37470a6d7aa435d5578afe40df7154885eda55afc59f0bf20dc9db3b2fd88ceb9a0319b9678f9e9af01e7afd4851ec3a79f3f402
This commit is contained in:
@@ -1,29 +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/.
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
|
||||
set(DEPENDS_EXPLICIT_OPT DEPENDS_EXPLICIT_ONLY)
|
||||
else()
|
||||
set(DEPENDS_EXPLICIT_OPT)
|
||||
endif()
|
||||
|
||||
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
|
||||
${DEPENDS_EXPLICIT_OPT}
|
||||
)
|
||||
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
|
||||
${DEPENDS_EXPLICIT_OPT}
|
||||
)
|
||||
endfunction()
|
55
cmake/module/TargetDataSources.cmake
Normal file
55
cmake/module/TargetDataSources.cmake
Normal file
@@ -0,0 +1,55 @@
|
||||
# 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/.
|
||||
|
||||
macro(set_add_custom_command_options)
|
||||
set(DEPENDS_EXPLICIT_OPT "")
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
|
||||
set(DEPENDS_EXPLICIT_OPT DEPENDS_EXPLICIT_ONLY)
|
||||
endif()
|
||||
set(CODEGEN_OPT "")
|
||||
if(POLICY CMP0171)
|
||||
cmake_policy(GET CMP0171 _cmp0171_status)
|
||||
if(_cmp0171_status STREQUAL "NEW")
|
||||
set(CODEGEN_OPT CODEGEN)
|
||||
endif()
|
||||
unset(_cmp0171_status)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Specifies JSON data files to be processed into corresponding
|
||||
# header files for inclusion when building a target.
|
||||
function(target_json_data_sources target)
|
||||
set_add_custom_command_options()
|
||||
foreach(json_file IN LISTS ARGN)
|
||||
set(header ${CMAKE_CURRENT_BINARY_DIR}/${json_file}.h)
|
||||
add_custom_command(
|
||||
OUTPUT ${header}
|
||||
COMMAND ${CMAKE_COMMAND} -DJSON_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${json_file} -DHEADER_PATH=${header} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${json_file} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake
|
||||
VERBATIM
|
||||
${CODEGEN_OPT}
|
||||
${DEPENDS_EXPLICIT_OPT}
|
||||
)
|
||||
target_sources(${target} PRIVATE ${header})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# Specifies raw binary data files to be processed into corresponding
|
||||
# header files for inclusion when building a target.
|
||||
function(target_raw_data_sources target)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 _ "" "NAMESPACE" "")
|
||||
set_add_custom_command_options()
|
||||
foreach(raw_file IN LISTS __UNPARSED_ARGUMENTS)
|
||||
set(header ${CMAKE_CURRENT_BINARY_DIR}/${raw_file}.h)
|
||||
add_custom_command(
|
||||
OUTPUT ${header}
|
||||
COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_file} -DHEADER_PATH=${header} -DRAW_NAMESPACE=${__NAMESPACE} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_file} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
|
||||
VERBATIM
|
||||
${CODEGEN_OPT}
|
||||
${DEPENDS_EXPLICIT_OPT}
|
||||
)
|
||||
target_sources(${target} PRIVATE ${header})
|
||||
endforeach()
|
||||
endfunction()
|
Reference in New Issue
Block a user