176b26550SSylvestre Ledru# Building libclang-cpp.so fails if LLVM_ENABLE_PIC=Off 2876e3993SChris Bienemanif (NOT LLVM_ENABLE_PIC) 3876e3993SChris Bieneman return() 4876e3993SChris Bienemanendif() 5876e3993SChris Bieneman 6876e3993SChris Bienemanget_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS) 7876e3993SChris Bieneman 8876e3993SChris Bienemanforeach (lib ${clang_libs}) 95fd467feSJordan Rose if(XCODE) 105fd467feSJordan Rose # Xcode doesn't support object libraries, so we have to trick it into 115fd467feSJordan Rose # linking the static libraries instead. 125fd467feSJordan Rose list(APPEND _DEPS "-force_load" ${lib}) 135fd467feSJordan Rose else() 14876e3993SChris Bieneman list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>) 155fd467feSJordan Rose endif() 161d68a780STom Stellard if (BUILD_SHARED_LIBS) 171d68a780STom Stellard # If we are building static libraries, then we don't need to add the static 185674a3c8SGabriel Ravier # libraries as a dependency, because we are already linking against the 191d68a780STom Stellard # individual object files. 20aaa49034SShoaib Meenai list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>) 211d68a780STom Stellard endif() 22ebcf25eaSTom Stellard 23ebcf25eaSTom Stellard # clang libraries are redundant since we are linking all the individual 24ebcf25eaSTom Stellard # object files into libclang-cpp.so, so filter them out from _DEPS. 25ebcf25eaSTom Stellard # This avoids problems with LLVM global data when building with 26ebcf25eaSTom Stellard # BUILD_SHARED_LIBS=ON 27ebcf25eaSTom Stellard # FIXME: We could use list(FILTER) with cmake >= 3.6 28ebcf25eaSTom Stellard # FIXME: With cmake >= 3.15 we could use the generator expression 29ebcf25eaSTom Stellard # $<FILTER:list,INCLUDE|EXCLUDE,regex> 30ebcf25eaSTom Stellard get_target_property(interface ${lib} LINK_LIBRARIES) 31ebcf25eaSTom Stellard if (interface) 32ebcf25eaSTom Stellard foreach(lib ${interface}) 33ebcf25eaSTom Stellard if (NOT ${lib} MATCHES "^clang") 34ebcf25eaSTom Stellard list(APPEND _DEPS ${lib}) 35ebcf25eaSTom Stellard endif() 36ebcf25eaSTom Stellard endforeach() 37ebcf25eaSTom Stellard endif() 38876e3993SChris Bienemanendforeach () 39876e3993SChris Bieneman 401d062daeSTom Stellardif (CLANG_LINK_CLANG_DYLIB) 411d062daeSTom Stellard set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) 421d062daeSTom Stellardendif() 431d062daeSTom Stellard 4476b26550SSylvestre Ledruadd_clang_library(clang-cpp 45876e3993SChris Bieneman SHARED 461d062daeSTom Stellard ${INSTALL_WITH_TOOLCHAIN} 47876e3993SChris Bieneman clang-shlib.cpp 48876e3993SChris Bieneman ${_OBJECTS} 49876e3993SChris Bieneman LINK_LIBS 50876e3993SChris Bieneman ${_DEPS}) 51*08bf901eSXing Xue 52461e58e7SAaron Puchertconfigure_file(simple_version_script.map.in simple_version_script.map) 53461e58e7SAaron Puchert 54eaa0a21dSAaron Puchertif (CMAKE_SYSTEM_NAME STREQUAL "Linux") 55461e58e7SAaron Puchert target_link_options(clang-cpp PRIVATE LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map) 56461e58e7SAaron Puchertendif() 57461e58e7SAaron Puchert 584f05f4c8SFangrui Song# Optimize function calls for default visibility definitions to avoid PLT and 594f05f4c8SFangrui Song# reduce dynamic relocations. 6049c35f69SBrad Smithif (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS) 614f05f4c8SFangrui Song target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions) 624f05f4c8SFangrui Songendif() 63592e935eSMartin Storsjöif (MINGW OR CYGWIN) 64592e935eSMartin Storsjö # The clang-cpp DLL is supposed to export all symbols (except for ones 65592e935eSMartin Storsjö # that are explicitly hidden). Normally, this is what happens anyway, but 66592e935eSMartin Storsjö # if there are symbols that are marked explicitly as dllexport, we'd only 67592e935eSMartin Storsjö # export them and nothing else. Therefore, add --export-all-symbols to 68592e935eSMartin Storsjö # make sure we export all symbols despite potential dllexports. 69592e935eSMartin Storsjö target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols) 70592e935eSMartin Storsjöendif() 71