Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / cmake / config-ix.cmake
blob702fe7d1d72f777620388d59efc82794dac14cf3
1 include(CMakePushCheckState)
2 include(CheckLibraryExists)
3 include(CheckCCompilerFlag)
4 include(CheckCXXCompilerFlag)
5 include(CheckCSourceCompiles)
7 check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
8 if (NOT LIBCXXABI_USE_COMPILER_RT)
9   if (ANDROID)
10     check_library_exists(gcc __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_LIB)
11   else ()
12     check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_S_LIB)
13     check_library_exists(gcc __aeabi_uldivmod "" LIBCXXABI_HAS_GCC_LIB)
14   endif ()
15 endif ()
17 # libc++abi is using -nostdlib++ at the link step when available,
18 # otherwise -nodefaultlibs is used. We want all our checks to also
19 # use one of these options, otherwise we may end up with an inconsistency between
20 # the flags we think we require during configuration (if the checks are
21 # performed without -nodefaultlibs) and the flags that are actually
22 # required during compilation (which has the -nodefaultlibs). libc is
23 # required for the link to go through. We remove sanitizers from the
24 # configuration checks to avoid spurious link errors.
26 check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
27 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
28   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
29 else()
30   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
31   if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
32     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
33   endif()
34 endif()
36 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
37   if (LIBCXXABI_HAS_C_LIB)
38     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
39   endif ()
40   if (LIBCXXABI_USE_COMPILER_RT)
41     include(HandleCompilerRT)
42     find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY
43                              FLAGS "${LIBCXXABI_COMPILE_FLAGS}")
44     if (LIBCXXABI_BUILTINS_LIBRARY)
45       list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
46     else()
47       message(WARNING "Could not find builtins library from libc++abi")
48     endif()
49   else ()
50     if (LIBCXXABI_HAS_GCC_S_LIB)
51       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
52     endif ()
53     if (LIBCXXABI_HAS_GCC_LIB)
54       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
55     endif ()
56   endif ()
57   if (MINGW)
58     # Mingw64 requires quite a few "C" runtime libraries in order for basic
59     # programs to link successfully with -nodefaultlibs.
60     if (LIBCXXABI_USE_COMPILER_RT)
61       set(MINGW_RUNTIME ${LIBCXXABI_BUILTINS_LIBRARY})
62     else ()
63       set(MINGW_RUNTIME gcc_s gcc)
64     endif()
65     set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
66                         shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
67                         moldname mingwex msvcrt)
68     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
69   endif()
70   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
71     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
72   endif ()
73   if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
74     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsanitize-coverage=0")
75   endif ()
76 endif ()
78 # Check compiler pragmas
79 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
80   cmake_push_check_state()
81   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
82   check_c_source_compiles("
83 #pragma comment(lib, \"c\")
84 int main(void) { return 0; }
85 " C_SUPPORTS_COMMENT_LIB_PRAGMA)
86   cmake_pop_check_state()
87 endif()
89 # Check compiler flags
90 check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
92 # Check libraries
93 if(FUCHSIA)
94   set(LIBCXXABI_HAS_DL_LIB NO)
95   set(LIBCXXABI_HAS_PTHREAD_LIB NO)
96   check_library_exists(c __cxa_thread_atexit_impl ""
97     LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
98 else()
99   check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB)
100   check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB)
101   check_library_exists(c __cxa_thread_atexit_impl ""
102     LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
103 endif()