Skip to content

Commit 9934532

Browse files
committed
cmake: switch host libraries to use target_link_libraries
This is a follow up to the discussion on #22740 to switch the host libraries to use the `target_link_libraries` rather than the `LINK_LIBRARIES` special handling. This allows the dependency to be properly tracked by CMake and allows us to use the more modern syntax.
1 parent f820c6e commit 9934532

File tree

27 files changed

+127
-123
lines changed

27 files changed

+127
-123
lines changed

lib/AST/CMakeLists.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ add_swift_host_library(swiftAST STATIC
6464
TypeWalker.cpp
6565
USRGeneration.cpp
6666

67-
LINK_LIBRARIES
68-
swiftMarkup
69-
swiftBasic
70-
swiftSyntax
71-
7267
INTERFACE_LINK_LIBRARIES
7368
# Clang dependencies.
7469
# FIXME: Clang should really export these in some reasonable manner.
@@ -98,6 +93,10 @@ add_swift_host_library(swiftAST STATIC
9893

9994
${EXTRA_AST_FLAGS}
10095
)
96+
target_link_libraries(swiftAST PRIVATE
97+
swiftBasic
98+
swiftMarkup
99+
swiftSyntax)
101100

102101
# intrinsics_gen is the LLVM tablegen target that generates the include files
103102
# where intrinsics and attributes are declared. swiftAST depends on these

lib/ASTSectionImporter/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_swift_host_library(swiftASTSectionImporter STATIC
22
ASTSectionImporter.cpp
3-
LINK_LIBRARIES swiftBasic
43
LLVM_COMPONENT_DEPENDS core)
4+
target_link_libraries(swiftASTSectionImporter PRIVATE
5+
swiftBasic)
56

lib/Basic/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ add_swift_host_library(swiftBasic STATIC
105105
UnicodeExtendedGraphemeClusters.cpp.gyb
106106

107107
C_COMPILE_FLAGS ${UUID_INCLUDE}
108-
LINK_LIBRARIES
109-
swiftDemangling
110-
${UUID_LIBRARIES}
111108
LLVM_COMPONENT_DEPENDS support)
109+
target_link_libraries(swiftBasic PRIVATE
110+
swiftDemangling
111+
${UUID_LIBRARIES})
112112

113113
message(STATUS "Swift version: ${SWIFT_VERSION}")
114114
message(STATUS "Swift vendor: ${SWIFT_VENDOR}")

lib/ClangImporter/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ add_swift_host_library(swiftClangImporter STATIC
1616
ImportName.cpp
1717
ImportType.cpp
1818
SwiftLookupTable.cpp
19-
LINK_LIBRARIES
20-
swiftAST
21-
swiftParse
2219
)
20+
target_link_libraries(swiftClangImporter PRIVATE
21+
swiftAST
22+
swiftParse)
2323

2424
# This property is only set by calls to clang_tablegen. It will not be set on
2525
# standalone builds, so it can always be safely passed.

lib/Driver/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ set(swiftDriver_targetDefines)
1919

2020
add_swift_host_library(swiftDriver STATIC
2121
${swiftDriver_sources}
22-
DEPENDS SwiftOptions
23-
LINK_LIBRARIES swiftAST swiftBasic swiftOption)
22+
DEPENDS SwiftOptions)
23+
target_link_libraries(swiftDriver PRIVATE
24+
swiftAST
25+
swiftBasic
26+
swiftOption)
2427

2528
# Generate the static-stdlib-args.lnk file used by -static-stdlib option
2629
# for 'GenericUnix' (eg linux)

