[lld][WebAssembly] Add `--table-base` setting
[llvm-project.git] / llvm-libgcc / lib / CMakeLists.txt
blobd895a21554b03c96ae29ae6a3b5bebf25549dfda
1 include(CheckLibraryExists)
2 include(GNUInstallDirs)
3 include(ExtendPath)
5 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
7 add_custom_target(gcc_s_ver ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gcc_s.ver")
8 set(LLVM_LIBGCC_GCC_S_VER "${CMAKE_CURRENT_BINARY_DIR}/gcc_s.ver")
10 add_custom_target(gcc_s.ver ALL
11   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/gcc_s.ver"
12   COMMAND
13     "${CMAKE_C_COMPILER}"
14     "-E"
15     "-xc" "${CMAKE_CURRENT_SOURCE_DIR}/gcc_s.ver"
16     "-o" "${CMAKE_CURRENT_BINARY_DIR}/gcc_s.ver"
18 set_target_properties(gcc_s.ver PROPERTIES
19   OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/gcc_s.ver")
21 add_library(libgcc_s SHARED blank.c)
22 add_dependencies(libgcc_s gcc_s_ver)
23 set_target_properties(libgcc_s
24   PROPERTIES
25     LINKER_LANGUAGE C
26     OUTPUT_NAME "unwind"
27     VERSION "1.0"
28     SOVERSION "1"
29     POSITION_INDEPENDENT_CODE ON)
30 string(REGEX MATCH "[^-]+" LLVM_LIBGCC_TARGET_ARCH ${CMAKE_C_COMPILER_TARGET})
31 target_link_libraries(libgcc_s PRIVATE
32   $<TARGET_OBJECTS:unwind_static>
33   $<TARGET_OBJECTS:clang_rt.builtins-${LLVM_LIBGCC_TARGET_ARCH}>
35 target_link_options(libgcc_s PRIVATE
36   -nostdlib
37   -Wl,--version-script,$<TARGET_PROPERTY:gcc_s.ver,OUTPUT_PATH>)
39 check_library_exists(m sin "" LLVM_LIBGCC_HAS_LIBM)
40 target_link_libraries(libgcc_s PRIVATE
41   $<$<BOOL:LLVM_LIBGCC_HAS_LIBM>:m>
42   c
45 extend_path(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}" "${LIBUNWIND_INSTALL_LIBRARY_DIR}")
46 #string(REPLACE "${CMAKE_INSTALL_FULL_LIBDIR}/" "" LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}")
48 install(TARGETS libgcc_s
49         LIBRARY DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind
50         ARCHIVE DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind
51         RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT unwind)
53 get_compiler_rt_install_dir(${LLVM_LIBGCC_TARGET_ARCH} install_dir_builtins)
54 string(REGEX REPLACE "^lib/" "" install_dir_builtins "${install_dir_builtins}")
55 string(FIND "${install_dir_builtins}" "clang" install_path_contains_triple)
56 if(install_path_contains_triple EQUAL -1)
57   set(builtins_suffix "-${LLVM_LIBGCC_TARGET_ARCH}")
58 else()
59   string(PREPEND install_dir_builtins "../")
60 endif()
61 install(CODE "execute_process(
62                 COMMAND \"\${CMAKE_COMMAND}\" -E
63                 create_symlink ${install_dir_builtins}/libclang_rt.builtins${builtins_suffix}.a libgcc.a
64                 WORKING_DIRECTORY \"\$ENV{DESTDIR}${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}\")"
65         COMPONENT unwind)
67 install(CODE "execute_process(
68                 COMMAND \"\${CMAKE_COMMAND}\" -E
69                 create_symlink libunwind.a libgcc_eh.a
70                 WORKING_DIRECTORY \"\$ENV{DESTDIR}${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}\")"
71         COMPONENT unwind)
72 install(CODE "execute_process(
73                COMMAND \"\${CMAKE_COMMAND}\" -E
74                create_symlink libunwind.so libgcc_s.so.1.0
75                WORKING_DIRECTORY \"\$ENV{DESTDIR}${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}\")"
76         COMPONENT unwind)
77 install(CODE "execute_process(
78                 COMMAND \"\${CMAKE_COMMAND}\" -E
79                 create_symlink libgcc_s.so.1.0 libgcc_s.so.1
80                 WORKING_DIRECTORY \"\$ENV{DESTDIR}${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}\")"
81         COMPONENT unwind)
82 install(CODE "execute_process(
83                 COMMAND \"\${CMAKE_COMMAND}\" -E
84                 create_symlink libgcc_s.so.1 libgcc_s.so
85                 WORKING_DIRECTORY \"\$ENV{DESTDIR}${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}\")"
86         COMPONENT unwind)