cmake: Add CLANG_LINK_CLANG_DYLIB option

Summary:
Setting CLANG_LINK_CLANG_DYLIB=ON causes clang tools to link against
libclang_shared.so instead of the individual component libraries.

Reviewers: mgorny, beanz, smeenai, phosek, sylvestre.ledru

Subscribers: arphaman, cfe-commits, llvm-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63503

llvm-svn: 365092
This commit is contained in:
Tom Stellard 2019-07-03 22:45:55 +00:00
parent e0308279cb
commit 2e97d2aa1b
39 changed files with 86 additions and 45 deletions

View File

@ -323,6 +323,14 @@ set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
"Python versions to install libclang python bindings for")
set(CLANG_LINK_CLANG_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
"Link tools against libclang_shared.so")
if (NOT LLVM_LINK_LLVM_DYLIB AND CLANG_LINK_CLANG_DYLIB)
message(FATAL_ERROR "Cannot set CLANG_LINK_CLANG_DYLIB=ON when "
"LLVM_LINK_LLVM_DYLIB=OFF")
endif()
# The libdir suffix must exactly match whatever LLVM's configuration used.
set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")

View File

@ -172,3 +172,12 @@ macro(add_clang_symlink name dest)
# Always generate install targets
llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
endmacro()
function(clang_target_link_libraries target type)
if (CLANG_LINK_CLANG_DYLIB)
target_link_libraries(${target} ${type} clang_shared)
else()
target_link_libraries(${target} ${type} ${ARGN})
endif()
endfunction()

View File

@ -1,11 +1,13 @@
add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL clang)
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
target_link_libraries(AnnotateFunctions PRIVATE
set(LLVM_LINK_COMPONENTS
Support
)
clang_target_link_libraries(AnnotateFunctions PRIVATE
clangAST
clangBasic
clangFrontend
clangLex
LLVMSupport
)
endif()

View File

@ -12,10 +12,12 @@ endif()
add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL clang)
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
target_link_libraries(PrintFunctionNames PRIVATE
set(LLVM_LINK_COMPONENTS
Support
)
clang_target_link_libraries(PrintFunctionNames PRIVATE
clangAST
clangBasic
clangFrontend
LLVMSupport
)
endif()

View File

@ -19,7 +19,7 @@ add_dependencies(clang-interpreter
clang-resource-headers
)
target_link_libraries(clang-interpreter
clang_target_link_libraries(clang-interpreter
PRIVATE
clangBasic
clangCodeGen

View File

@ -1,10 +1,13 @@
set(LLVM_LINK_COMPONENTS
Support
)
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerDependencyHandlingAnalyzerPlugin.exports)
add_llvm_library(CheckerDependencyHandlingAnalyzerPlugin MODULE CheckerDependencyHandling.cpp PLUGIN_TOOL clang)
target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
clang_target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
clangAnalysis
clangAST
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
LLVMSupport
)

View File

@ -1,10 +1,13 @@
set(LLVM_LINK_COMPONENTS
Support
)
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerOptionHandlingAnalyzerPlugin.exports)
add_llvm_library(CheckerOptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
clang_target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
clangAnalysis
clangAST
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
LLVMSupport
)

View File

