Skip to content

Commit d806af3

Browse files
committed
[CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables. Dependencies added in this way apply to both the target and its dependencies, i.e. they become part of the executable's link interface and are transitive. Transitive dependencies generally don't make sense for executables, since you wouldn't normally be linking against an executable. This also causes issues for generating install export files when using LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM library dependencies, which are currently added as interface dependencies. If clang is in the distribution components but the LLVM libraries it depends on aren't (which is a perfectly legitimate use case if the LLVM libraries are being built static and there are therefore no run-time dependencies on them), CMake will complain about the LLVM libraries not being in export set when attempting to generate the install export file for clang. This is reasonable behavior on CMake's part, and the right thing is for LLVM's build system to explicitly use PRIVATE dependencies for executables. Unfortunately, CMake doesn't allow you to mix and match the keyword and non-keyword target_link_libraries signatures for a single target; i.e., if a single call to target_link_libraries for a particular target uses one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must also be updated to use those keywords. This means we must do this change in a single shot. I also fully expect to have missed some instances; I tested by enabling all the projects in the monorepo (except dragonegg), and configuring both with and without shared libraries, on both Darwin and Linux, but I'm planning to rely on the buildbots for other configurations (since it should be pretty easy to fix those). Even after this change, we still have a lot of target_link_libraries calls that don't specify a scope keyword, mostly for shared libraries. I'm thinking about addressing those in a follow-up, but that's a separate change IMO. Differential Revision: https://reviews.llvm.org/D40823 llvm-svn: 319840
1 parent 15fd440 commit d806af3

File tree

79 files changed

+87
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+87
-29
lines changed

clang-tools-extra/change-namespace/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_executable(clang-change-namespace
88
ClangChangeNamespace.cpp
99
)
1010
target_link_libraries(clang-change-namespace
11+
PRIVATE
1112
clangAST
1213
clangASTMatchers
1314
clangBasic

clang-tools-extra/clang-apply-replacements/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_clang_executable(clang-apply-replacements
66
ClangApplyReplacementsMain.cpp
77
)
88
target_link_libraries(clang-apply-replacements
9+
PRIVATE
910
clangApplyReplacements
1011
clangBasic
1112
clangFormat

clang-tools-extra/clang-move/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_clang_executable(clang-move
55
)
66

77
target_link_libraries(clang-move
8+
PRIVATE
89
clangAST
910
clangASTMatchers
1011
clangBasic

clang-tools-extra/clang-query/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
22

33
add_clang_executable(clang-query ClangQuery.cpp)
44
target_link_libraries(clang-query
5+
PRIVATE
56
clangAST
67
clangASTMatchers
78
clangBasic

clang-tools-extra/clang-reorder-fields/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_clang_tool(clang-reorder-fields ClangReorderFields.cpp)
22

33
target_link_libraries(clang-reorder-fields
4+
PRIVATE
45
clangBasic
56
clangFrontend
67
clangReorderFields

clang-tools-extra/clang-tidy/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_dependencies(clang-tidy
1212
clang-headers
1313
)
1414
target_link_libraries(clang-tidy
15+
PRIVATE
1516
clangAST
1617
clangASTMatchers
1718
clangBasic

clang-tools-extra/clangd/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
99
)
1010

1111
target_link_libraries(clangd
12+
PRIVATE
1213
clangBasic
1314
clangDaemon
1415
clangFormat

clang-tools-extra/include-fixer/find-all-symbols/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_clang_executable(find-all-symbols
55
)
66

77
target_link_libraries(find-all-symbols
8+
PRIVATE
89
clangAST
910
clangASTMatchers
1011
clangBasic

clang-tools-extra/include-fixer/tool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_clang_executable(clang-include-fixer
55
)
66

77
target_link_libraries(clang-include-fixer
8+
PRIVATE
89
clangBasic
910
clangFormat
1011
clangFrontend

clang-tools-extra/modularize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_clang_tool(modularize
1212
)
1313

1414
target_link_libraries(modularize
15+
PRIVATE
1516
clangAST
1617
clangBasic
1718
clangDriver

0 commit comments

Comments
 (0)