[clang-format] Add .inc extension to git-clang-format
[llvm-project.git] / libunwind / cmake / config-ix.cmake
blobd311477f02c690a736acba951e9f8398cccf167d
1 include(CMakePushCheckState)
2 include(CheckCCompilerFlag)
3 include(CheckCXXCompilerFlag)
4 include(CheckLibraryExists)
5 include(LLVMCheckCompilerLinkerFlag)
6 include(CheckSymbolExists)
7 include(CheckCSourceCompiles)
9 # The compiler driver may be implicitly trying to link against libunwind, which
10 # might not work if libunwind doesn't exist yet. Try to check if
11 # --unwindlib=none is supported, and use that if possible.
12 llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
14 check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
16 if (NOT LIBUNWIND_USE_COMPILER_RT)
17   if (ANDROID)
18     check_library_exists(gcc __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_LIB)
19   else ()
20     check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)
21     check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB)
22   endif ()
23 endif()
25 # libunwind is using -nostdlib++ at the link step when available,
26 # otherwise -nodefaultlibs is used. We want all our checks to also
27 # use one of these options, otherwise we may end up with an inconsistency between
28 # the flags we think we require during configuration (if the checks are
29 # performed without one of those options) and the flags that are actually
30 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
31 # required for the link to go through. We remove sanitizers from the
32 # configuration checks to avoid spurious link errors.
34 llvm_check_compiler_linker_flag(CXX "-nostdlib++" CXX_SUPPORTS_NOSTDLIBXX_FLAG)
35 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
36   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
37 else()
38   llvm_check_compiler_linker_flag(C "-nodefaultlibs" C_SUPPORTS_NODEFAULTLIBS_FLAG)
39   if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
40     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
41   endif()
42 endif()
44 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
45   if (LIBUNWIND_HAS_C_LIB)
46     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
47   endif ()
48   if (LIBUNWIND_USE_COMPILER_RT)
49     include(HandleCompilerRT)
50     find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY
51                              FLAGS ${LIBUNWIND_COMPILE_FLAGS})
52     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
53   else ()
54     if (LIBUNWIND_HAS_GCC_S_LIB)
55       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
56     endif ()
57     if (LIBUNWIND_HAS_GCC_LIB)
58       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
59     endif ()
60   endif ()
61   if (MINGW)
62     # Mingw64 requires quite a few "C" runtime libraries in order for basic
63     # programs to link successfully with -nodefaultlibs.
64     if (LIBUNWIND_USE_COMPILER_RT)
65       set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY})
66     else ()
67       set(MINGW_RUNTIME gcc_s gcc)
68     endif()
69     set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
70                         shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
71                         moldname mingwex msvcrt)
72     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
73   endif()
74   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
75     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
76   endif ()
77   if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
78     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsanitize-coverage=0")
79   endif ()
80 endif ()
82 # Check compiler pragmas
83 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
84   cmake_push_check_state()
85   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
86   check_c_source_compiles("
87 #pragma comment(lib, \"c\")
88 int main(void) { return 0; }
89 " C_SUPPORTS_COMMENT_LIB_PRAGMA)
90   cmake_pop_check_state()
91 endif()
93 # Check compiler flags
94 check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
96 # Check symbols
97 check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
98 check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
99 check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
101 if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH)
102   # This condition is copied from __libunwind_config.h
103   set(LIBUNWIND_USES_ARM_EHABI ON)
104 endif()
106 # Check libraries
107 if(FUCHSIA)
108   set(LIBUNWIND_HAS_DL_LIB NO)
109   set(LIBUNWIND_HAS_PTHREAD_LIB NO)
110 else()
111   check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
112   check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
113 endif()