lib/Frontend/CMakeLists.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ add_swift_host_library(swiftFrontend STATIC
1111
PrintingDiagnosticConsumer.cpp
1212
SerializedDiagnosticConsumer.cpp
1313
DEPENDS
14-
SwiftOptions
15-
LINK_LIBRARIES
16-
swiftSIL
17-
swiftMigrator
18-
swiftOption
19-
swiftParseSIL
20-
swiftSILGen
21-
swiftSILOptimizer
22-
swiftSema
23-
swiftSerialization)
14+
SwiftOptions)
15+
target_link_libraries(swiftFrontend PRIVATE
16+
swiftSIL
17+
swiftMigrator
18+
swiftOption
19+
swiftParseSIL
20+
swiftSILGen
21+
swiftSILOptimizer
22+
swiftSema
23+
swiftSerialization)
2424

lib/FrontendTool/CMakeLists.txt

+16-12
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@ add_swift_host_library(swiftFrontendTool STATIC
55
TBD.cpp
66
DEPENDS
77
swift-syntax-generated-headers SwiftOptions
8-
LINK_LIBRARIES
9-
swiftIndex
10-
swiftIDE
11-
swiftTBDGen swiftIRGen swiftSIL swiftSILGen swiftSILOptimizer
12-
swiftDemangling
13-
swiftImmediate
14-
swiftSerialization
15-
swiftPrintAsObjC
16-
swiftFrontend
17-
swiftClangImporter
18-
swiftDWARFImporter
19-
swiftOption
208
INTERFACE_LINK_LIBRARIES
219
clangAPINotes
2210
clangBasic
2311
)
12+
target_link_libraries(swiftFrontendTool PRIVATE
13+
swiftClangImporter
14+
swiftDemangling
15+
swiftDWARFImporter
16+
swiftFrontend
17+
swiftIDE
18+
swiftImmediate
19+
swiftIndex
20+
swiftIRGen
21+
swiftOption
22+
swiftPrintAsObjC
23+
swiftSerialization
24+
swiftSIL
25+
swiftSILGen
26+
swiftSILOptimizer
27+
swiftTBDGen)

lib/IDE/CMakeLists.txt

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ add_swift_host_library(swiftIDE STATIC
1515
IDETypeChecking.cpp
1616
APIDigesterData.cpp
1717
SourceEntityWalker.cpp
18-
TypeContextInfo.cpp
19-
LINK_LIBRARIES
20-
swiftAST
21-
swiftFrontend
22-
swiftClangImporter
23-
swiftDWARFImporter
24-
swiftParse
25-
swiftSema
26-
swiftIndex)
18+
TypeContextInfo.cpp)
19+
target_link_libraries(swiftIDE PRIVATE
20+
swiftAST
21+
swiftClangImporter
22+
swiftDWARFImporter
23+
swiftFrontend
24+
swiftIndex
25+
swiftParse
26+
swiftSema)
2727

lib/IRGen/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ add_swift_host_library(swiftIRGen STATIC
5050
SwiftTargetInfo.cpp
5151
TypeLayoutDumper.cpp
5252
TypeLayoutVerifier.cpp
53-
LINK_LIBRARIES
54-
swiftAST
55-
swiftLLVMPasses
56-
swiftSIL
57-
swiftSILGen
58-
swiftSILOptimizer
5953

6054
INTERFACE_LINK_LIBRARIES
6155
# Clang dependencies.
@@ -67,3 +61,9 @@ add_swift_host_library(swiftIRGen STATIC
6761
target
6862
transformutils
6963
)
64+
target_link_libraries(swiftIRGen PRIVATE
65+
swiftAST
66+
swiftLLVMPasses
67+
swiftSIL
68+
swiftSILGen
69+
swiftSILOptimizer)

lib/Immediate/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
add_swift_host_library(swiftImmediate STATIC
22
Immediate.cpp
33
REPL.cpp
4-
LINK_LIBRARIES
5-
swiftIDE
6-
swiftFrontend
7-
swiftSILGen
8-
swiftSILOptimizer
9-
swiftIRGen
104
LLVM_COMPONENT_DEPENDS
115
executionengine
126
linker
137
mcjit
148
transformutils)
9+
target_link_libraries(swiftImmediate PRIVATE
10+
swiftFrontend
11+
swiftIDE
12+
swiftIRGen
13+
swiftSILGen
14+
swiftSILOptimizer)
1515

1616
if(HAVE_UNICODE_LIBEDIT)
1717
target_link_libraries(swiftImmediate PRIVATE edit)

lib/Index/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ add_swift_host_library(swiftIndex STATIC
22
Index.cpp
33
IndexDataConsumer.cpp
44
IndexRecord.cpp
5-
IndexSymbol.cpp
6-
LINK_LIBRARIES
7-
swiftAST)
5+
IndexSymbol.cpp)
6+
target_link_libraries(swiftIndex PRIVATE
7+
swiftAST)

