diff options
author | Shoaib Meenai <smeenai@fb.com> | 2017-12-05 21:49:56 +0000 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2017-12-05 21:49:56 +0000 |
commit | 4a6bb5316a70ee5df350bd8617ce7dcbd569a4ae (patch) | |
tree | f439c94195f4e99be213464fb425dd47763ae190 | |
parent | 96cfeb34745e61ec68d8835c83b9a93a0ddaf8aa (diff) |
[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/llvm/trunk@319840 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | cmake/modules/AddLLVM.cmake | 4 | ||||
-rw-r--r-- | cmake/modules/LLVM-Config.cmake | 4 | ||||
-rw-r--r-- | examples/ParallelJIT/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/bugpoint/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tools/dsymutil/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-cfi-verify/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-objdump/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/opt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/DebugInfo/CodeView/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/DebugInfo/DWARF/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/DebugInfo/MSF/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/DebugInfo/PDB/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/ExecutionEngine/Orc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/ProfileData/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/Support/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/Support/DynamicLibrary/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/tools/llvm-cfi-verify/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/FileCheck/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/not/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/yaml-bench/CMakeLists.txt | 2 |
20 files changed, 23 insertions, 23 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 26da2d13eed..90cba50d94c 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -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) diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake index 9cce1a2d4bc..10fd5260927 100644 --- a/cmake/modules/LLVM-Config.cmake +++ b/cmake/modules/LLVM-Config.cmake @@ -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. diff --git a/examples/ParallelJIT/CMakeLists.txt b/examples/ParallelJIT/CMakeLists.txt index deeee072b33..c42dfc85c14 100644 --- a/examples/ParallelJIT/CMakeLists.txt +++ b/examples/ParallelJIT/CMakeLists.txt @@ -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}) diff --git a/tools/bugpoint/CMakeLists.txt b/tools/bugpoint/CMakeLists.txt index 8975e676343..72c597379c8 100644 --- a/tools/bugpoint/CMakeLists.txt +++ b/tools/bugpoint/CMakeLists.txt @@ -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) diff --git a/tools/dsymutil/CMakeLists.txt b/tools/dsymutil/CMakeLists.txt index 61d78b5094a..1dcb2116f34 100644 --- a/tools/dsymutil/CMakeLists.txt +++ b/tools/dsymutil/CMakeLists.txt @@ -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) diff --git a/tools/llvm-cfi-verify/CMakeLists.txt b/tools/llvm-cfi-verify/CMakeLists.txt index de6a46e7859..7a008a66770 100644 --- a/tools/llvm-cfi-verify/CMakeLists.txt +++ b/tools/llvm-cfi-verify/CMakeLists.txt @@ -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) diff --git a/tools/llvm-objdump/CMakeLists.txt b/tools/llvm-objdump/CMakeLists.txt index 043a181d639..177c98166ef 100644 --- a/tools/llvm-objdump/CMakeLists.txt +++ b/tools/llvm-objdump/CMakeLists.txt @@ -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) diff --git a/tools/opt/CMakeLists.txt b/tools/opt/CMakeLists.txt index 518396e3602..fcc957abaee 100644 --- a/tools/opt/CMakeLists.txt +++ b/tools/opt/CMakeLists.txt @@ -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) diff --git a/unittests/DebugInfo/CodeView/CMakeLists.txt b/unittests/DebugInfo/CodeView/CMakeLists.txt index 6f504d8149b..bdac117b36c 100644 --- a/unittests/DebugInfo/CodeView/CMakeLists.txt +++ b/unittests/DebugInfo/CodeView/CMakeLists.txt @@ -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) diff --git a/unittests/DebugInfo/DWARF/CMakeLists.txt b/unittests/DebugInfo/DWARF/CMakeLists.txt index 1966472a946..f490097a21a 100644 --- a/unittests/DebugInfo/DWARF/CMakeLists.txt +++ b/unittests/DebugInfo/DWARF/CMakeLists.txt @@ -18,4 +18,4 @@ add_llvm_unittest(DebugInfoDWARFTests ${DebugInfoSources} ) -target_link_libraries(DebugInfoDWARFTests LLVMTestingSupport) +target_link_libraries(DebugInfoDWARFTests PRIVATE LLVMTestingSupport) diff --git a/unittests/DebugInfo/MSF/CMakeLists.txt b/unittests/DebugInfo/MSF/CMakeLists.txt index 25e011178cd..20f3b2ab3dc 100644 --- a/unittests/DebugInfo/MSF/CMakeLists.txt +++ b/unittests/DebugInfo/MSF/CMakeLists.txt @@ -12,4 +12,4 @@ add_llvm_unittest(DebugInfoMSFTests ${DebugInfoMSFSources} ) -target_link_libraries(DebugInfoMSFTests LLVMTestingSupport) +target_link_libraries(DebugInfoMSFTests PRIVATE LLVMTestingSupport) diff --git a/unittests/DebugInfo/PDB/CMakeLists.txt b/unittests/DebugInfo/PDB/CMakeLists.txt index e2db58ff937..b19ee2cf43a 100644 --- a/unittests/DebugInfo/PDB/CMakeLists.txt +++ b/unittests/DebugInfo/PDB/CMakeLists.txt @@ -14,4 +14,4 @@ add_llvm_unittest(DebugInfoPDBTests ${DebugInfoPDBSources} ) -target_link_libraries(DebugInfoPDBTests LLVMTestingSupport) +target_link_libraries(DebugInfoPDBTests PRIVATE LLVMTestingSupport) diff --git a/unittests/ExecutionEngine/Orc/CMakeLists.txt b/unittests/ExecutionEngine/Orc/CMakeLists.txt index b6937982313..28e07959ac7 100644 --- a/unittests/ExecutionEngine/Orc/CMakeLists.txt +++ b/unittests/ExecutionEngine/Orc/CMakeLists.txt @@ -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}) diff --git a/unittests/ProfileData/CMakeLists.txt b/unittests/ProfileData/CMakeLists.txt index 80f9ada7b83..366ed5482bf 100644 --- a/unittests/ProfileData/CMakeLists.txt +++ b/unittests/ProfileData/CMakeLists.txt @@ -11,4 +11,4 @@ add_llvm_unittest(ProfileDataTests SampleProfTest.cpp ) -target_link_libraries(ProfileDataTests LLVMTestingSupport) +target_link_libraries(ProfileDataTests PRIVATE LLVMTestingSupport) diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index f2a9b472d90..24500e66ae7 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -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) diff --git a/unittests/Support/DynamicLibrary/CMakeLists.txt b/unittests/Support/DynamicLibrary/CMakeLists.txt index c6201b1ad31..4f060e4020d 100644 --- a/unittests/Support/DynamicLibrary/CMakeLists.txt +++ b/unittests/Support/DynamicLibrary/CMakeLists.txt @@ -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) diff --git a/unittests/tools/llvm-cfi-verify/CMakeLists.txt b/unittests/tools/llvm-cfi-verify/CMakeLists.txt index adb7a55327a..e47bbdf7f13 100644 --- a/unittests/tools/llvm-cfi-verify/CMakeLists.txt +++ b/unittests/tools/llvm-cfi-verify/CMakeLists.txt @@ -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) diff --git a/utils/FileCheck/CMakeLists.txt b/utils/FileCheck/CMakeLists.txt index 999320f78af..32e948a1a19 100644 --- a/utils/FileCheck/CMakeLists.txt +++ b/utils/FileCheck/CMakeLists.txt @@ -2,4 +2,4 @@ add_llvm_utility(FileCheck FileCheck.cpp ) -target_link_libraries(FileCheck LLVMSupport) +target_link_libraries(FileCheck PRIVATE LLVMSupport) diff --git a/utils/not/CMakeLists.txt b/utils/not/CMakeLists.txt index 4a92348ba0f..29c7b021852 100644 --- a/utils/not/CMakeLists.txt +++ b/utils/not/CMakeLists.txt @@ -2,4 +2,4 @@ add_llvm_utility(not not.cpp ) -target_link_libraries(not LLVMSupport) +target_link_libraries(not PRIVATE LLVMSupport) diff --git a/utils/yaml-bench/CMakeLists.txt b/utils/yaml-bench/CMakeLists.txt index 403182ceee2..cd04b33d0a2 100644 --- a/utils/yaml-bench/CMakeLists.txt +++ b/utils/yaml-bench/CMakeLists.txt @@ -2,4 +2,4 @@ add_llvm_utility(yaml-bench YAMLBench.cpp ) -target_link_libraries(yaml-bench LLVMSupport) +target_link_libraries(yaml-bench PRIVATE LLVMSupport) |