]> granicus.if.org Git - clang/commitdiff
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319840 91177308-0d34-0410-b5e6-96231b3b80d8

32 files changed:
examples/clang-interpreter/CMakeLists.txt
tools/arcmt-test/CMakeLists.txt
tools/c-arcmt-test/CMakeLists.txt
tools/c-index-test/CMakeLists.txt
tools/clang-check/CMakeLists.txt
tools/clang-diff/CMakeLists.txt
tools/clang-format/CMakeLists.txt
tools/clang-func-mapping/CMakeLists.txt
tools/clang-fuzzer/CMakeLists.txt
tools/clang-import-test/CMakeLists.txt
tools/clang-offload-bundler/CMakeLists.txt
tools/clang-refactor/CMakeLists.txt
tools/clang-rename/CMakeLists.txt
tools/diagtool/CMakeLists.txt
tools/driver/CMakeLists.txt
unittests/AST/CMakeLists.txt
unittests/ASTMatchers/CMakeLists.txt
unittests/ASTMatchers/Dynamic/CMakeLists.txt
unittests/Analysis/CMakeLists.txt
unittests/Basic/CMakeLists.txt
unittests/CodeGen/CMakeLists.txt
unittests/CrossTU/CMakeLists.txt
unittests/Driver/CMakeLists.txt
unittests/Format/CMakeLists.txt
unittests/Frontend/CMakeLists.txt
unittests/Lex/CMakeLists.txt
unittests/Rename/CMakeLists.txt
unittests/Rewrite/CMakeLists.txt
unittests/Sema/CMakeLists.txt
unittests/StaticAnalyzer/CMakeLists.txt
unittests/Tooling/CMakeLists.txt
unittests/libclang/CMakeLists.txt