@ -1,10 +1,13 @@
set(LLVM_LINK_COMPONENTS
Support
)
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
add_llvm_library(SampleAnalyzerPlugin MODULE MainCallChecker.cpp PLUGIN_TOOL clang)
target_link_libraries(SampleAnalyzerPlugin PRIVATE
clang_target_link_libraries(SampleAnalyzerPlugin PRIVATE
clangAnalysis
clangAST
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
LLVMSupport
)

View File

@ -6,7 +6,7 @@ add_clang_executable(arcmt-test
arcmt-test.cpp
)
target_link_libraries(arcmt-test
clang_target_link_libraries(arcmt-test
PRIVATE
clangARCMigrate
clangBasic

View File

@ -8,7 +8,7 @@ add_clang_executable(clang-check
ClangCheck.cpp
)
target_link_libraries(clang-check
clang_target_link_libraries(clang-check
PRIVATE
clangAST
clangBasic

View File

@ -6,7 +6,7 @@ add_clang_executable(clang-diff
ClangDiff.cpp
)
target_link_libraries(clang-diff
clang_target_link_libraries(clang-diff
PRIVATE
clangBasic
clangFrontend

View File

@ -7,7 +7,7 @@ add_clang_executable(clang-extdef-mapping
ClangExtDefMapGen.cpp
)
target_link_libraries(clang-extdef-mapping
clang_target_link_libraries(clang-extdef-mapping
PRIVATE
clangAST
clangBasic

View File

@ -11,7 +11,7 @@ set(CLANG_FORMAT_LIB_DEPS
clangToolingCore
)
target_link_libraries(clang-format
clang_target_link_libraries(clang-format
PRIVATE
${CLANG_FORMAT_LIB_DEPS}
)

View File

@ -24,7 +24,7 @@ set(CLANG_IMPORT_TEST_LIB_DEPS
clangSerialization
)
target_link_libraries(clang-import-test
clang_target_link_libraries(clang-import-test
PRIVATE
${CLANG_IMPORT_TEST_LIB_DEPS}
)

View File

@ -17,7 +17,7 @@ set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
add_dependencies(clang clang-offload-bundler)
target_link_libraries(clang-offload-bundler
clang_target_link_libraries(clang-offload-bundler
PRIVATE
${CLANG_OFFLOAD_BUNDLER_LIB_DEPS}
)

View File

@ -8,7 +8,7 @@ add_clang_tool(clang-refactor
TestSupport.cpp
)
target_link_libraries(clang-refactor
clang_target_link_libraries(clang-refactor
PRIVATE
clangAST
clangBasic

View File

@ -7,7 +7,7 @@ add_clang_tool(clang-rename
ClangRename.cpp
)
target_link_libraries(clang-rename
clang_target_link_libraries(clang-rename
PRIVATE
clangBasic
clangFrontend

View File

@ -21,7 +21,7 @@ set(CLANG_SCAN_DEPS_LIB_DEPS
clangDependencyScanning
)
target_link_libraries(clang-scan-deps
clang_target_link_libraries(clang-scan-deps
PRIVATE
${CLANG_SCAN_DEPS_LIB_DEPS}
)

View File

@ -12,7 +12,7 @@ add_clang_executable(diagtool
TreeView.cpp
)
target_link_libraries(diagtool
clang_target_link_libraries(diagtool
PRIVATE
clangBasic
clangFrontend

View File

@ -39,7 +39,7 @@ add_clang_tool(clang
${tablegen_deps}
)
target_link_libraries(clang
clang_target_link_libraries(clang
PRIVATE
clangBasic
clangCodeGen

View File

@ -31,7 +31,7 @@ add_clang_unittest(ASTTests
StructuralEquivalenceTest.cpp
)
target_link_libraries(ASTTests
clang_target_link_libraries(ASTTests
PRIVATE
clangAST
clangASTMatchers

View File

@ -18,7 +18,7 @@ add_clang_unittest(ASTMatchersTests
ASTMatchersTraversalTest.cpp
)
target_link_libraries(ASTMatchersTests
clang_target_link_libraries(ASTMatchersTests
PRIVATE
clangAST
clangASTMatchers

View File

@ -8,7 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
RegistryTest.cpp
)
target_link_libraries(DynamicASTMatchersTests
clang_target_link_libraries(DynamicASTMatchersTests
PRIVATE
clangAST
clangASTMatchers

View File

@ -8,7 +8,7 @@ add_clang_unittest(ClangAnalysisTests
ExprMutationAnalyzerTest.cpp
)
target_link_libraries(ClangAnalysisTests
clang_target_link_libraries(ClangAnalysisTests
PRIVATE
clangAnalysis
clangAST

View File

@ -10,7 +10,7 @@ add_clang_unittest(BasicTests
SourceManagerTest.cpp
)
target_link_libraries(BasicTests
clang_target_link_libraries(BasicTests
PRIVATE
clangAST
clangBasic

View File

@ -10,7 +10,7 @@ add_clang_unittest(ClangCodeGenTests
TBAAMetadataTest.cpp
)
target_link_libraries(ClangCodeGenTests
clang_target_link_libraries(ClangCodeGenTests
PRIVATE
clangAST
clangBasic

View File

@ -7,7 +7,7 @@ add_clang_unittest(CrossTUTests
CrossTranslationUnitTest.cpp
)
target_link_libraries(CrossTUTests
clang_target_link_libraries(CrossTUTests
PRIVATE
clangAST
clangBasic

View File

@ -11,7 +11,7 @@ add_clang_unittest(ClangDriverTests
MultilibTest.cpp
)
target_link_libraries(ClangDriverTests
clang_target_link_libraries(ClangDriverTests
PRIVATE
clangDriver
clangBasic

View File

@ -22,7 +22,7 @@ add_clang_unittest(FormatTests
UsingDeclarationsSorterTest.cpp
)
target_link_libraries(FormatTests
clang_target_link_libraries(FormatTests
PRIVATE
clangBasic
clangFormat

View File

@ -12,7 +12,7 @@ add_clang_unittest(FrontendTests
PCHPreambleTest.cpp
OutputStreamTest.cpp
)
target_link_libraries(FrontendTests
clang_target_link_libraries(FrontendTests
PRIVATE
clangAST
clangBasic

View File

@ -7,7 +7,7 @@ add_clang_unittest(IndexTests
IndexTests.cpp
)
target_link_libraries(IndexTests
clang_target_link_libraries(IndexTests
PRIVATE
clangAST
clangBasic

View File

@ -11,7 +11,7 @@ add_clang_unittest(LexTests
PPConditionalDirectiveRecordTest.cpp
)
target_link_libraries(LexTests
clang_target_link_libraries(LexTests
PRIVATE
clangAST
clangBasic

View File

@ -13,7 +13,7 @@ add_clang_unittest(ClangRenameTests
RenameFunctionTest.cpp
)
target_link_libraries(ClangRenameTests
clang_target_link_libraries(ClangRenameTests
PRIVATE
clangAST
clangASTMatchers

View File

@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_unittest(RewriteTests
RewriteBufferTest.cpp
)
target_link_libraries(RewriteTests
clang_target_link_libraries(RewriteTests
PRIVATE
clangRewrite
)

View File

@ -7,7 +7,7 @@ add_clang_unittest(SemaTests
CodeCompleteTest.cpp
)
target_link_libraries(SemaTests
clang_target_link_libraries(SemaTests
PRIVATE
clangAST
clangBasic
@ -16,5 +16,9 @@ target_link_libraries(SemaTests
clangSema
clangSerialization
clangTooling
LLVMTestingSupport
)
target_link_libraries(SemaTests
PRIVATE
LLVMTestingSupport
)

View File

@ -8,7 +8,7 @@ add_clang_unittest(SerializationTests
InMemoryModuleCacheTest.cpp
)
target_link_libraries(SerializationTests
clang_target_link_libraries(SerializationTests
PRIVATE
clangAST
clangBasic

View File

@ -10,7 +10,7 @@ add_clang_unittest(StaticAnalysisTests
SymbolReaperTest.cpp
)
target_link_libraries(StaticAnalysisTests
clang_target_link_libraries(StaticAnalysisTests
PRIVATE
clangBasic
clangAnalysis

View File

@ -57,7 +57,7 @@ add_clang_unittest(ToolingTests
TransformerTest.cpp
)
target_link_libraries(ToolingTests
clang_target_link_libraries(ToolingTests
PRIVATE
clangAST
clangASTMatchers
@ -71,8 +71,11 @@ target_link_libraries(ToolingTests
clangToolingCore
clangToolingInclusions
clangToolingRefactoring
LLVMTestingSupport
)
target_link_libraries(ToolingTests
PRIVATE
LLVMTestingSupport
)
add_subdirectory(Syntax)

View File

@ -6,7 +6,7 @@ add_clang_unittest(SyntaxTests
TokensTest.cpp
)
target_link_libraries(SyntaxTests
clang_target_link_libraries(SyntaxTests
PRIVATE
clangAST
clangBasic
@ -15,5 +15,9 @@ target_link_libraries(SyntaxTests
clangSerialization
clangTooling
clangToolingSyntax
LLVMTestingSupport
)
target_link_libraries(SyntaxTests
PRIVATE
LLVMTestingSupport
)