1 # Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off
2 if (NOT LLVM_ENABLE_PIC)
6 get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
8 foreach (lib ${clang_libs})
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})
14 list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
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>)
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)
32 foreach(lib ${interface})
33 if (NOT ${lib} MATCHES "^clang")
34 list(APPEND _DEPS ${lib})
40 if (CLANG_LINK_CLANG_DYLIB)
41 set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN)
44 add_clang_library(clang-cpp
46 ${INSTALL_WITH_TOOLCHAIN}
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)
57 # The clang-cpp DLL is supposed to export all symbols (except for ones
58 # that are explicitly hidden). Normally, this is what happens anyway, but
59 # if there are symbols that are marked explicitly as dllexport, we'd only
60 # export them and nothing else. Therefore, add --export-all-symbols to
61 # make sure we export all symbols despite potential dllexports.
62 target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols)