Skip to content

Commit 717c4d3

Browse files
committed
SourceKit: remove LINK_LIBS (NFC)
This removes the custom `LINK_LIBS` in favour of `target_link_libraries`. This simplifies the custom functions that we have for adding libraries, makes it easier to query the information from ninja and will allow us to slowly remove more of the custom logic for building the products.
1 parent 7722d43 commit 717c4d3

File tree

11 files changed

+88
-86
lines changed

11 files changed

+88
-86
lines changed

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ endfunction()
8787
#
8888
# Usage:
8989
# add_sourcekit_library(name # Name of the library
90-
# [LINK_LIBS dep1 ...] # Libraries this library will be linked with
9190
# [DEPENDS dep1 ...] # Targets this library depends on
9291
# [LLVM_LINK_COMPONENTS comp1 ...] # LLVM components this library depends on
9392
# [INSTALL_IN_COMPONENT comp] # The Swift installation component that this library belongs to.
@@ -97,7 +96,7 @@ macro(add_sourcekit_library name)
9796
cmake_parse_arguments(SOURCEKITLIB
9897
"SHARED"
9998
"INSTALL_IN_COMPONENT"
100-
"HEADERS;LINK_LIBS;DEPENDS;LLVM_LINK_COMPONENTS"
99+
"HEADERS;DEPENDS;LLVM_LINK_COMPONENTS"
101100
${ARGN})
102101
set(srcs ${SOURCEKITLIB_UNPARSED_ARGUMENTS})
103102

@@ -149,21 +148,6 @@ macro(add_sourcekit_library name)
149148
add_dependencies(${name} ${SOURCEKITLIB_DEPENDS})
150149
endif(SOURCEKITLIB_DEPENDS)
151150

152-
set(prefixed_link_libraries)
153-
foreach(dep ${SOURCEKITLIB_LINK_LIBS})
154-
if("${dep}" MATCHES "^clang")
155-
set(dep "${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${dep}${CMAKE_STATIC_LIBRARY_SUFFIX}")
156-
endif()
157-
list(APPEND prefixed_link_libraries "${dep}")
158-
endforeach()
159-
set(SOURCEKITLIB_LINK_LIBS "${prefixed_link_libraries}")
160-
161-
if("${libkind}" STREQUAL "SHARED")
162-
target_link_libraries("${name}" PRIVATE ${SOURCEKITLIB_LINK_LIBS})
163-
else()
164-
target_link_libraries("${name}" INTERFACE ${SOURCEKITLIB_LINK_LIBS})
165-
endif()
166-
167151
swift_common_llvm_config(${name} ${SOURCEKITLIB_LLVM_LINK_COMPONENTS})
168152

169153
if(SOURCEKITLIB_SHARED AND EXPORTED_SYMBOL_FILE)
@@ -213,7 +197,6 @@ endmacro()
213197
#
214198
# Usage:
215199
# add_sourcekit_executable(name # Name of the executable
216-
# [LINK_LIBS dep1 ...] # Libraries this executable depends on
217200
# [LLVM_LINK_COMPONENTS comp1 ...] # LLVM components this executable
218201
# # depends on
219202
# [EXCLUDE_FROM_ALL] # Whether to exclude this executable from
@@ -223,7 +206,7 @@ macro(add_sourcekit_executable name)
223206
cmake_parse_arguments(SOURCEKITEXE
224207
"EXCLUDE_FROM_ALL"
225208
""
226-
"LINK_LIBS;LLVM_LINK_COMPONENTS"
209+
"LLVM_LINK_COMPONENTS"
227210
${ARGN})
228211

229212
if (${SOURCEKITEXE_EXCLUDE_FROM_ALL})
@@ -244,7 +227,6 @@ macro(add_sourcekit_executable name)
244227
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
245228
endif()
246229

247-
target_link_libraries(${name} PRIVATE ${SOURCEKITEXE_LINK_LIBS})
248230
swift_common_llvm_config(${name} ${SOURCEKITEXE_LLVM_LINK_COMPONENTS})
249231
target_link_libraries(${name} PRIVATE ${LLVM_COMMON_LIBS})
250232

