Skip to content

Commit 8975161

Browse files
committed
Temporarily workaround CMake dependencies bug
Workaround a CMake bug in order to make sure that libraries are rebuilt when their dependencies change.
1 parent ef4605b commit 8975161

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Sources/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
# cmake generation for Swift adds an order only dependency, which matches how C-family languages
10+
# works. In that case, however, ninja (and presumably other generators) will rebuild on header
11+
# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
12+
# ABI/API of B changes.
13+
#
14+
# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
15+
# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
16+
# seem to be being tracked.
17+
#
18+
# Remove once rdar://102202478 is fixed.
19+
function(target_link_libraries TARGET)
20+
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
21+
22+
_target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
23+
foreach(DEPENDENCY ${ARGS_PUBLIC})
24+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
25+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
26+
DEPENDS ${DEPENDENCY}
27+
)
28+
target_sources(${TARGET} PRIVATE
29+
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
30+
)
31+
endforeach()
32+
endfunction()
33+
934
add_subdirectory(SwiftBasicFormat)
1035
add_subdirectory(SwiftSyntax)
1136
add_subdirectory(SwiftDiagnostics)

0 commit comments

Comments
 (0)