Skip to content

Commit c4e4983

Browse files
committed
build: avoid unnecessary dependencies on generated headers
This prevents the generation of these headers from also depending on the dependencies of the libs/binaries which consume them. Specifically, this prevents generated test headers (such as test/data/base58_encode_decode.json.h) from depending on the dependencies of test_bitcoin (libcrc32c.a libcrc32c_sse42.a libleveldb.a) Note that this is currently only relevant for Ninja. For more detail, see: https://cmake.org/cmake/help/latest/command/add_custom_command.html
1 parent 8fa10ed commit c4e4983

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cmake/module/GenerateHeaders.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or https://opensource.org/license/mit/.
44

5+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
6+
set(DEPENDS_EXPLICIT_OPT DEPENDS_EXPLICIT_ONLY)
7+
else()
8+
set(DEPENDS_EXPLICIT_OPT)
9+
endif()
10+
511
function(generate_header_from_json json_source_relpath)
612
add_custom_command(
713
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${json_source_relpath}.h
814
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
915
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${json_source_relpath} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromJson.cmake
1016
VERBATIM
17+
${DEPENDS_EXPLICIT_OPT}
1118
)
1219
endfunction()
1320

@@ -17,5 +24,6 @@ function(generate_header_from_raw raw_source_relpath raw_namespace)
1724
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
1825
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
1926
VERBATIM
27+
${DEPENDS_EXPLICIT_OPT}
2028
)
2129
endfunction()

0 commit comments

Comments
 (0)