@@ -267,14 +249,13 @@ endmacro()
267249
#
268250
# Usage:
269251
# add_sourcekit_framework(name # Name of the framework
270-
# [LINK_LIBS dep1 ...] # Libraries this framework will link with
271252
# [LLVM_LINK_COMPONENTS comp1 ...] # LLVM components this framework depends on
272253
# [MODULEMAP modulemap] # Module map file for this framework
273254
# [INSTALL_IN_COMPONENT comp] # The Swift installation component that this framework belongs to.
274255
# source1 [source2 source3 ...]) # Sources to add into this framework
275256
macro(add_sourcekit_framework name)
276257
cmake_parse_arguments(SOURCEKITFW
277-
"" "MODULEMAP;INSTALL_IN_COMPONENT" "LINK_LIBS;LLVM_LINK_COMPONENTS" ${ARGN})
258+
"" "MODULEMAP;INSTALL_IN_COMPONENT" "LLVM_LINK_COMPONENTS" ${ARGN})
278259
set(srcs ${SOURCEKITFW_UNPARSED_ARGUMENTS})
279260

280261
set(lib_dir ${SOURCEKIT_LIBRARY_OUTPUT_INTDIR})
@@ -316,7 +297,6 @@ macro(add_sourcekit_framework name)
316297
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
317298
endif(LLVM_COMMON_DEPENDS)
318299

319-
target_link_libraries(${name} PRIVATE ${SOURCEKITFW_LINK_LIBS})
320300
swift_common_llvm_config(${name} ${SOURCEKITFW_LLVM_LINK_COMPONENTS})
321301

322302
if (EXPORTED_SYMBOL_FILE)
@@ -394,11 +374,10 @@ endmacro(add_sourcekit_framework)
394374
#
395375
# Usage:
396376
# add_sourcekit_xpc_service(name # Name of the XPC service
397-
# [LINK_LIBS dep1 ...] # Libraries this service will link with
398377
# [LLVM_LINK_COMPONENTS comp1 ...] # LLVM components this service depends on
399378
# source1 [source2 source3 ...]) # Sources to add into this service
400379
macro(add_sourcekit_xpc_service name framework_target)
401-
cmake_parse_arguments(SOURCEKITXPC "" "" "LINK_LIBS;LLVM_LINK_COMPONENTS" ${ARGN})
380+
cmake_parse_arguments(SOURCEKITXPC "" "" "LLVM_LINK_COMPONENTS" ${ARGN})
402381
set(srcs ${SOURCEKITXPC_UNPARSED_ARGUMENTS})
403382

404383
set(lib_dir ${SOURCEKIT_LIBRARY_OUTPUT_INTDIR})
@@ -439,7 +418,6 @@ macro(add_sourcekit_xpc_service name framework_target)
439418
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
440419
endif(LLVM_COMMON_DEPENDS)
441420

442-
target_link_libraries(${name} PRIVATE ${SOURCEKITXPC_LINK_LIBS})
443421
swift_common_llvm_config(${name} ${SOURCEKITXPC_LLVM_LINK_COMPONENTS})
444422
target_link_libraries(${name} PRIVATE ${LLVM_COMMON_LIBS})
445423

tools/SourceKit/lib/Core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ add_sourcekit_library(SourceKitCore
33
Context.cpp
44
LangSupport.cpp
55
NotificationCenter.cpp
6-
LINK_LIBS SourceKitSupport
76
)
7+
target_link_libraries(SourceKitCore PRIVATE
8+
SourceKitSupport)

tools/SourceKit/lib/Support/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ add_sourcekit_library(SourceKitSupport
55
ImmutableTextBuffer.cpp
66
ThreadSafeRefCntPtr.cpp
77
Tracing.cpp
8-
UIDRegistry.cpp
9-
LINK_LIBS swiftBasic swiftSyntax clangBasic clangRewrite
10-
)
8+
UIDRegistry.cpp)
9+
target_link_libraries(SourceKitSupport PRIVATE
10+
swiftBasic
11+
swiftSyntax
12+
clangBasic
13+
clangRewrite)
1114
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
1215
target_link_libraries(SourceKitSupport INTERFACE dispatch BlocksRuntime)
1316
endif()

