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)
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)
28 if (LIBUNWIND_USE_COMPILER_RT)
29 find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
30 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
32 if (LIBUNWIND_HAS_GCC_S_LIB)
33 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
35 if (LIBUNWIND_HAS_GCC_LIB)
36 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
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})
45 set(MINGW_RUNTIME gcc_s gcc)
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})
52 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
53 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
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")
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()
71 # Check compiler flags
72 check_cxx_compiler_flag(-nostdinc++ LIBUNWIND_HAS_NOSTDINCXX_FLAG)
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)
86 set(LIBUNWIND_HAS_DL_LIB NO)
87 set(LIBUNWIND_HAS_PTHREAD_LIB NO)
89 check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
90 check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)