Skip to content

Commit e46997e

Browse files
blucayonghong-song
authored andcommitted
cmake: link dynamically to libclang-cpp if found and ENABLE_LLVM_SHARED is set
ENABLE_LLVM_SHARED allows to dynamically link against libLLVM, but libclang is still unconditionally linked statically. Search for libclang-cpp.so, and if it is found and ENABLE_LLVM_SHARED is set dynamically link against it. Also expand the libstdc++ static linking check to include this new condition.
1 parent b1ab869 commit e46997e

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ find_library(libclangRewrite NAMES clangRewrite clang-cpp HINTS ${CLANG_SEARCH})
7979
find_library(libclangSema NAMES clangSema clang-cpp HINTS ${CLANG_SEARCH})
8080
find_library(libclangSerialization NAMES clangSerialization clang-cpp HINTS ${CLANG_SEARCH})
8181
find_library(libclangASTMatchers NAMES clangASTMatchers clang-cpp HINTS ${CLANG_SEARCH})
82+
find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
8283
if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")
8384
message(FATAL_ERROR "Unable to find clang libraries")
8485
endif()

cmake/clang_libs.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ llvm_map_components_to_libnames(_llvm_libs ${llvm_raw_libs})
2626
llvm_expand_dependencies(llvm_libs ${_llvm_libs})
2727
endif()
2828

29+
if(ENABLE_LLVM_SHARED AND NOT libclang-shared STREQUAL "libclang-shared-NOTFOUND")
30+
set(clang_libs ${libclang-shared})
31+
else()
2932
# order is important
3033
set(clang_libs
3134
${libclangFrontend}
@@ -46,6 +49,7 @@ list(APPEND clang_libs
4649
${libclangAST}
4750
${libclangLex}
4851
${libclangBasic})
52+
endif()
4953

5054
# prune unused llvm static library stuff when linking into the new .so
5155
set(_exclude_flags)

cmake/static_libstdc++.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# only turn on static-libstdc++ if also linking statically against clang
22
string(REGEX MATCH ".*[.]a$" LIBCLANG_ISSTATIC "${libclangBasic}")
33
# if gcc 4.9 or higher is used, static libstdc++ is a good option
4-
if (CMAKE_COMPILER_IS_GNUCC AND LIBCLANG_ISSTATIC)
4+
if (CMAKE_COMPILER_IS_GNUCC AND LIBCLANG_ISSTATIC AND (NOT ENABLE_LLVM_SHARED OR libclang-shared STREQUAL "libclang-shared-NOTFOUND"))
55
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
66
if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
77
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-libgcc-file-name OUTPUT_VARIABLE GCC_LIB)

0 commit comments

Comments
 (0)