tools/SourceKit/lib/SwiftLang/CMakeLists.txt

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,6 @@ add_sourcekit_library(SourceKitSwiftLang
1010
SwiftLangSupport.cpp
1111
SwiftSourceDocInfo.cpp
1212
SwiftTypeContextInfo.cpp
13-
LINK_LIBS
14-
SourceKitCore swiftDriver swiftFrontend
15-
swiftClangImporter swiftIDE
16-
swiftAST swiftMarkup swiftParse swiftParseSIL swiftSIL swiftSILGen
17-
swiftSILOptimizer swiftIRGen swiftSema swiftBasic swiftSerialization
18-
swiftSyntax swiftOption libcmark_static
19-
# Clang dependencies.
20-
clangIndex
21-
clangFormat
22-
clangToolingCore
23-
clangFrontendTool
24-
clangFrontend
25-
clangDriver
26-
clangCodeGen
27-
clangSerialization
28-
clangParse
29-
clangSema
30-
clangAnalysis
31-
clangEdit
32-
clangRewriteFrontend
33-
clangRewrite
34-
clangLex
35-
clangAST
36-
clangAPINotes
37-
clangBasic
3813
LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD}
3914
bitreader
4015
bitwriter
@@ -49,5 +24,43 @@ add_sourcekit_library(SourceKitSwiftLang
4924
objcarcopts
5025
profiledata
5126
)
52-
27+
target_link_libraries(SourceKitSwiftLang PRIVATE
28+
SourceKitCore
29+
swiftDriver
30+
swiftFrontend
31+
swiftClangImporter
32+
swiftIDE
33+
swiftAST
34+
swiftMarkup
35+
swiftParse
36+
swiftParseSIL
37+
swiftSIL
38+
swiftSILGen
39+
swiftSILOptimizer
40+
swiftIRGen
41+
swiftSema
42+
swiftBasic
43+
swiftSerialization
44+
swiftSyntax
45+
swiftOption
46+
libcmark_static
47+
# Clang dependencies.
48+
clangIndex
49+
clangFormat
50+
clangToolingCore
51+
clangFrontendTool
52+
clangFrontend
53+
clangDriver
54+
clangCodeGen
55+
clangSerialization
56+
clangParse
57+
clangSema
58+
clangAnalysis
59+
clangEdit
60+
clangRewriteFrontend
61+
clangRewrite
62+
clangLex
63+
clangAST
64+
clangAPINotes
65+
clangBasic)
5366
add_dependencies(SourceKitSwiftLang clang-tablegen-targets)

tools/SourceKit/tools/complete-test/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
2-
set(SOURCEKITD_TEST_LINK_LIBS sourcekitdInProc)
3-
else()
4-
set(SOURCEKITD_TEST_LINK_LIBS sourcekitd)
5-
endif()
6-
71
add_sourcekit_executable(complete-test
82
complete-test.cpp
9-
LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS}
10-
LLVM_LINK_COMPONENTS support option coverage lto
3+
LLVM_LINK_COMPONENTS option coverage lto
114
)
5+
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
6+
target_link_libraries(complete-test PRIVATE sourcekitdInProc)
7+
else()
8+
target_link_libraries(complete-test PRIVATE sourcekitd)
9+
endif()
1210
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
1311
target_link_libraries(complete-test PRIVATE dispatch BlocksRuntime)
1412
endif()

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} edit)
22
check_symbol_exists(el_wgets "histedit.h" HAVE_UNICODE_LIBEDIT)
33

44
if(HAVE_UNICODE_LIBEDIT)
5-
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
6-
set(SOURCEKITD_REPL_LINK_LIBS sourcekitdInProc)
7-
else()
8-
set(SOURCEKITD_REPL_LINK_LIBS sourcekitd)
9-
endif()
10-
115
add_sourcekit_executable(sourcekitd-repl
126
sourcekitd-repl.cpp
13-
LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} edit
14-
LLVM_LINK_COMPONENTS support coverage lto
7+
LLVM_LINK_COMPONENTS coverage lto
158
)
9+
target_link_libraries(sourcekitd-repl PRIVATE edit)
10+
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
11+
target_link_libraries(sourcekitd-repl PRIVATE sourcekitdInProc)
12+
else()
13+
target_link_libraries(sourcekitd-repl PRIVATE sourcekitd)
14+
endif()
1615
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
1716
target_link_libraries(sourcekitd-repl PRIVATE dispatch BlocksRuntime)
1817
endif()

tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ set(LLVM_TARGET_DEFINITIONS Options.td)
22
swift_tablegen(Options.inc -gen-opt-parser-defs)
33
swift_add_public_tablegen_target(sourcekitdTestOptionsTableGen)
44

5-
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
6-
set(SOURCEKITD_TEST_LINK_LIBS sourcekitdInProc)
7-
else()
8-
set(SOURCEKITD_TEST_LINK_LIBS sourcekitd)
9-
endif()
10-
115
add_sourcekit_executable(sourcekitd-test
126
sourcekitd-test.cpp
137
TestOptions.cpp
14-
LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} SourceKitSupport
15-
clangRewrite clangLex clangBasic
16-
LLVM_LINK_COMPONENTS core support option coverage lto
8+
LLVM_LINK_COMPONENTS core option coverage lto
179
)
10+
target_link_libraries(sourcekitd-test PRIVATE
11+
SourceKitSupport
12+
clangRewrite
13+
clangLex
14+
clangBasic)
15+
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
16+
target_link_libraries(sourcekitd-test PRIVATE sourcekitdInProc)
17+
else()
18+
target_link_libraries(sourcekitd-test PRIVATE sourcekitd)
19+
endif()
1820
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
1921
target_link_libraries(sourcekitd-test PRIVATE dispatch BlocksRuntime)
2022
endif()

tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ option(SOURCEKITD_BUILD_STATIC_INPROC
55

66
set(sourcekitdInProc_args
77
sourcekitdInProc.cpp
8-
LINK_LIBS SourceKitSwiftLang sourcekitdAPI
98
LLVM_LINK_COMPONENTS support coverage
109
)
1110

@@ -36,6 +35,9 @@ else()
3635
SHARED
3736
)
3837
endif()
38+
target_link_libraries(sourcekitdInProc PRIVATE
39+
SourceKitSwiftLang
40+
sourcekitdAPI)
3941

4042
# While it is possible to build this as a static library,
4143
# to get the runtime paths correct, it must be linked into a binary
@@ -46,6 +48,9 @@ if (SOURCEKITD_BUILD_STATIC_INPROC)
4648
${SOURCEKITD_SOURCE_DIR}/include/sourcekitd/sourcekitd.h
4749
${sourcekitdInProc_args}
4850
)
51+
target_link_libraries(sourcekitdInProc_Static PRIVATE
52+
SourceKitSwiftLang
53+
sourcekitdAPI)
4954
endif()
5055

5156
if (SOURCEKIT_BUILT_STANDALONE)

tools/SourceKit/tools/sourcekitd/bin/XPC/Client/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ set(EXPORTED_SYMBOL_FILE "${SOURCEKITD_SOURCE_DIR}/bin/sourcekitd.exports")
1010
add_sourcekit_framework(sourcekitd
1111
${public_headers}
1212
sourcekitd.cpp
13-
LINK_LIBS sourcekitdAPI
1413
LLVM_LINK_COMPONENTS support
1514
MODULEMAP module.modulemap
1615
INSTALL_IN_COMPONENT sourcekit-xpc-service
1716
)
17+
target_link_libraries(sourcekitd PRIVATE sourcekitdAPI)
1818

1919
add_definitions(-DSOURCEKIT_XPCSERVICE_IDENTIFIER="com.apple.SourceKitService.${SOURCEKIT_VERSION_STRING}_${SOURCEKIT_PLATFORM_NAME}")
2020

tools/SourceKit/tools/sourcekitd/bin/XPC/Service/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
if (NOT SOURCEKIT_INSTALLING_INPROC)
22
add_sourcekit_xpc_service(SourceKitService sourcekitd
33
XPCService.cpp
4-
LINK_LIBS SourceKitSwiftLang sourcekitdAPI
54
LLVM_LINK_COMPONENTS support coverage
65
)
6+
target_link_libraries(SourceKitService PRIVATE
7+
SourceKitSwiftLang
8+
sourcekitdAPI)
79
endif()
810

911
if (NOT SOURCEKIT_DEPLOYMENT_OS MATCHES "^macosx")

0 commit comments

Comments
 (0)