Skip to content

Commit 2e97d2a

Browse files
committed
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
1 parent e030827 commit 2e97d2a

File tree

39 files changed

+86
-45
lines changed

39 files changed

+86
-45
lines changed

clang/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
323323
set(CLANG_PYTHON_BINDINGS_VERSIONS "" CACHE STRING
324324
"Python versions to install libclang python bindings for")
325325

326+
set(CLANG_LINK_CLANG_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
327+
"Link tools against libclang_shared.so")
328+
329+
if (NOT LLVM_LINK_LLVM_DYLIB AND CLANG_LINK_CLANG_DYLIB)
330+
message(FATAL_ERROR "Cannot set CLANG_LINK_CLANG_DYLIB=ON when "
331+
"LLVM_LINK_LLVM_DYLIB=OFF")
332+
endif()
333+
326334
# The libdir suffix must exactly match whatever LLVM's configuration used.
327335
set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
328336

clang/cmake/modules/AddClang.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,12 @@ macro(add_clang_symlink name dest)
172172
# Always generate install targets
173173
llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
174174
endmacro()
175+
176+
function(clang_target_link_libraries target type)
177+
if (CLANG_LINK_CLANG_DYLIB)
178+
target_link_libraries(${target} ${type} clang_shared)
179+
else()
180+
target_link_libraries(${target} ${type} ${ARGN})
181+
endif()
182+
183+
endfunction()
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL clang)
22

33
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
4-
target_link_libraries(AnnotateFunctions PRIVATE
4+
set(LLVM_LINK_COMPONENTS
5+
Support
6+
)
7+
clang_target_link_libraries(AnnotateFunctions PRIVATE
58
clangAST
69
clangBasic
710
clangFrontend
811
clangLex
9-
LLVMSupport
1012
)
1113
endif()

clang/examples/PrintFunctionNames/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ endif()
1212
add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL clang)
1313

1414
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
15-
target_link_libraries(PrintFunctionNames PRIVATE
15+
set(LLVM_LINK_COMPONENTS
16+
Support
17+
)
18+
clang_target_link_libraries(PrintFunctionNames PRIVATE
1619
clangAST
1720
clangBasic
1821
clangFrontend
19-
LLVMSupport
2022
)
2123
endif()

clang/examples/clang-interpreter/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ add_dependencies(clang-interpreter
1919
clang-resource-headers
2020
)
2121

22-
target_link_libraries(clang-interpreter
22+
clang_target_link_libraries(clang-interpreter
2323
PRIVATE
2424
clangBasic
2525
clangCodeGen
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
set(LLVM_LINK_COMPONENTS
2+
Support
3+
)
4+
15
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerDependencyHandlingAnalyzerPlugin.exports)
26
add_llvm_library(CheckerDependencyHandlingAnalyzerPlugin MODULE CheckerDependencyHandling.cpp PLUGIN_TOOL clang)
37

4-
target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
8+
clang_target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE
59
clangAnalysis
610
clangAST
711
clangStaticAnalyzerCore
812
clangStaticAnalyzerFrontend
9-
LLVMSupport
1013
)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
set(LLVM_LINK_COMPONENTS
2+
Support
3+
)
4+
15
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/CheckerOptionHandlingAnalyzerPlugin.exports)
26
add_llvm_library(CheckerOptionHandlingAnalyzerPlugin MODULE CheckerOptionHandling.cpp PLUGIN_TOOL clang)
37

4-
target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
8+
clang_target_link_libraries(CheckerOptionHandlingAnalyzerPlugin PRIVATE
59
clangAnalysis
610
clangAST
711
clangStaticAnalyzerCore
812
clangStaticAnalyzerFrontend
9-
LLVMSupport
1013
)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
set(LLVM_LINK_COMPONENTS
2+
Support
3+
)
4+
15
set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
26
add_llvm_library(SampleAnalyzerPlugin MODULE MainCallChecker.cpp PLUGIN_TOOL clang)
37

4-
target_link_libraries(SampleAnalyzerPlugin PRIVATE
8+
clang_target_link_libraries(SampleAnalyzerPlugin PRIVATE
59
clangAnalysis
610
clangAST
711
clangStaticAnalyzerCore
812
clangStaticAnalyzerFrontend
9-
LLVMSupport
1013
)

clang/tools/arcmt-test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_clang_executable(arcmt-test
66
arcmt-test.cpp
77
)
88

9-
target_link_libraries(arcmt-test
9+
clang_target_link_libraries(arcmt-test
1010
PRIVATE
1111
clangARCMigrate
1212
clangBasic

clang/tools/clang-check/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_clang_executable(clang-check
88
ClangCheck.cpp
99
)
1010

11-
target_link_libraries(clang-check
11+
clang_target_link_libraries(clang-check
1212
PRIVATE
1313
clangAST
1414
clangBasic

0 commit comments

Comments
 (0)