Debian Codegraph @

clang/tools/clang-shlib/CMakeLists.txt

raw
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 if (HAIKU)
45 list(APPEND _DEPS network)
46 endif()
47
48 add_clang_library(clang-cpp
49 SHARED
50 ${INSTALL_WITH_TOOLCHAIN}
51 clang-shlib.cpp
52 ${_OBJECTS}
53 LINK_LIBS
54 ${_DEPS})
55
56 configure_file(simple_version_script.map.in simple_version_script.map)
57
58 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
59 target_link_options(clang-cpp PRIVATE LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
60 endif()
61
62 # Optimize function calls for default visibility definitions to avoid PLT and
63 # reduce dynamic relocations.
64 if (NOT APPLE AND LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
65 target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
66 endif()
67 if (MINGW OR CYGWIN)
68 # The clang-cpp DLL is supposed to export all symbols (except for ones
69 # that are explicitly hidden). Normally, this is what happens anyway, but
70 # if there are symbols that are marked explicitly as dllexport, we'd only
71 # export them and nothing else. Therefore, add --export-all-symbols to
72 # make sure we export all symbols despite potential dllexports.
73 target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols)
74 endif()