lib/Markup/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
add_swift_host_library(swiftMarkup STATIC
22
AST.cpp
33
LineList.cpp
4-
Markup.cpp
5-
6-
LINK_LIBRARIES
7-
libcmark_static)
4+
Markup.cpp)
5+
target_link_libraries(swiftMarkup PRIVATE
6+
libcmark_static)
87
target_compile_definitions(swiftMarkup
98
PRIVATE
109
CMARK_STATIC_DEFINE)

lib/Migrator/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ add_swift_host_library(swiftMigrator STATIC
5454
Migrator.cpp
5555
MigrationState.cpp
5656
OptionalTryMigratorPass.cpp
57-
RewriteBufferEditsReceiver.cpp
58-
LINK_LIBRARIES swiftSyntax swiftIDE)
57+
RewriteBufferEditsReceiver.cpp)
58+
target_link_libraries(swiftMigrator PRIVATE
59+
swiftIDE
60+
swiftSyntax)
5961

6062
add_dependencies(swiftMigrator
6163
"symlink_migrator_data")

lib/Option/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_host_library(swiftOption STATIC
22
Options.cpp
33
SanitizerOptions.cpp
44
DEPENDS SwiftOptions
5-
LINK_LIBRARIES swiftBasic
65
FILE_DEPENDS SwiftOptions)
6+
target_link_libraries(swiftOption PRIVATE
7+
swiftBasic)
78

lib/Parse/CMakeLists.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ add_swift_host_library(swiftParse STATIC
2424
PersistentParserState.cpp
2525
Scope.cpp
2626
SyntaxParsingCache.cpp
27-
SyntaxParsingContext.cpp
28-
LINK_LIBRARIES
29-
swiftAST
30-
swiftSyntax
31-
)
27+
SyntaxParsingContext.cpp)
28+
target_link_libraries(swiftParse PRIVATE
29+
swiftAST
30+
swiftSyntax)
3231

3332
add_dependencies(swiftParse swift-parse-syntax-generated-headers)

lib/ParseSIL/CMakeLists.txt

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
add_swift_host_library(swiftParseSIL STATIC
2-
ParseSIL.cpp
3-
LINK_LIBRARIES
4-
swiftSyntaxParse
5-
swiftSema
6-
swiftSIL
7-
)
2+
ParseSIL.cpp)
3+
target_link_libraries(swiftParseSIL PRIVATE
4+
swiftSema
5+
swiftSIL
6+
swiftSyntaxParse)
87

lib/PrintAsObjC/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
add_swift_host_library(swiftPrintAsObjC STATIC
2-
PrintAsObjC.cpp
3-
LINK_LIBRARIES
4-
swiftIDE
5-
swiftFrontend
6-
swiftClangImporter
7-
swiftAST)
2+
PrintAsObjC.cpp)
3+
target_link_libraries(swiftPrintAsObjC PRIVATE
4+
swiftAST
5+
swiftClangImporter
6+
swiftFrontend
7+
swiftIDE)
88

