Skip to content

Commit 6277c7e

Browse files
committed
Improve tracking dependencies of header generation.
Before: - Build example 3 using `cmake -G Ninja && ninja` - Change include/fibonacci.h - Rebuild using just `ninja` - No build occurs. After: - Follow same steps - Generated header file is emitted afresh
1 parent 36f0a94 commit 6277c7e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

3_bidirectional_cxx_interop/cmake/modules/AddSwift.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ function(_swift_generate_cxx_header target header)
4848
cmake_path(APPEND base_path ${header}
4949
OUTPUT_VARIABLE header_path)
5050

51+
# Work out the name of the .d file that swiftc will emit
52+
get_target_property(module_name ${target} Swift_MODULE_NAME)
53+
set(depfile_name "${module_name}.emit-module.d")
54+
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR ${depfile_name} OUTPUT_VARIABLE depfile_path)
55+
5156
set(_AllSources $<TARGET_PROPERTY:${target},SOURCES>)
5257
set(_SwiftSources $<FILTER:${_AllSources},INCLUDE,\\.swift$>)
5358
add_custom_command(OUTPUT ${header_path}
@@ -61,6 +66,8 @@ function(_swift_generate_cxx_header target header)
6166
-module-name "${ARG_MODULE_NAME}"
6267
-cxx-interoperability-mode=default
6368
-emit-clang-header-path ${header_path}
69+
-emit-dependencies
70+
DEPFILE ${depfile_path}
6471
COMMENT
6572
"Generating '${header_path}'"
6673
COMMAND_EXPAND_LISTS)

0 commit comments

Comments
 (0)