| 1 |
# Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off |
| 2 |
if (NOT LLVM_ENABLE_PIC) |
| 3 |
return() |
| 4 |
endif() |
| 5 |
|
| 6 |
get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS) |
| 7 |
|
| 8 |
foreach (lib ${clang_libs}) |
| 9 |
if(XCODE) |
| 10 |
# Xcode doesn't support object libraries, so we have to trick it into |
| 11 |
# linking the static libraries instead. |
| 12 |
list(APPEND _DEPS "-force_load" ${lib}) |
| 13 |
else() |
| 14 |
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>) |
| 15 |
endif() |
| 16 |
if (BUILD_SHARED_LIBS) |
| 17 |
# If we are building static libraries, then we don't need to add the static |
| 18 |
# libraries as a dependency, because we are already linking against the |
| 19 |
# individual object files. |
| 20 |
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>) |
| 21 |
endif() |
| 22 |
|
| 23 |
# clang libraries are redundant since we are linking all the individual |
| 24 |
# object files into libclang-cpp.so, so filter them out from _DEPS. |
| 25 |
# This avoids problems with LLVM global data when building with |
| 26 |
# BUILD_SHARED_LIBS=ON |
| 27 |
# FIXME: We could use list(FILTER) with cmake >= 3.6 |
| 28 |
# FIXME: With cmake >= 3.15 we could use the generator expression |
| 29 |
# $<FILTER:list,INCLUDE|EXCLUDE,regex> |
| 30 |
get_target_property(interface ${lib} LINK_LIBRARIES) |
| 31 |
if (interface) |
| 32 |
foreach(lib ${interface}) |
| 33 |
if (NOT ${lib} MATCHES "^clang") |
| 34 |
list(APPEND _DEPS ${lib}) |
| 35 |
endif() |
| 36 |
endforeach() |
| 37 |
endif() |
| 38 |
endforeach () |
| 39 |
|
| 40 |
if (CLANG_LINK_CLANG_DYLIB) |
| 41 |
set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) |
| 42 |
endif() |
| 43 |
|
| 44 |
add_clang_library(clang-cpp |
| 45 |
SHARED |
| 46 |
${INSTALL_WITH_TOOLCHAIN} |
| 47 |
clang-shlib.cpp |
| 48 |
${_OBJECTS} |
| 49 |
LINK_LIBS |
| 50 |
${_DEPS}) |
| 51 |
# Optimize function calls for default visibility definitions to avoid PLT and |
| 52 |
# reduce dynamic relocations. |
| 53 |
if (NOT APPLE AND NOT MINGW) |
| 54 |
target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions) |
| 55 |
endif() |