1# Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off 2if (NOT LLVM_ENABLE_PIC) 3 return() 4endif() 5 6get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS) 7 8foreach (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() 38endforeach () 39 40if (CLANG_LINK_CLANG_DYLIB) 41 set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) 42endif() 43 44add_clang_library(clang-cpp 45 SHARED 46 ${INSTALL_WITH_TOOLCHAIN} 47 clang-shlib.cpp 48 ${_OBJECTS} 49 LINK_LIBS 50 ${_DEPS}) 51 52configure_file(simple_version_script.map.in simple_version_script.map) 53 54if (CMAKE_SYSTEM_NAME STREQUAL "Linux") 55 target_link_options(clang-cpp PRIVATE LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map) 56endif() 57 58# Optimize function calls for default visibility definitions to avoid PLT and 59# reduce dynamic relocations. 60if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS) 61 target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions) 62endif() 63if (MINGW OR CYGWIN) 64 # The clang-cpp DLL is supposed to export all symbols (except for ones 65 # that are explicitly hidden). Normally, this is what happens anyway, but 66 # if there are symbols that are marked explicitly as dllexport, we'd only 67 # export them and nothing else. Therefore, add --export-all-symbols to 68 # make sure we export all symbols despite potential dllexports. 69 target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols) 70endif() 71