@@ -165,6 +165,7 @@ function(add_swift_compiler_modules_library name)
165
165
add_custom_command_target (dep_target OUTPUT ${module_obj_file}
166
166
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
167
167
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
168
+ importedHeaderDependencies
168
169
COMMAND ${ALS_SWIFT_EXEC} "-c" "-o" ${module_obj_file}
169
170
${sdk_option}
170
171
"-target" ${target}
@@ -229,6 +230,24 @@ else()
229
230
230
231
add_subdirectory (Sources )
231
232
233
+ # This is a hack to get correct dependencies from imported C++ headers:
234
+ # step 1: generate a dummy source file, which just includes all headers defined in include/swift/module.modulemap
235
+ add_custom_command (
236
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /HeaderDependencies.cpp"
237
+ COMMAND
238
+ "sed"
239
+ -n -e "/header/!d" -e "s/.*header/#include/" -e "w ${CMAKE_CURRENT_BINARY_DIR} /HeaderDependencies.cpp"
240
+ "${CMAKE_SOURCE_DIR} /include/swift/module.modulemap"
241
+ DEPENDS "${CMAKE_SOURCE_DIR} /include/swift/module.modulemap"
242
+ COMMENT "Generate HeaderDependencies.cpp"
243
+ )
244
+
245
+ # step 2: build a library containing that source file. This library depends on all the included header files.
246
+ # The swift modules can now depend on that target.
247
+ # Note that this library is unused, i.e. not linked to anything.
248
+ add_library (importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR} /HeaderDependencies.cpp" )
249
+ target_include_directories (importedHeaderDependencies PRIVATE "${CMAKE_SOURCE_DIR} /include/swift" )
250
+
232
251
if (${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE" )
233
252
234
253
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES )
0 commit comments