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
)
target_link_libraries(clang-interpreter
+ PRIVATE
clangBasic
clangCodeGen
clangDriver
)
target_link_libraries(arcmt-test
+ PRIVATE
clangARCMigrate
clangBasic
clangFrontend
if (LLVM_BUILD_STATIC)
target_link_libraries(c-arcmt-test
+ PRIVATE
libclang_static
)
else()
target_link_libraries(c-arcmt-test
+ PRIVATE
libclang
)
endif()
)
else()
target_link_libraries(c-index-test
+ PRIVATE
libclang
clangAST
clangBasic
# 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)
)
target_link_libraries(clang-check
+ PRIVATE
clangAST
clangBasic
clangDriver
)
target_link_libraries(clang-diff
+ PRIVATE
clangBasic
clangFrontend
clangTooling
)
target_link_libraries(clang-format
+ PRIVATE
${CLANG_FORMAT_LIB_DEPS}
)
)
target_link_libraries(clang-func-mapping
+ PRIVATE
clangAST
clangBasic
clangCrossTU
)
target_link_libraries(clang-fuzzer
+ PRIVATE
${LLVM_LIB_FUZZING_ENGINE}
clangHandleCXX
)
)
target_link_libraries(clang-import-test
+ PRIVATE
${CLANG_IMPORT_TEST_LIB_DEPS}
)
add_dependencies(clang clang-offload-bundler)
target_link_libraries(clang-offload-bundler
+ PRIVATE
${CLANG_OFFLOAD_BUNDLER_LIB_DEPS}
)
)
target_link_libraries(clang-refactor
+ PRIVATE
clangAST
clangBasic
clangFormat
add_clang_tool(clang-rename ClangRename.cpp)
target_link_libraries(clang-rename
+ PRIVATE
clangBasic
clangFrontend
clangRewrite
)
target_link_libraries(diagtool
+ PRIVATE
clangBasic
clangFrontend
)
)
target_link_libraries(clang
+ PRIVATE
clangBasic
clangCodeGen
clangDriver
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)
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)
)
target_link_libraries(ASTTests
+ PRIVATE
clangAST
clangASTMatchers
clangBasic
ASTMatchersTraversalTest.cpp)
target_link_libraries(ASTMatchersTests
+ PRIVATE
clangAST
clangASTMatchers
clangBasic
RegistryTest.cpp)
target_link_libraries(DynamicASTMatchersTests
+ PRIVATE
clangAST
clangASTMatchers
clangBasic
)
target_link_libraries(ClangAnalysisTests
+ PRIVATE
clangAnalysis
clangAST
clangASTMatchers
)
target_link_libraries(BasicTests
+ PRIVATE
clangBasic
clangLex
)
)
target_link_libraries(ClangCodeGenTests
+ PRIVATE
clangAST
clangBasic
clangCodeGen
)
target_link_libraries(CrossTUTests
+ PRIVATE
clangAST
clangBasic
clangCrossTU
)
target_link_libraries(ClangDriverTests
+ PRIVATE
clangDriver
clangBasic
)
)
target_link_libraries(FormatTests
+ PRIVATE
clangBasic
clangFormat
clangFrontend
PCHPreambleTest.cpp
)
target_link_libraries(FrontendTests
+ PRIVATE
clangAST
clangBasic
clangFrontend
)
target_link_libraries(LexTests
+ PRIVATE
clangAST
clangBasic
clangLex
)
target_link_libraries(ClangRenameTests
+ PRIVATE
clangAST
clangASTMatchers
clangBasic
RewriteBufferTest.cpp
)
target_link_libraries(RewriteTests
+ PRIVATE
clangRewrite
)
)
target_link_libraries(SemaTests
+ PRIVATE
clangAST
clangBasic
clangFrontend
)
target_link_libraries(StaticAnalysisTests
+ PRIVATE
clangBasic
clangAnalysis
clangStaticAnalyzerCore
)
target_link_libraries(ToolingTests
+ PRIVATE
clangAST
clangASTMatchers
clangBasic
)
target_link_libraries(libclangTests
+ PRIVATE
libclang
)