1 include(CheckLibraryExists)
2 include(GNUInstallDirs)
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"
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
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
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>
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}")
59 string(PREPEND install_dir_builtins "../")
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}\")"
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}\")"
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}\")"
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}\")"
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}\")"