@@ -46,34 +46,31 @@ if (SWIFT_SWIFT_PARSER)
46
46
47
47
target_compile_options (swiftASTGen PRIVATE $< $< COMPILE_LANGUAGE:Swift> :-target;${target} > )
48
48
49
- # Link against the SwiftSyntax parser and libraries it depends on. The actual
50
- # formulation of this is a hack to work around a CMake bug in Ninja file
51
- # generation that results in multiple Ninja targets producing the same file in
52
- # a downstream SourceKit target. This should be expressed as:
53
- #
54
- # target_link_libraries(swiftASTGen
55
- # PRIVATE
56
- # SwiftSyntax::SwiftCompilerSupport
57
- # )
58
- target_link_libraries (swiftASTGen
59
- PRIVATE
60
- $< TARGET_OBJECTS:SwiftSyntax::SwiftBasicFormat>
61
- $< TARGET_OBJECTS:SwiftSyntax::SwiftParser>
62
- $< TARGET_OBJECTS:SwiftSyntax::SwiftParserDiagnostics>
63
- $< TARGET_OBJECTS:SwiftSyntax::SwiftDiagnostics>
64
- $< TARGET_OBJECTS:SwiftSyntax::SwiftSyntax>
65
- $< TARGET_OBJECTS:SwiftSyntax::SwiftOperators>
66
- $< TARGET_OBJECTS:SwiftSyntax::SwiftSyntaxBuilder>
67
- $< TARGET_OBJECTS:SwiftSyntax::_SwiftSyntaxMacros>
68
- $< TARGET_OBJECTS:SwiftSyntax::SwiftCompilerSupport>
49
+ # Workaround a cmake bug, see the corresponding function in swift-syntax
50
+ function (force_target_linked_libraries TARGET )
51
+ cmake_parse_arguments (ARGS "" "" "PUBLIC" ${ARGN} )
69
52
70
- swiftAST
71
- )
53
+ foreach (DEPENDENCY ${ARGS_PUBLIC} )
54
+ # This is a hack to workaround a cmake bug that results in multiple ninja targets producing
55
+ # the same file in a downstream SourceKit target. This should use `PUBLIC`, the dependency
56
+ # directly (rather than `TARGET_OBJECTS`), and no `add_dependencies`.
57
+ target_link_libraries (${TARGET} PRIVATE
58
+ $< TARGET_OBJECTS:${DEPENDENCY} >
59
+ )
60
+ add_dependencies (${TARGET} ${DEPENDENCY} )
72
61
73
- target_include_directories (swiftASTGen PUBLIC
74
- "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR} /swift" )
62
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /forced-${DEPENDENCY}-dep.swift
63
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR} /forced-${DEPENDENCY}-dep.swift
64
+ DEPENDS ${DEPENDENCY}
65
+ )
66
+ target_sources (${TARGET} PRIVATE
67
+ ${CMAKE_CURRENT_BINARY_DIR} /forced-${DEPENDENCY}-dep.swift
68
+ )
69
+ endforeach ()
70
+ endfunction ()
75
71
76
- add_dependencies (swiftASTGen
72
+ # TODO: Change to target_link_libraries when cmake is fixed
73
+ force_target_link_libraries (swiftASTGen PUBLIC
77
74
SwiftSyntax::SwiftBasicFormat
78
75
SwiftSyntax::SwiftParser
79
76
SwiftSyntax::SwiftParserDiagnostics
@@ -83,8 +80,13 @@ if (SWIFT_SWIFT_PARSER)
83
80
SwiftSyntax::SwiftSyntaxBuilder
84
81
SwiftSyntax::_SwiftSyntaxMacros
85
82
SwiftSyntax::SwiftCompilerSupport
83
+ )
84
+ target_link_libraries (swiftASTGen PUBLIC
86
85
swiftAST
87
86
)
88
87
88
+ target_include_directories (swiftASTGen PUBLIC
89
+ "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR} /swift" )
90
+
89
91
set_property (GLOBAL APPEND PROPERTY SWIFT_EXPORTS swiftASTGen )
90
92
endif ()
0 commit comments