[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
This commit is contained in:
Shoaib Meenai 2017-12-05 21:49:56 +00:00
Родитель 3b1d962466
Коммит 456e35cbb3
32 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -17,6 +17,7 @@ add_dependencies(clang-interpreter
)
target_link_libraries(clang-interpreter
PRIVATE
clangBasic
clangCodeGen
clangDriver

Просмотреть файл

@ -7,6 +7,7 @@ add_clang_executable(arcmt-test
)
target_link_libraries(arcmt-test
PRIVATE
clangARCMigrate
clangBasic
clangFrontend

Просмотреть файл

@ -4,10 +4,12 @@ add_clang_executable(c-arcmt-test
if (LLVM_BUILD_STATIC)
target_link_libraries(c-arcmt-test
PRIVATE
libclang_static
)
else()
target_link_libraries(c-arcmt-test
PRIVATE
libclang
)
endif()

Просмотреть файл

@ -22,6 +22,7 @@ if (LLVM_BUILD_STATIC)
)
else()
target_link_libraries(c-index-test
PRIVATE
libclang
clangAST
clangBasic
@ -39,7 +40,7 @@ set_target_properties(c-index-test
# If libxml2 is available, make it available for c-index-test.
if (CLANG_HAVE_LIBXML)
include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
target_link_libraries(c-index-test ${LIBXML2_LIBRARIES})
target_link_libraries(c-index-test PRIVATE ${LIBXML2_LIBRARIES})
endif()
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)

Просмотреть файл

@ -9,6 +9,7 @@ add_clang_executable(clang-check
)
target_link_libraries(clang-check
PRIVATE
clangAST
clangBasic
clangDriver

Просмотреть файл

@ -7,6 +7,7 @@ add_clang_executable(clang-diff
)
target_link_libraries(clang-diff
PRIVATE
clangBasic
clangFrontend
clangTooling

Просмотреть файл

@ -12,6 +12,7 @@ set(CLANG_FORMAT_LIB_DEPS
)
target_link_libraries(clang-format
PRIVATE
${CLANG_FORMAT_LIB_DEPS}
)

Просмотреть файл

@ -10,6 +10,7 @@ add_clang_executable(clang-func-mapping
)
target_link_libraries(clang-func-mapping
PRIVATE
clangAST
clangBasic
clangCrossTU

Просмотреть файл

@ -66,6 +66,7 @@ add_clang_executable(clang-fuzzer
)
target_link_libraries(clang-fuzzer
PRIVATE
${LLVM_LIB_FUZZING_ENGINE}
clangHandleCXX
)

Просмотреть файл

@ -24,5 +24,6 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
)
target_link_libraries(clang-import-test
PRIVATE
${CLANG_IMPORT_TEST_LIB_DEPS}
)

Просмотреть файл

@ -18,6 +18,7 @@ set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
add_dependencies(clang clang-offload-bundler)
target_link_libraries(clang-offload-bundler
PRIVATE
${CLANG_OFFLOAD_BUNDLER_LIB_DEPS}
)

Просмотреть файл

@ -9,6 +9,7 @@ add_clang_tool(clang-refactor
)
target_link_libraries(clang-refactor
PRIVATE
clangAST
clangBasic
clangFormat

Просмотреть файл

@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_tool(clang-rename ClangRename.cpp)
target_link_libraries(clang-rename
PRIVATE
clangBasic
clangFrontend
clangRewrite

Просмотреть файл

@ -13,6 +13,7 @@ add_clang_executable(diagtool
)
target_link_libraries(diagtool
PRIVATE
clangBasic
clangFrontend
)

Просмотреть файл

@ -38,6 +38,7 @@ add_clang_tool(clang
)
target_link_libraries(clang
PRIVATE
clangBasic
clangCodeGen
clangDriver
@ -85,6 +86,7 @@ if (APPLE)
set(TOOL_INFO_PLIST_OUT "${CMAKE_CURRENT_BINARY_DIR}/${TOOL_INFO_PLIST}")
target_link_libraries(clang
PRIVATE
"-Wl,-sectcreate,__TEXT,__info_plist,${TOOL_INFO_PLIST_OUT}")
configure_file("${TOOL_INFO_PLIST}.in" "${TOOL_INFO_PLIST_OUT}" @ONLY)
@ -127,5 +129,5 @@ if(CLANG_ORDER_FILE AND (LD64_EXECUTABLE OR GOLD_EXECUTABLE))
endif()
if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
target_link_libraries(clang Polly)
target_link_libraries(clang PRIVATE Polly)
endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)

Просмотреть файл

@ -21,6 +21,7 @@ add_clang_unittest(ASTTests
)
target_link_libraries(ASTTests
PRIVATE
clangAST
clangASTMatchers
clangBasic

Просмотреть файл

@ -18,6 +18,7 @@ add_clang_unittest(ASTMatchersTests
ASTMatchersTraversalTest.cpp)
target_link_libraries(ASTMatchersTests
PRIVATE
clangAST
clangASTMatchers
clangBasic

Просмотреть файл

@ -8,6 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
RegistryTest.cpp)
target_link_libraries(DynamicASTMatchersTests
PRIVATE
clangAST
clangASTMatchers
clangBasic

Просмотреть файл

@ -8,6 +8,7 @@ add_clang_unittest(ClangAnalysisTests
)
target_link_libraries(ClangAnalysisTests
PRIVATE
clangAnalysis
clangAST
clangASTMatchers

Просмотреть файл

@ -12,6 +12,7 @@ add_clang_unittest(BasicTests
)
target_link_libraries(BasicTests
PRIVATE
clangBasic
clangLex
)

Просмотреть файл

@ -10,6 +10,7 @@ add_clang_unittest(ClangCodeGenTests
)
target_link_libraries(ClangCodeGenTests
PRIVATE
clangAST
clangBasic
clangCodeGen

Просмотреть файл

@ -8,6 +8,7 @@ add_clang_unittest(CrossTUTests
)
target_link_libraries(CrossTUTests
PRIVATE
clangAST
clangBasic
clangCrossTU

Просмотреть файл

@ -11,6 +11,7 @@ add_clang_unittest(ClangDriverTests
)
target_link_libraries(ClangDriverTests
PRIVATE
clangDriver
clangBasic
)

Просмотреть файл

@ -20,6 +20,7 @@ add_clang_unittest(FormatTests
)
target_link_libraries(FormatTests
PRIVATE
clangBasic
clangFormat
clangFrontend

Просмотреть файл

@ -11,6 +11,7 @@ add_clang_unittest(FrontendTests
PCHPreambleTest.cpp
)
target_link_libraries(FrontendTests
PRIVATE
clangAST
clangBasic
clangFrontend

Просмотреть файл

@ -10,6 +10,7 @@ add_clang_unittest(LexTests
)
target_link_libraries(LexTests
PRIVATE
clangAST
clangBasic
clangLex

Просмотреть файл

@ -14,6 +14,7 @@ add_clang_unittest(ClangRenameTests
)
target_link_libraries(ClangRenameTests
PRIVATE
clangAST
clangASTMatchers
clangBasic

Просмотреть файл

@ -6,5 +6,6 @@ add_clang_unittest(RewriteTests
RewriteBufferTest.cpp
)
target_link_libraries(RewriteTests
PRIVATE
clangRewrite
)

Просмотреть файл

@ -7,6 +7,7 @@ add_clang_unittest(SemaTests
)
target_link_libraries(SemaTests
PRIVATE
clangAST
clangBasic
clangFrontend

Просмотреть файл

@ -7,6 +7,7 @@ add_clang_unittest(StaticAnalysisTests
)
target_link_libraries(StaticAnalysisTests
PRIVATE
clangBasic
clangAnalysis
clangStaticAnalyzerCore

Просмотреть файл

@ -35,6 +35,7 @@ add_clang_unittest(ToolingTests
)
target_link_libraries(ToolingTests
PRIVATE
clangAST
clangASTMatchers
clangBasic

Просмотреть файл

@ -3,5 +3,6 @@ add_clang_unittest(libclangTests
)
target_link_libraries(libclangTests
PRIVATE
libclang
)