index e7e59d930877680205adf611faca4f8d6d3a313e..3084238844802363545360fcb2065464007f4d2a 100644 (file)
@@ -17,6 +17,7 @@ add_dependencies(clang-interpreter
   )
 
 target_link_libraries(clang-interpreter
+  PRIVATE
   clangBasic
   clangCodeGen
   clangDriver
index 0cb2c0f98eb51db04724e475595385b0bbfd0f2f..2b456be2fcdd7970501f3dafa4ed97a6b972f0ba 100644 (file)
@@ -7,6 +7,7 @@ add_clang_executable(arcmt-test
   )
 
 target_link_libraries(arcmt-test
+  PRIVATE
   clangARCMigrate
   clangBasic
   clangFrontend
index 8914607358fcb4f2f912e6cf68bf34de68efc983..08ac93c176db1295c328cc90d2a7ae42ae59caff 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 c5cb0591c51573ec4b3571b687bb0f1927d5c35d..fdc713dc49289ddc7118ec6e129b17d16e576f96 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 04151a8e0331dbabf62f97b1262d75863a6cdb08..c5ace26c2914ed9123a1c9361094b9c617cda4ee 100644 (file)
@@ -9,6 +9,7 @@ add_clang_executable(clang-check
   )
 
 target_link_libraries(clang-check
+  PRIVATE
   clangAST
   clangBasic
   clangDriver
index a1fc6275be308d6a20adb8bf982480b5dd5296db..09bebf2cb6e5fe6935ac5f04555cdecf3bac9275 100644 (file)
@@ -7,6 +7,7 @@ add_clang_executable(clang-diff
   )
 
 target_link_libraries(clang-diff
+  PRIVATE
   clangBasic
   clangFrontend
   clangTooling
index c695ba34424ee21ca357a80b6d83bd25fb729ecf..a295e8cd0b2ac01de7ff67db1c17535c4a115164 100644 (file)
@@ -12,6 +12,7 @@ set(CLANG_FORMAT_LIB_DEPS
   )
 
 target_link_libraries(clang-format
+  PRIVATE
   ${CLANG_FORMAT_LIB_DEPS}
   )
 
index 8c10fcd7570ba1b1f0de543c76d97bf2575f8619..ae28e28d532df2f204f6aaa2a88fc81930d34b39 100644 (file)
@@ -10,6 +10,7 @@ add_clang_executable(clang-func-mapping
   )
 
 target_link_libraries(clang-func-mapping
+  PRIVATE
   clangAST
   clangBasic
   clangCrossTU
index abc501511f8999d46d4fd916921668de95d80210..eab921c7d61204ea134196e01287b36314e9230e 100644 (file)
@@ -66,6 +66,7 @@ add_clang_executable(clang-fuzzer
   )
 
 target_link_libraries(clang-fuzzer
+  PRIVATE
   ${LLVM_LIB_FUZZING_ENGINE}
   clangHandleCXX
   )
index 85e833d37b66e247e2c9ed28ea9d22674c8b197e..836efac8ac3e1e7916b01e3069ba599bf1bfca40 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 6161d08ae587c2910b083003d273e775260cddaf..8718015be76a274f7bb4d9b5b5e9d6a09852ae1a 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 c20e83bacf5a3471e85f244889edf78eff467d06..d2029066b9b76fe8070e6084f33021a4792eb7d1 100644 (file)
@@ -9,6 +9,7 @@ add_clang_tool(clang-refactor
   )
 
 target_link_libraries(clang-refactor
+  PRIVATE
   clangAST
   clangBasic
   clangFormat
index e74f05d8216d396237792e8b525fac65ff913ea9..9689e1c6804d4e982a7266d72705e16a7c316d7b 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 3f7d80385a82c332d4b1e849152c7b1ea8f3e1c4..beb6c35457c4816e71633b982c14fb474cef3eb1 100644 (file)
@@ -13,6 +13,7 @@ add_clang_executable(diagtool
 )
 
 target_link_libraries(diagtool
+  PRIVATE
   clangBasic
   clangFrontend
   )
index 901b6d62e465234c1be0b5b5fcbc18463fdb7287..a0b190faabc407a983540808609a357980e53984 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 45dfa7a97247f6c8edbe87d95ba02e16227d60cb..9839cdb1f2ec2aa14c899720d9984cbcebd3feb9 100644 (file)
@@ -21,6 +21,7 @@ add_clang_unittest(ASTTests
   )
 
 target_link_libraries(ASTTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 563303157a8eeed1784851a965eb8ea059ef5019..a876fc2d3360521b03baa1664e0e49245d914f48 100644 (file)
@@ -18,6 +18,7 @@ add_clang_unittest(ASTMatchersTests
   ASTMatchersTraversalTest.cpp)
 
 target_link_libraries(ASTMatchersTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 506a65549e4f3ec5c3f5a989c368abd23432e1d2..848a820adeadbd6e07328a9287080e8d92b599f6 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
   RegistryTest.cpp)
 
 target_link_libraries(DynamicASTMatchersTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 62db8f652e111853c056f6a6f31232f0ce32d81d..0056f82402aae74d36a5d69faedc93bcb63a0cdb 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(ClangAnalysisTests
   )
 
 target_link_libraries(ClangAnalysisTests
+  PRIVATE
   clangAnalysis
   clangAST
   clangASTMatchers
index 3a9f34f3d2754a645db4ed09f26f303db7fd0ae0..b46c067dc2efe433837537420b2f5a2d9205b449 100644 (file)
@@ -12,6 +12,7 @@ add_clang_unittest(BasicTests
   )
 
 target_link_libraries(BasicTests
+  PRIVATE
   clangBasic
   clangLex
   )
index c49776bc0265736aa0ee1298b91309bb3d50428d..3fb79a03075dce87ef711064de5d479a30dad18d 100644 (file)
@@ -10,6 +10,7 @@ add_clang_unittest(ClangCodeGenTests
   )
 
 target_link_libraries(ClangCodeGenTests
+  PRIVATE
   clangAST
   clangBasic
   clangCodeGen
index 3c479c447329e9612a04c82423b4210e468b6cfc..652d91612fb4dd0f035cb50a4606ced7d18545cc 100644 (file)
@@ -8,6 +8,7 @@ add_clang_unittest(CrossTUTests
   )
 
 target_link_libraries(CrossTUTests
+  PRIVATE
   clangAST
   clangBasic
   clangCrossTU
index 2a3f41d63b245e4148cd59e54fa4e73c7e33e64e..b8c800f59eaf7bd610b26d507d04631e4e307b1c 100644 (file)
@@ -11,6 +11,7 @@ add_clang_unittest(ClangDriverTests
   )
 
 target_link_libraries(ClangDriverTests
+  PRIVATE
   clangDriver
   clangBasic
   )
index 992db0e508d00d0780312e21bc0dffae7688099d..18e4432308db2acb5c221c176a14ca5fa36044db 100644 (file)
@@ -20,6 +20,7 @@ add_clang_unittest(FormatTests
   )
 
 target_link_libraries(FormatTests
+  PRIVATE
   clangBasic
   clangFormat
   clangFrontend
index c1f4f186354b9867e63b4134aa1218dd562828a3..f3c4336ea22fa5771db589c608648b71602268c6 100644 (file)
@@ -11,6 +11,7 @@ add_clang_unittest(FrontendTests
   PCHPreambleTest.cpp
   )
 target_link_libraries(FrontendTests
+  PRIVATE
   clangAST
   clangBasic
   clangFrontend
index ef0f06c0b3c9d534c48170b040e95f1e555629f9..ea6f9fd234020348276c9e4819a72910b89bdf50 100644 (file)
@@ -10,6 +10,7 @@ add_clang_unittest(LexTests
   )
 
 target_link_libraries(LexTests
+  PRIVATE
   clangAST
   clangBasic
   clangLex
index cecb2d39b9881a764113b77e9dd357e142a45753..b625a7a691fbb39d7b5750b662fec5e73bd3834b 100644 (file)
@@ -14,6 +14,7 @@ add_clang_unittest(ClangRenameTests
   )
 
 target_link_libraries(ClangRenameTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index bee7ff6d55418f908d44409e47373b73167e5af5..8edd9ba8f830ed9380a9ea0e462e85507301141d 100644 (file)
@@ -6,5 +6,6 @@ add_clang_unittest(RewriteTests
   RewriteBufferTest.cpp
   )
 target_link_libraries(RewriteTests
+  PRIVATE
   clangRewrite
   )
index c25db814b7c2972c6cb1d6442558d0a29abff921..16fae820dfe407e7e6ffe48c4c5af1d674d88011 100644 (file)
@@ -7,6 +7,7 @@ add_clang_unittest(SemaTests
   )
 
 target_link_libraries(SemaTests
+  PRIVATE
   clangAST
   clangBasic
   clangFrontend
index 4aa5efba77a2dd32b3d45a3b8b0c134d30bdd1f2..4ca0be50e5c2632ff55f5147634ff485019e0ac8 100644 (file)
@@ -7,6 +7,7 @@ add_clang_unittest(StaticAnalysisTests
   )
 
 target_link_libraries(StaticAnalysisTests
+  PRIVATE
   clangBasic
   clangAnalysis
   clangStaticAnalyzerCore 
index f9ddf7ffc18f641ffc6d68a5e2e3cc2856544f2a..557d1007ae2c6b3c6b795dae0e88cc84a26ffdf7 100644 (file)
@@ -35,6 +35,7 @@ add_clang_unittest(ToolingTests
   )
 
 target_link_libraries(ToolingTests
+  PRIVATE
   clangAST
   clangASTMatchers
   clangBasic
index 1cdc45e2d22a661065bf623cad8cba8c49eb3e36..36f6089787d26cdcda6e35e8dfdef947181ed1d5 100644 (file)
@@ -3,5 +3,6 @@ add_clang_unittest(libclangTests
   )
 
 target_link_libraries(libclangTests
+  PRIVATE
   libclang
   )