Skip to content

Commit d422b5c

Browse files
authored
Merge pull request #60299 from eeckstein/fix-cmake-dependencies
cmake: add a hack to get correct dependencies from C++ header files -> Swift compiler sources
2 parents 63b652d + e796fc8 commit d422b5c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function(add_swift_compiler_modules_library name)
165165
add_custom_command_target(dep_target OUTPUT ${module_obj_file}
166166
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
167167
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
168+
importedHeaderDependencies
168169
COMMAND ${ALS_SWIFT_EXEC} "-c" "-o" ${module_obj_file}
169170
${sdk_option}
170171
"-target" ${target}
@@ -229,6 +230,24 @@ else()
229230

230231
add_subdirectory(Sources)
231232

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+
232251
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
233252

234253
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES)

0 commit comments

Comments
 (0)