lib/RemoteAST/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif()
1414
add_swift_host_library(swiftRemoteAST STATIC
1515
RemoteAST.cpp
1616
InProcessMemoryReader.cpp
17-
${REMOTE_LIB_HEADERS}
18-
LINK_LIBRARIES
19-
swiftSema swiftIRGen)
17+
${REMOTE_LIB_HEADERS})
18+
target_link_libraries(swiftRemoteAST PRIVATE
19+
swiftIRGen
20+
swiftSema)

lib/SIL/CMakeLists.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ add_swift_host_library(swiftSIL STATIC
4646
SILWitnessTable.cpp
4747
TypeLowering.cpp
4848
ValueOwnership.cpp
49-
ValueUtils.cpp
50-
LINK_LIBRARIES
51-
swiftSerialization
52-
swiftSema
53-
)
49+
ValueUtils.cpp)
50+
target_link_libraries(swiftSIL PRIVATE
51+
swiftSema
52+
swiftSerialization)
5453

5554
# intrinsics_gen is the LLVM tablegen target that generates the include files
5655
# where intrinsics and attributes are declared. swiftSIL depends on these

lib/SILGen/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ add_swift_host_library(swiftSILGen STATIC
2929
SILGenProlog.cpp
3030
SILGenStmt.cpp
3131
SILGenThunk.cpp
32-
SILGenType.cpp
33-
LINK_LIBRARIES
34-
swiftSIL
35-
)
32+
SILGenType.cpp)
33+
target_link_libraries(swiftSILGen PRIVATE
34+
swiftSIL)

lib/SILOptimizer/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ add_subdirectory(UtilityPasses)
3434
add_subdirectory(Utils)
3535

3636
add_swift_host_library(swiftSILOptimizer STATIC
37-
${SILOPTIMIZER_SOURCES}
38-
LINK_LIBRARIES swiftSIL)
37+
${SILOPTIMIZER_SOURCES})
38+
target_link_libraries(swiftSILOptimizer PRIVATE
39+
swiftSIL)

lib/Sema/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ add_swift_host_library(swiftSema STATIC
5959
TypeCheckSwitchStmt.cpp
6060
TypeCheckType.cpp
6161
TypeChecker.cpp
62-
LINK_LIBRARIES
63-
swiftParse
64-
swiftAST
65-
swiftSerialization
66-
${EXTRA_TYPECHECKER_FLAGS}
67-
)
62+
63+
${EXTRA_TYPECHECKER_FLAGS})
64+
target_link_libraries(swiftSema PRIVATE
65+
swiftAST
66+
swiftParse
67+
swiftSerialization)
6868

lib/Serialization/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_swift_host_library(swiftSerialization STATIC
66
SerializedModuleLoader.cpp
77
SerializedSILLoader.cpp
88
SerializeDoc.cpp
9-
SerializeSIL.cpp
10-
LINK_LIBRARIES
11-
swiftClangImporter)
9+
SerializeSIL.cpp)
10+
target_link_libraries(swiftSerialization PRIVATE
11+
swiftClangImporter)
1212

lib/SwiftDemangle/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ add_swift_host_library(swiftDemangle
22
SHARED
33
SwiftDemangle.cpp
44
MangleHack.cpp
5-
LINK_LIBRARIES
6-
swiftDemangling
75
C_COMPILE_FLAGS
86
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1)
7+
target_link_libraries(swiftDemangle PRIVATE
8+
swiftDemangling)
99

1010
swift_install_in_component(compiler
1111
TARGETS swiftDemangle

lib/SyntaxParse/CMakeLists.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
add_swift_host_library(swiftSyntaxParse STATIC
22
RawSyntaxTokenCache.cpp
3-
SyntaxTreeCreator.cpp
4-
LINK_LIBRARIES
5-
swiftParse
6-
swiftSyntax
7-
)
3+
SyntaxTreeCreator.cpp)
4+
target_link_libraries(swiftSyntaxParse PRIVATE
5+
swiftParse
6+
swiftSyntax)

0 commit comments

Comments
 (0)