[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / libunwind / cmake / config-ix.cmake
blob9c8089cfe2150ec142f4d71e7c67b47a82acd03e
1 include(CMakePushCheckState)
2 include(CheckCCompilerFlag)
3 include(CheckCXXCompilerFlag)
4 include(CheckLibraryExists)
5 include(CheckSymbolExists)
6 include(CheckCSourceCompiles)
8 check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
10 if (NOT LIBUNWIND_USE_COMPILER_RT)
11   check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)
12   check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB)
13 endif()
15 # libunwind is built with -nodefaultlibs, so we want all our checks to also
16 # use this option, otherwise we may end up with an inconsistency between
17 # the flags we think we require during configuration (if the checks are
18 # performed without -nodefaultlibs) and the flags that are actually
19 # required during compilation (which has the -nodefaultlibs). libc is
20 # required for the link to go through. We remove sanitizers from the
21 # configuration checks to avoid spurious link errors.
22 check_c_compiler_flag(-nodefaultlibs LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
23 if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
24   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
25   if (LIBUNWIND_HAS_C_LIB)
26     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
27   endif ()
28   if (LIBUNWIND_USE_COMPILER_RT)
29     find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
30     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
31   else ()
32     if (LIBUNWIND_HAS_GCC_S_LIB)
33       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
34     endif ()
35     if (LIBUNWIND_HAS_GCC_LIB)
36       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
37     endif ()
38   endif ()
39   if (MINGW)
40     # Mingw64 requires quite a few "C" runtime libraries in order for basic
41     # programs to link successfully with -nodefaultlibs.
42     if (LIBUNWIND_USE_COMPILER_RT)
43       set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY})
44     else ()
45       set(MINGW_RUNTIME gcc_s gcc)
46     endif()
47     set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
48                         shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
49                         moldname mingwex msvcrt)
50     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
51   endif()
52   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
53     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
54   endif ()
55   if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
56     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
57   endif ()
58 endif ()
60 # Check compiler pragmas
61 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
62   cmake_push_check_state()
63   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
64   check_c_source_compiles("
65 #pragma comment(lib, \"c\")
66 int main() { return 0; }
67 " LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
68   cmake_pop_check_state()
69 endif()
71 # Check compiler flags
72 check_cxx_compiler_flag(-nostdinc++ LIBUNWIND_HAS_NOSTDINCXX_FLAG)
74 # Check symbols
75 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
76 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
77 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
79 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH)
80   # This condition is copied from __libunwind_config.h
81   set(LIBUNWIND_USES_ARM_EHABI ON)
82 endif()
84 # Check libraries
85 if(FUCHSIA)
86   set(LIBUNWIND_HAS_DL_LIB NO)
87   set(LIBUNWIND_HAS_PTHREAD_LIB NO)
88 else()
89   check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
90   check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
91 endif()