[CMake] Use PRIVATE in target_link_libraries for executables
authorShoaib Meenai <smeenai@fb.com>
Tue, 5 Dec 2017 21:49:56 +0000 (21:49 +0000)
committerShoaib Meenai <smeenai@fb.com>
Tue, 5 Dec 2017 21:49:56 +0000 (21:49 +0000)
commitd806af3499c5fcc6df0e014a9739bd99ac01cf7d
treeb9e1aa4cc351b40bcd80adce223f90816e15525b
parent15fd4404103ee5734db9956cb36f565746ae6e44
[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
79 files changed:
clang-tools-extra/change-namespace/tool/CMakeLists.txt
clang-tools-extra/clang-apply-replacements/tool/CMakeLists.txt
clang-tools-extra/clang-move/tool/CMakeLists.txt
clang-tools-extra/clang-query/tool/CMakeLists.txt
clang-tools-extra/clang-reorder-fields/tool/CMakeLists.txt
clang-tools-extra/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/clangd/tool/CMakeLists.txt
clang-tools-extra/include-fixer/find-all-symbols/tool/CMakeLists.txt
clang-tools-extra/include-fixer/tool/CMakeLists.txt
clang-tools-extra/modularize/CMakeLists.txt
clang-tools-extra/pp-trace/CMakeLists.txt
clang-tools-extra/tool-template/CMakeLists.txt
clang-tools-extra/unittests/change-namespace/CMakeLists.txt
clang-tools-extra/unittests/clang-apply-replacements/CMakeLists.txt
clang-tools-extra/unittests/clang-move/CMakeLists.txt
clang-tools-extra/unittests/clang-query/CMakeLists.txt
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
clang-tools-extra/unittests/clangd/CMakeLists.txt
clang-tools-extra/unittests/include-fixer/CMakeLists.txt
clang-tools-extra/unittests/include-fixer/find-all-symbols/CMakeLists.txt
clang/examples/clang-interpreter/CMakeLists.txt
clang/tools/arcmt-test/CMakeLists.txt
clang/tools/c-arcmt-test/CMakeLists.txt
clang/tools/c-index-test/CMakeLists.txt
clang/tools/clang-check/CMakeLists.txt
clang/tools/clang-diff/CMakeLists.txt
clang/tools/clang-format/CMakeLists.txt
clang/tools/clang-func-mapping/CMakeLists.txt
clang/tools/clang-fuzzer/CMakeLists.txt
clang/tools/clang-import-test/CMakeLists.txt
clang/tools/clang-offload-bundler/CMakeLists.txt
clang/tools/clang-refactor/CMakeLists.txt
clang/tools/clang-rename/CMakeLists.txt
clang/tools/diagtool/CMakeLists.txt
clang/tools/driver/CMakeLists.txt
clang/unittests/AST/CMakeLists.txt
clang/unittests/ASTMatchers/CMakeLists.txt
clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt
clang/unittests/Basic/CMakeLists.txt
clang/unittests/CodeGen/CMakeLists.txt
clang/unittests/CrossTU/CMakeLists.txt
clang/unittests/Driver/CMakeLists.txt
clang/unittests/Format/CMakeLists.txt
clang/unittests/Frontend/CMakeLists.txt
clang/unittests/Lex/CMakeLists.txt
clang/unittests/Rename/CMakeLists.txt
clang/unittests/Rewrite/CMakeLists.txt
clang/unittests/Sema/CMakeLists.txt
clang/unittests/StaticAnalyzer/CMakeLists.txt
clang/unittests/Tooling/CMakeLists.txt
clang/unittests/libclang/CMakeLists.txt
lld/tools/lld/CMakeLists.txt
lld/unittests/DriverTests/CMakeLists.txt
lld/unittests/MachOTests/CMakeLists.txt
lldb/cmake/modules/AddLLDB.cmake
lldb/unittests/CMakeLists.txt
lldb/unittests/Interpreter/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/cmake/modules/LLVM-Config.cmake
llvm/examples/ParallelJIT/CMakeLists.txt
llvm/tools/bugpoint/CMakeLists.txt
llvm/tools/dsymutil/CMakeLists.txt
llvm/tools/llvm-cfi-verify/CMakeLists.txt
llvm/tools/llvm-objdump/CMakeLists.txt
llvm/tools/opt/CMakeLists.txt
llvm/unittests/DebugInfo/CodeView/CMakeLists.txt
llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
llvm/unittests/DebugInfo/MSF/CMakeLists.txt
llvm/unittests/DebugInfo/PDB/CMakeLists.txt
llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
llvm/unittests/ProfileData/CMakeLists.txt
llvm/unittests/Support/CMakeLists.txt
llvm/unittests/Support/DynamicLibrary/CMakeLists.txt
llvm/unittests/tools/llvm-cfi-verify/CMakeLists.txt
llvm/utils/FileCheck/CMakeLists.txt
llvm/utils/not/CMakeLists.txt
llvm/utils/yaml-bench/CMakeLists.txt
polly/unittests/CMakeLists.txt