Skip to content

Commit

Permalink
cmake: Add CLANG_LINK_CLANG_DYLIB option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tstellar committed Jul 3, 2019
1 parent e030827 commit 2e97d2a
Show file tree
Hide file tree
Showing 39 changed files with 86 additions and 45 deletions.
8 changes: 8 additions & 0 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
9 changes: 9 additions & 0 deletions clang/cmake/modules/AddClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions clang/examples/AnnotateFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 4 additions & 2 deletions clang/examples/PrintFunctionNames/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion clang/examples/clang-interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
7 changes: 5 additions & 2 deletions clang/lib/Analysis/plugins/SampleAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion clang/tools/arcmt-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-diff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-extdef-mapping/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-import-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
2 changes: 1 addition & 1 deletion clang/tools/clang-offload-bundler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-refactor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-rename/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-scan-deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/diagtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_clang_executable(diagtool
TreeView.cpp
)

target_link_libraries(diagtool
clang_target_link_libraries(diagtool
PRIVATE
clangBasic
clangFrontend
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ add_clang_tool(clang
${tablegen_deps}
)

target_link_libraries(clang
clang_target_link_libraries(clang
PRIVATE
clangBasic
clangCodeGen
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ add_clang_unittest(ASTTests
StructuralEquivalenceTest.cpp
)

target_link_libraries(ASTTests
clang_target_link_libraries(ASTTests
PRIVATE
clangAST
clangASTMatchers
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/ASTMatchers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_clang_unittest(ASTMatchersTests
ASTMatchersTraversalTest.cpp
)

target_link_libraries(ASTMatchersTests
clang_target_link_libraries(ASTMatchersTests
PRIVATE
clangAST
clangASTMatchers
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/ASTMatchers/Dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_clang_unittest(DynamicASTMatchersTests
RegistryTest.cpp
)

target_link_libraries(DynamicASTMatchersTests
clang_target_link_libraries(DynamicASTMatchersTests
PRIVATE
clangAST
clangASTMatchers
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_clang_unittest(ClangAnalysisTests
ExprMutationAnalyzerTest.cpp
)

target_link_libraries(ClangAnalysisTests
clang_target_link_libraries(ClangAnalysisTests
PRIVATE
clangAnalysis
clangAST
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_clang_unittest(BasicTests
SourceManagerTest.cpp
)

target_link_libraries(BasicTests
clang_target_link_libraries(BasicTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_clang_unittest(ClangCodeGenTests
TBAAMetadataTest.cpp
)

target_link_libraries(ClangCodeGenTests
clang_target_link_libraries(ClangCodeGenTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/CrossTU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_clang_unittest(CrossTUTests
CrossTranslationUnitTest.cpp
)

target_link_libraries(CrossTUTests
clang_target_link_libraries(CrossTUTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_clang_unittest(ClangDriverTests
MultilibTest.cpp
)

target_link_libraries(ClangDriverTests
clang_target_link_libraries(ClangDriverTests
PRIVATE
clangDriver
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_clang_unittest(FormatTests
UsingDeclarationsSorterTest.cpp
)

target_link_libraries(FormatTests
clang_target_link_libraries(FormatTests
PRIVATE
clangBasic
clangFormat
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_clang_unittest(FrontendTests
PCHPreambleTest.cpp
OutputStreamTest.cpp
)
target_link_libraries(FrontendTests
clang_target_link_libraries(FrontendTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Index/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_clang_unittest(IndexTests
IndexTests.cpp
)

target_link_libraries(IndexTests
clang_target_link_libraries(IndexTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Lex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_clang_unittest(LexTests
PPConditionalDirectiveRecordTest.cpp
)

target_link_libraries(LexTests
clang_target_link_libraries(LexTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Rename/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_clang_unittest(ClangRenameTests
RenameFunctionTest.cpp
)

target_link_libraries(ClangRenameTests
clang_target_link_libraries(ClangRenameTests
PRIVATE
clangAST
clangASTMatchers
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Rewrite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 6 additions & 2 deletions clang/unittests/Sema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_clang_unittest(SemaTests
CodeCompleteTest.cpp
)

target_link_libraries(SemaTests
clang_target_link_libraries(SemaTests
PRIVATE
clangAST
clangBasic
Expand All @@ -16,5 +16,9 @@ target_link_libraries(SemaTests
clangSema
clangSerialization
clangTooling
LLVMTestingSupport
)

target_link_libraries(SemaTests
PRIVATE
LLVMTestingSupport
)
2 changes: 1 addition & 1 deletion clang/unittests/Serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_clang_unittest(SerializationTests
InMemoryModuleCacheTest.cpp
)

target_link_libraries(SerializationTests
clang_target_link_libraries(SerializationTests
PRIVATE
clangAST
clangBasic
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/StaticAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_clang_unittest(StaticAnalysisTests
SymbolReaperTest.cpp
)

target_link_libraries(StaticAnalysisTests
clang_target_link_libraries(StaticAnalysisTests
PRIVATE
clangBasic
clangAnalysis
Expand Down
Loading

0 comments on commit 2e97d2a

Please sign in to comment.