[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)
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

index 62c412a..f1d8ddb 100644 (file)
@@ -8,6 +8,7 @@ add_clang_executable(clang-change-namespace
   ClangChangeNamespace.cpp
   )
 target_link_libraries(clang-change-namespace
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index b5c159d..bee5579 100644 (file)
@@ -6,6 +6,7 @@ add_clang_executable(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements
+  PRIVATE
   clangApplyReplacements
   clangBasic
   clangFormat
index 6840915..9f678bb 100644 (file)
@@ -5,6 +5,7 @@ add_clang_executable(clang-move
   )
 
 target_link_libraries(clang-move
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 52af5c8..a950931 100644 (file)
@@ -2,6 +2,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
 
 add_clang_executable(clang-query ClangQuery.cpp)
 target_link_libraries(clang-query
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 1303924..2de2cec 100644 (file)
@@ -1,6 +1,7 @@
 add_clang_tool(clang-reorder-fields ClangReorderFields.cpp)
 
 target_link_libraries(clang-reorder-fields
+  PRIVATE
   clangBasic
   clangFrontend
   clangReorderFields
index 37bb7c1..07f2671 100644 (file)
@@ -12,6 +12,7 @@ add_dependencies(clang-tidy
   clang-headers
   )
 target_link_libraries(clang-tidy
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 29fe9b6..c188761 100644 (file)
@@ -9,6 +9,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 target_link_libraries(clangd
+  PRIVATE
   clangBasic
   clangDaemon
   clangFormat
index 0bd14f7..474dc51 100644 (file)
@@ -5,6 +5,7 @@ add_clang_executable(find-all-symbols
   )
 
 target_link_libraries(find-all-symbols
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index a07a684..027e2e7 100644 (file)
@@ -5,6 +5,7 @@ add_clang_executable(clang-include-fixer
   )
 
 target_link_libraries(clang-include-fixer
+  PRIVATE
   clangBasic
   clangFormat
   clangFrontend
index 187db94..4481ce0 100644 (file)
@@ -12,6 +12,7 @@ add_clang_tool(modularize
   )
 
 target_link_libraries(modularize
+  PRIVATE
   clangAST
   clangBasic
   clangDriver
index 95a1f10..fbbe865 100644 (file)
@@ -8,6 +8,7 @@ add_clang_executable(pp-trace
   )
 
 target_link_libraries(pp-trace
+  PRIVATE
   clangAST
   clangBasic
   clangFrontend
index 125523a..6478157 100644 (file)
@@ -7,6 +7,7 @@ add_clang_executable(tool-template
   )
 
 target_link_libraries(tool-template
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 8091cf2..3745bbd 100644 (file)
@@ -16,6 +16,7 @@ add_extra_unittest(ChangeNamespaceTests
   )
 
 target_link_libraries(ChangeNamespaceTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index f06dae6..180aef1 100644 (file)
@@ -13,6 +13,7 @@ add_extra_unittest(ClangApplyReplacementsTests
   )
 
 target_link_libraries(ClangApplyReplacementsTests
+  PRIVATE
   clangApplyReplacements
   clangBasic
   clangToolingCore
index e393b29..fea15e1 100644 (file)
@@ -16,6 +16,7 @@ add_extra_unittest(ClangMoveTests
   )
 
 target_link_libraries(ClangMoveTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 3f145d2..21d82b7 100644 (file)
@@ -12,6 +12,7 @@ add_extra_unittest(ClangQueryTests
   )
 
 target_link_libraries(ClangQueryTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index c284fd7..c564453 100644 (file)
@@ -19,6 +19,7 @@ add_extra_unittest(ClangTidyTests
   ReadabilityModuleTest.cpp)
 
 target_link_libraries(ClangTidyTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index bd0aac0..98727da 100644 (file)
@@ -18,6 +18,7 @@ add_extra_unittest(ClangdTests
   )
 
 target_link_libraries(ClangdTests
+  PRIVATE
   clangBasic
   clangDaemon
   clangFormat
index caab1cb..80284a6 100644 (file)
@@ -17,6 +17,7 @@ add_extra_unittest(IncludeFixerTests
   )
 
 target_link_libraries(IncludeFixerTests
+  PRIVATE
   clangBasic
   clangFormat
   clangFrontend
index 5cd29d0..5689285 100644 (file)
@@ -13,6 +13,7 @@ add_extra_unittest(FindAllSymbolsTests
   )
 
 target_link_libraries(FindAllSymbolsTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index e7e59d9..3084238 100644 (file)
@@ -17,6 +17,7 @@ add_dependencies(clang-interpreter
   )
 
 target_link_libraries(clang-interpreter
+  PRIVATE
   clangBasic
   clangCodeGen
   clangDriver
index 0cb2c0f..2b456be 100644 (file)
@@ -7,6 +7,7 @@ add_clang_executable(arcmt-test
   )
 
 target_link_libraries(arcmt-test
+  PRIVATE
   clangARCMigrate
   clangBasic
   clangFrontend
index 8914607..08ac93c 100644 (file)
@@ -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()
index c5cb059..fdc713d 100644 (file)
@@ -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)
index 04151a8..c5ace26 100644 (file)
@@ -9,6 +9,7 @@ add_clang_executable(clang-check
   )
 
 target_link_libraries(clang-check
+  PRIVATE
   clangAST
   clangBasic
   clangDriver
index a1fc627..09bebf2 100644 (file)
@@ -7,6 +7,7 @@ add_clang_executable(clang-diff
   )
 
 target_link_libraries(clang-diff
+  PRIVATE
   clangBasic
   clangFrontend
   clangTooling
index c695ba3..a295e8c 100644 (file)
@@ -12,6 +12,7 @@ set(CLANG_FORMAT_LIB_DEPS
   )
 
 target_link_libraries(clang-format
+  PRIVATE
   ${CLANG_FORMAT_LIB_DEPS}
   )
 
index 8c10fcd..ae28e28 100644 (file)
@@ -10,6 +10,7 @@ add_clang_executable(clang-func-mapping
   )
 
 target_link_libraries(clang-func-mapping
+  PRIVATE
   clangAST
   clangBasic
   clangCrossTU
index abc5015..eab921c 100644 (file)
@@ -66,6 +66,7 @@ add_clang_executable(clang-fuzzer
   )
 
 target_link_libraries(clang-fuzzer
+  PRIVATE
   ${LLVM_LIB_FUZZING_ENGINE}
   clangHandleCXX
   )
index 85e833d..836efac 100644 (file)
@@ -24,5 +24,6 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
   )
 
 target_link_libraries(clang-import-test
+  PRIVATE
   ${CLANG_IMPORT_TEST_LIB_DEPS}
   )
index 6161d08..8718015 100644 (file)
@@ -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}
   )
 
index c20e83b..d202906 100644 (file)
@@ -9,6 +9,7 @@ add_clang_tool(clang-refactor
   )
 
 target_link_libraries(clang-refactor
+  PRIVATE
   clangAST
   clangBasic
   clangFormat
index e74f05d..9689e1c 100644 (file)
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_tool(clang-rename ClangRename.cpp)
 
 target_link_libraries(clang-rename
+  PRIVATE
   clangBasic
   clangFrontend
   clangRewrite
index 3f7d803..beb6c35 100644 (file)
@@ -13,6 +13,7 @@ add_clang_executable(diagtool
 )
 
 target_link_libraries(diagtool
+  PRIVATE
   clangBasic
   clangFrontend
   )
index 901b6d6..a0b190f 100644 (file)
@@ -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)
index 45dfa7a..9839cdb 100644 (file)
@@ -21,6 +21,7 @@ add_clang_unittest(ASTTests
   )
 
 target_link_libraries(ASTTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 5633031..a876fc2 100644 (file)
@@ -18,6 +18,7 @@ add_clang_unittest(ASTMatchersTests
   ASTMatchersTraversalTest.cpp)
 
 target_link_libraries(ASTMatchersTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 506a655..848a820 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
   RegistryTest.cpp)
 
 target_link_libraries(DynamicASTMatchersTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 62db8f6..0056f82 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(ClangAnalysisTests
   )
 
 target_link_libraries(ClangAnalysisTests
+  PRIVATE
   clangAnalysis
   clangAST
   clangASTMatchers
index 3a9f34f..b46c067 100644 (file)
@@ -12,6 +12,7 @@ add_clang_unittest(BasicTests
   )
 
 target_link_libraries(BasicTests
+  PRIVATE
   clangBasic
   clangLex
   )
index c49776b..3fb79a0 100644 (file)
@@ -10,6 +10,7 @@ add_clang_unittest(ClangCodeGenTests
   )
 
 target_link_libraries(ClangCodeGenTests
+  PRIVATE
   clangAST
   clangBasic
   clangCodeGen
index 3c479c4..652d916 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(CrossTUTests
   )
 
 target_link_libraries(CrossTUTests
+  PRIVATE
   clangAST
   clangBasic
   clangCrossTU
index 2a3f41d..b8c800f 100644 (file)
@@ -11,6 +11,7 @@ add_clang_unittest(ClangDriverTests
   )
 
 target_link_libraries(ClangDriverTests
+  PRIVATE
   clangDriver
   clangBasic
   )
index 992db0e..18e4432 100644 (file)
@@ -20,6 +20,7 @@ add_clang_unittest(FormatTests
   )
 
 target_link_libraries(FormatTests
+  PRIVATE
   clangBasic
   clangFormat
   clangFrontend
index c1f4f18..f3c4336 100644 (file)
@@ -11,6 +11,7 @@ add_clang_unittest(FrontendTests
   PCHPreambleTest.cpp
   )
 target_link_libraries(FrontendTests
+  PRIVATE
   clangAST
   clangBasic
   clangFrontend
index ef0f06c..ea6f9fd 100644 (file)
@@ -10,6 +10,7 @@ add_clang_unittest(LexTests
   )
 
 target_link_libraries(LexTests
+  PRIVATE
   clangAST
   clangBasic
   clangLex
index cecb2d3..b625a7a 100644 (file)
@@ -14,6 +14,7 @@ add_clang_unittest(ClangRenameTests
   )
 
 target_link_libraries(ClangRenameTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index bee7ff6..8edd9ba 100644 (file)
@@ -6,5 +6,6 @@ add_clang_unittest(RewriteTests
   RewriteBufferTest.cpp
   )
 target_link_libraries(RewriteTests
+  PRIVATE
   clangRewrite
   )
index c25db81..16fae82 100644 (file)
@@ -7,6 +7,7 @@ add_clang_unittest(SemaTests
   )
 
 target_link_libraries(SemaTests
+  PRIVATE
   clangAST
   clangBasic
   clangFrontend
index 4aa5efb..4ca0be5 100644 (file)
@@ -7,6 +7,7 @@ add_clang_unittest(StaticAnalysisTests
   )
 
 target_link_libraries(StaticAnalysisTests
+  PRIVATE
   clangBasic
   clangAnalysis
   clangStaticAnalyzerCore 
index f9ddf7f..557d100 100644 (file)
@@ -35,6 +35,7 @@ add_clang_unittest(ToolingTests
   )
 
 target_link_libraries(ToolingTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 1cdc45e..36f6089 100644 (file)
@@ -3,5 +3,6 @@ add_clang_unittest(libclangTests
   )
 
 target_link_libraries(libclangTests
+  PRIVATE
   libclang
   )
index d857b42..d882949 100644 (file)
@@ -7,6 +7,7 @@ add_lld_tool(lld
   )
 
 target_link_libraries(lld
+  PRIVATE
   lldCOFF
   lldDriver
   lldELF
index 91d22ca..7137d69 100644 (file)
@@ -3,6 +3,7 @@ add_lld_unittest(DriverTests
   )
 
 target_link_libraries(DriverTests
+  PRIVATE
   lldDriver
   lldMachO
   )
index 1a68348..b2b22fb 100644 (file)
@@ -7,6 +7,7 @@ add_lld_unittest(lldMachOTests
   )
 
 target_link_libraries(lldMachOTests
+  PRIVATE
   lldDriver
   lldMachO
   lldYAML
index b4b8d50..ae5fa8b 100644 (file)
@@ -92,7 +92,7 @@ function(add_lldb_executable name)
   list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
   add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})
 
-  target_link_libraries(${name} ${ARG_LINK_LIBS})
+  target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS})
   set_target_properties(${name} PROPERTIES
     FOLDER "lldb executables")
 
index bee0259..7b8bc67 100644 (file)
@@ -44,7 +44,7 @@ function(add_lldb_unittest test_name)
     POST_BUILD
     COMMAND "${CMAKE_COMMAND}" -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Inputs)
 
-  target_link_libraries(${test_name} ${ARG_LINK_LIBS})
+  target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
 endfunction()
 
 function(add_unittest_inputs test_name inputs)
index 7be092b..40fc45d 100644 (file)
@@ -8,5 +8,6 @@ add_lldb_unittest(InterpreterTests
   )
 
 target_link_libraries(InterpreterTests
+  PRIVATE
   ${PYTHON_LIBRARY}
   )
index 26da2d1..90cba50 100644 (file)
@@ -768,7 +768,7 @@ macro(add_llvm_executable name)
     # libpthreads overrides some standard library symbols, so main
     # executable must be linked with it in order to provide consistent
     # API for all shared libaries loaded by this executable.
-    target_link_libraries(${name} ${LLVM_PTHREAD_LIB})
+    target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
   endif()
 endmacro(add_llvm_executable name)
 
@@ -1093,7 +1093,7 @@ function(add_unittest test_suite test_name)
   # libpthreads overrides some standard library symbols, so main
   # executable must be linked with it in order to provide consistent
   # API for all shared libaries loaded by this executable.
-  target_link_libraries(${test_name} gtest_main gtest ${LLVM_PTHREAD_LIB})
+  target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
 
   add_dependencies(${test_suite} ${test_name})
   get_target_property(test_suite_folder ${test_suite} FOLDER)
index 9cce1a2..10fd526 100644 (file)
@@ -87,7 +87,7 @@ macro(llvm_config executable)
       endif()
     endif()
 
-    target_link_libraries(${executable} LLVM)
+    target_link_libraries(${executable} PRIVATE LLVM)
   endif()
 
   explicit_llvm_config(${executable} ${link_components})
@@ -101,7 +101,7 @@ function(explicit_llvm_config executable)
   get_target_property(t ${executable} TYPE)
   if(t STREQUAL "STATIC_LIBRARY")
     target_link_libraries(${executable} INTERFACE ${LIBRARIES})
-  elseif(t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY")
+  elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY")
     target_link_libraries(${executable} PRIVATE ${LIBRARIES})
   else()
     # Use plain form for legacy user.
index deeee07..c42dfc8 100644 (file)
@@ -11,4 +11,4 @@ add_llvm_example(ParallelJIT
   ParallelJIT.cpp
   )
 
-target_link_libraries(ParallelJIT ${LLVM_PTHREAD_LIB})
+target_link_libraries(ParallelJIT PRIVATE ${LLVM_PTHREAD_LIB})
index 8975e67..72c5973 100644 (file)
@@ -37,7 +37,7 @@ add_llvm_tool(bugpoint
 export_executable_symbols(bugpoint)
 
 if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
-  target_link_libraries(bugpoint Polly)
+  target_link_libraries(bugpoint PRIVATE Polly)
   # Ensure LLVMTarget can resolve dependences in Polly.
-  target_link_libraries(bugpoint LLVMTarget)
+  target_link_libraries(bugpoint PRIVATE LLVMTarget)
 endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
index 61d78b5..1dcb211 100644 (file)
@@ -22,5 +22,5 @@ add_llvm_tool(llvm-dsymutil
   )
 
 IF(APPLE)
-  target_link_libraries(llvm-dsymutil "-framework CoreFoundation")
+  target_link_libraries(llvm-dsymutil PRIVATE "-framework CoreFoundation")
 ENDIF(APPLE)
index de6a46e..7a008a6 100644 (file)
@@ -15,4 +15,4 @@ add_llvm_tool(llvm-cfi-verify
   llvm-cfi-verify.cpp)
 
 add_subdirectory(lib)
-target_link_libraries(llvm-cfi-verify LLVMCFIVerify)
+target_link_libraries(llvm-cfi-verify PRIVATE LLVMCFIVerify)
index 043a181..177c981 100644 (file)
@@ -23,7 +23,7 @@ add_llvm_tool(llvm-objdump
   )
 
 if(HAVE_LIBXAR)
-  target_link_libraries(llvm-objdump ${XAR_LIB})
+  target_link_libraries(llvm-objdump PRIVATE ${XAR_LIB})
 endif()
 
 if(LLVM_INSTALL_BINUTILS_SYMLINKS)
index 518396e..fcc957a 100644 (file)
@@ -37,5 +37,5 @@ add_llvm_tool(opt
 export_executable_symbols(opt)
 
 if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
-  target_link_libraries(opt Polly)
+  target_link_libraries(opt PRIVATE Polly)
 endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
index 6f504d8..bdac117 100644 (file)
@@ -11,4 +11,4 @@ add_llvm_unittest(DebugInfoCodeViewTests
   ${DebugInfoCodeViewSources}
   )
 
-target_link_libraries(DebugInfoCodeViewTests LLVMTestingSupport)
\ No newline at end of file
+target_link_libraries(DebugInfoCodeViewTests PRIVATE LLVMTestingSupport)
index 1966472..f490097 100644 (file)
@@ -18,4 +18,4 @@ add_llvm_unittest(DebugInfoDWARFTests
   ${DebugInfoSources}
   )
 
-target_link_libraries(DebugInfoDWARFTests LLVMTestingSupport)
+target_link_libraries(DebugInfoDWARFTests PRIVATE LLVMTestingSupport)
index 25e0111..20f3b2a 100644 (file)
@@ -12,4 +12,4 @@ add_llvm_unittest(DebugInfoMSFTests
   ${DebugInfoMSFSources}
   )
 
-target_link_libraries(DebugInfoMSFTests LLVMTestingSupport)
+target_link_libraries(DebugInfoMSFTests PRIVATE LLVMTestingSupport)
index e2db58f..b19ee2c 100644 (file)
@@ -14,4 +14,4 @@ add_llvm_unittest(DebugInfoPDBTests
   ${DebugInfoPDBSources}
   )
 
-target_link_libraries(DebugInfoPDBTests LLVMTestingSupport)
+target_link_libraries(DebugInfoPDBTests PRIVATE LLVMTestingSupport)
index b693798..28e0795 100644 (file)
@@ -24,4 +24,4 @@ add_llvm_unittest(OrcJITTests
   SymbolStringPoolTest.cpp
   )
 
-target_link_libraries(OrcJITTests ${LLVM_PTHREAD_LIB})
+target_link_libraries(OrcJITTests PRIVATE ${LLVM_PTHREAD_LIB})
index 80f9ada..366ed54 100644 (file)
@@ -11,4 +11,4 @@ add_llvm_unittest(ProfileDataTests
   SampleProfTest.cpp
   )
 
-target_link_libraries(ProfileDataTests LLVMTestingSupport)
+target_link_libraries(ProfileDataTests PRIVATE LLVMTestingSupport)
index f2a9b47..24500e6 100644 (file)
@@ -74,6 +74,6 @@ add_llvm_unittest(SupportTests
 set_source_files_properties(AlignOfTest.cpp PROPERTIES COMPILE_FLAGS -w)
 
 # ManagedStatic.cpp uses <pthread>.
-target_link_libraries(SupportTests LLVMTestingSupport ${LLVM_PTHREAD_LIB})
+target_link_libraries(SupportTests PRIVATE LLVMTestingSupport ${LLVM_PTHREAD_LIB})
 
 add_subdirectory(DynamicLibrary)
index c6201b1..4f060e4 100644 (file)
@@ -4,7 +4,7 @@ add_library(DynamicLibraryLib STATIC ExportedFuncs.cxx)
 set_target_properties(DynamicLibraryLib PROPERTIES FOLDER "Tests")
 
 add_llvm_unittest(DynamicLibraryTests DynamicLibraryTest.cpp)
-target_link_libraries(DynamicLibraryTests DynamicLibraryLib)
+target_link_libraries(DynamicLibraryTests PRIVATE DynamicLibraryLib)
 export_executable_symbols(DynamicLibraryTests)
 
 function(dynlib_add_module NAME)
index adb7a55..e47bbdf 100644 (file)
@@ -14,4 +14,4 @@ set(LLVM_LINK_COMPONENTS
 add_llvm_unittest(CFIVerifyTests
   FileAnalysis.cpp
   GraphBuilder.cpp)
-target_link_libraries(CFIVerifyTests LLVMCFIVerify)
+target_link_libraries(CFIVerifyTests PRIVATE LLVMCFIVerify)
index 999320f..32e948a 100644 (file)
@@ -2,4 +2,4 @@ add_llvm_utility(FileCheck
   FileCheck.cpp
   )
 
-target_link_libraries(FileCheck LLVMSupport)
+target_link_libraries(FileCheck PRIVATE LLVMSupport)
index 4a92348..29c7b02 100644 (file)
@@ -2,4 +2,4 @@ add_llvm_utility(not
   not.cpp
   )
 
-target_link_libraries(not LLVMSupport)
+target_link_libraries(not PRIVATE LLVMSupport)
index 403182c..cd04b33 100644 (file)
@@ -2,4 +2,4 @@ add_llvm_utility(yaml-bench
   YAMLBench.cpp
   )
 
-target_link_libraries(yaml-bench LLVMSupport)
+target_link_libraries(yaml-bench PRIVATE LLVMSupport)
index ed42ef7..cac10df 100644 (file)
@@ -11,12 +11,12 @@ function(add_polly_unittest test_name)
     add_executable(${test_name} EXCLUDE_FROM_ALL ${ARGN})
     set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 
-    target_link_libraries(${test_name} gtest_main gtest)
+    target_link_libraries(${test_name} PRIVATE gtest_main gtest)
     add_dependencies(PollyUnitTests ${test_name})
 
     set_property(TARGET ${test_name} PROPERTY FOLDER "Polly")
   endif()
-  target_link_libraries(${test_name} Polly)
+  target_link_libraries(${test_name} PRIVATE Polly)
 endfunction()
 
 add_subdirectory(Isl)