Skip to content
This repository was archived by the owner on Feb 26, 2019. It is now read-only.

Commit 456e35c

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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319840 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3b1d962 commit 456e35c

File tree

32 files changed

+36
-2
lines changed

32 files changed

+36
-2
lines changed

examples/clang-interpreter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_dependencies(clang-interpreter
1717
)
1818

1919
target_link_libraries(clang-interpreter
20+
PRIVATE
2021
clangBasic
2122
clangCodeGen
2223
clangDriver

tools/arcmt-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_executable(arcmt-test
77
)
88

99
target_link_libraries(arcmt-test
10+
PRIVATE
1011
clangARCMigrate
1112
clangBasic
1213
clangFrontend

tools/c-arcmt-test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ add_clang_executable(c-arcmt-test
44

55
if (LLVM_BUILD_STATIC)
66
target_link_libraries(c-arcmt-test
7+
PRIVATE
78
libclang_static
89
)
910
else()
1011
target_link_libraries(c-arcmt-test
12+
PRIVATE
1113
libclang
1214
)
1315
endif()

tools/c-index-test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (LLVM_BUILD_STATIC)
2222
)
2323
else()
2424
target_link_libraries(c-index-test
25+
PRIVATE
2526
libclang
2627
clangAST
2728
clangBasic
@@ -39,7 +40,7 @@ set_target_properties(c-index-test
3940
# If libxml2 is available, make it available for c-index-test.
4041
if (CLANG_HAVE_LIBXML)
4142
include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
42-
target_link_libraries(c-index-test ${LIBXML2_LIBRARIES})
43+
target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
4344
endif()
4445

4546
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)

tools/clang-check/CMakeLists.txt

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

1111
target_link_libraries(clang-check
12+
PRIVATE
1213
clangAST
1314
clangBasic
1415
clangDriver

tools/clang-diff/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_executable(clang-diff
77
)
88

99
target_link_libraries(clang-diff
10+
PRIVATE
1011
clangBasic
1112
clangFrontend
1213
clangTooling

tools/clang-format/CMakeLists.txt

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

1414
target_link_libraries(clang-format
15+
PRIVATE
1516
${CLANG_FORMAT_LIB_DEPS}
1617
)
1718

tools/clang-func-mapping/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_clang_executable(clang-func-mapping
1010
)
1111

1212
target_link_libraries(clang-func-mapping
13+
PRIVATE
1314
clangAST
1415
clangBasic
1516
clangCrossTU

tools/clang-fuzzer/CMakeLists.txt

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

6868
target_link_libraries(clang-fuzzer
69+
PRIVATE
6970
${LLVM_LIB_FUZZING_ENGINE}
7071
clangHandleCXX
7172
)

tools/clang-import-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
2424
)
2525

2626
target_link_libraries(clang-import-test
27+
PRIVATE
2728
${CLANG_IMPORT_TEST_LIB_DEPS}
2829
)

tools/clang-offload-bundler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
1818
add_dependencies(clang clang-offload-bundler)
1919

2020
target_link_libraries(clang-offload-bundler
21+
PRIVATE
2122
${CLANG_OFFLOAD_BUNDLER_LIB_DEPS}
2223
)
2324

tools/clang-refactor/CMakeLists.txt

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

1111
target_link_libraries(clang-refactor
12+
PRIVATE
1213
clangAST
1314
clangBasic
1415
clangFormat

tools/clang-rename/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
66
add_clang_tool(clang-rename ClangRename.cpp)
77

88
target_link_libraries(clang-rename
9+
PRIVATE
910
clangBasic
1011
clangFrontend
1112
clangRewrite

tools/diagtool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_clang_executable(diagtool
1313
)
1414

1515
target_link_libraries(diagtool
16+
PRIVATE
1617
clangBasic
1718
clangFrontend
1819
)

tools/driver/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_clang_tool(clang
3838
)
3939

4040
target_link_libraries(clang
41+
PRIVATE
4142
clangBasic
4243
clangCodeGen
4344
clangDriver
@@ -85,6 +86,7 @@ if (APPLE)
8586

8687
set(TOOL_INFO_PLIST_OUT "${CMAKE_CURRENT_BINARY_DIR}/${TOOL_INFO_PLIST}")
8788
target_link_libraries(clang
89+
PRIVATE
8890
"-Wl,-sectcreate,__TEXT,__info_plist,${TOOL_INFO_PLIST_OUT}")
8991
configure_file("${TOOL_INFO_PLIST}.in" "${TOOL_INFO_PLIST_OUT}" @ONLY)
9092

@@ -127,5 +129,5 @@ if(CLANG_ORDER_FILE AND (LD64_EXECUTABLE OR GOLD_EXECUTABLE))
127129
endif()
128130

129131
if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
130-
target_link_libraries(clang Polly)
132+
target_link_libraries(clang PRIVATE Polly)
131133
endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)

unittests/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_clang_unittest(ASTTests
2121
)
2222

2323
target_link_libraries(ASTTests
24+
PRIVATE
2425
clangAST
2526
clangASTMatchers
2627
clangBasic

unittests/ASTMatchers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_clang_unittest(ASTMatchersTests
1818
ASTMatchersTraversalTest.cpp)
1919

2020
target_link_libraries(ASTMatchersTests
21+
PRIVATE
2122
clangAST
2223
clangASTMatchers
2324
clangBasic

unittests/ASTMatchers/Dynamic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
88
RegistryTest.cpp)
99

1010
target_link_libraries(DynamicASTMatchersTests
11+
PRIVATE
1112
clangAST
1213
clangASTMatchers
1314
clangBasic

unittests/Analysis/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_unittest(ClangAnalysisTests
88
)
99

1010
target_link_libraries(ClangAnalysisTests
11+
PRIVATE
1112
clangAnalysis
1213
clangAST
1314
clangASTMatchers

unittests/Basic/CMakeLists.txt

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

1414
target_link_libraries(BasicTests
15+
PRIVATE
1516
clangBasic
1617
clangLex
1718
)

unittests/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_clang_unittest(ClangCodeGenTests
1010
)
1111

1212
target_link_libraries(ClangCodeGenTests
13+
PRIVATE
1314
clangAST
1415
clangBasic
1516
clangCodeGen

unittests/CrossTU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_clang_unittest(CrossTUTests
88
)
99

1010
target_link_libraries(CrossTUTests
11+
PRIVATE
1112
clangAST
1213
clangBasic
1314
clangCrossTU

unittests/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_clang_unittest(ClangDriverTests
1111
)
1212

1313
target_link_libraries(ClangDriverTests
14+
PRIVATE
1415
clangDriver
1516
clangBasic
1617
)

unittests/Format/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_clang_unittest(FormatTests
2020
)
2121

2222
target_link_libraries(FormatTests
23+
PRIVATE
2324
clangBasic
2425
clangFormat
2526
clangFrontend

unittests/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_clang_unittest(FrontendTests
1111
PCHPreambleTest.cpp
1212
)
1313
target_link_libraries(FrontendTests
14+
PRIVATE
1415
clangAST
1516
clangBasic
1617
clangFrontend

unittests/Lex/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_clang_unittest(LexTests
1010
)
1111

1212
target_link_libraries(LexTests
13+
PRIVATE
1314
clangAST
1415
clangBasic
1516
clangLex

unittests/Rename/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_clang_unittest(ClangRenameTests
1414
)
1515

1616
target_link_libraries(ClangRenameTests
17+
PRIVATE
1718
clangAST
1819
clangASTMatchers
1920
clangBasic

unittests/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ add_clang_unittest(RewriteTests
66
RewriteBufferTest.cpp
77
)
88
target_link_libraries(RewriteTests
9+
PRIVATE
910
clangRewrite
1011
)

unittests/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_unittest(SemaTests
77
)
88

99
target_link_libraries(SemaTests
10+
PRIVATE
1011
clangAST
1112
clangBasic
1213
clangFrontend

unittests/StaticAnalyzer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_clang_unittest(StaticAnalysisTests
77
)
88

99
target_link_libraries(StaticAnalysisTests
10+
PRIVATE
1011
clangBasic
1112
clangAnalysis
1213
clangStaticAnalyzerCore

unittests/Tooling/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_clang_unittest(ToolingTests
3535
)
3636

3737
target_link_libraries(ToolingTests
38+
PRIVATE
3839
clangAST
3940
clangASTMatchers
4041
clangBasic

unittests/libclang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ add_clang_unittest(libclangTests
33
)
44

55
target_link_libraries(libclangTests
6+
PRIVATE
67
libclang
78
)

0 commit comments

Comments
 (0)