Skip to content

Commit 015e95f

Browse files
committed
Merge #110: cmake: add target_capnp_sources headers target
66e12f1 cmake: add target_capnp_sources headers target (Ryan Ofsky) Pull request description: Modify target_capnp_sources function to create a custom cmake target depending on generated capnp headers, that can be listed as an explicit dependency of other c++ targets when cmake's implicit dependency tracking for included files doesn't work. This might help fix the build problem encountered bitcoin/bitcoin#30510 (comment) ACKs for top commit: TheCharlatan: lgtm ACK 66e12f1 Tree-SHA512: e21cc3c58bf14af2c418f0c50af72f514c4a9358591dc9b63cfa5cec72f658d196fff15d94c9097bc552ee0443b8fcefcb4f99bbad89fe04393955892cdfb094
2 parents f67cae8 + 66e12f1 commit 015e95f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmake/TargetCapnpSources.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function(target_capnp_sources target include_prefix)
6464
message(FATAL_ERROR "Target 'Libmultiprocess::mpgen' does not exist.")
6565
endif()
6666

67+
set(generated_headers "")
6768
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
6869
add_custom_command(
6970
OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h
@@ -77,6 +78,8 @@ function(target_capnp_sources target include_prefix)
7778
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-server.c++
7879
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-types.c++
7980
)
81+
82+
list(APPEND generated_headers ${capnp_file}.h)
8083
endforeach()
8184

8285
# Translate include_prefix from a source path to a binary path and add it as a
@@ -91,4 +94,11 @@ function(target_capnp_sources target include_prefix)
9194
if(TARGET Libmultiprocess::multiprocess)
9295
target_link_libraries(${target} PRIVATE Libmultiprocess::multiprocess)
9396
endif()
97+
98+
# Add a custom target that can be specified as a dependency of c++ targets
99+
# that include generated headers. It can be necessary to specify these
100+
# dependencies explicitly because while cmake detect dependencies of non
101+
# generated files on generated headers, it does not reliably detect
102+
# dependencies of generated headers on other generated headers.
103+
add_custom_target("${target}_headers" DEPENDS ${generated_headers})
94104
endfunction()

0 commit comments

Comments
 (0)