[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / cmake / config-ix.cmake
blob079cabf25da5a26d7a73609a94f78559d887cf54
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     list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}")
45   else ()
46     if (LIBCXXABI_HAS_GCC_S_LIB)
47       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
48     endif ()
49     if (LIBCXXABI_HAS_GCC_LIB)
50       list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
51     endif ()
52   endif ()
53   if (MINGW)
54     # Mingw64 requires quite a few "C" runtime libraries in order for basic
55     # programs to link successfully with -nodefaultlibs.
56     if (LIBCXXABI_USE_COMPILER_RT)
57       set(MINGW_RUNTIME ${LIBCXXABI_BUILTINS_LIBRARY})
58     else ()
59       set(MINGW_RUNTIME gcc_s gcc)
60     endif()
61     set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
62                         shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
63                         moldname mingwex msvcrt)
64     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
65   endif()
66   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
67     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
68   endif ()
69   if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
70     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsanitize-coverage=0")
71   endif ()
72 endif ()
74 # Check compiler pragmas
75 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
76   cmake_push_check_state()
77   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
78   check_c_source_compiles("
79 #pragma comment(lib, \"c\")
80 int main() { return 0; }
81 " C_SUPPORTS_COMMENT_LIB_PRAGMA)
82   cmake_pop_check_state()
83 endif()
85 # Check compiler flags
86 check_cxx_compiler_flag(-nostdinc++ CXX_SUPPORTS_NOSTDINCXX_FLAG)
88 # Check libraries
89 if(FUCHSIA)
90   set(LIBCXXABI_HAS_DL_LIB NO)
91   set(LIBCXXABI_HAS_PTHREAD_LIB NO)
92   check_library_exists(c __cxa_thread_atexit_impl ""
93     LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
94   set(LIBCXXABI_HAS_SYSTEM_LIB NO)
95 else()
96   check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB)
97   check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB)
98   check_library_exists(c __cxa_thread_atexit_impl ""
99     LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
100   check_library_exists(System write "" LIBCXXABI_HAS_SYSTEM_LIB)
101 endif()