1include(CMakePushCheckState) 2include(CheckLibraryExists) 3include(CheckCCompilerFlag) 4include(CheckCXXCompilerFlag) 5include(CheckCSourceCompiles) 6 7check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB) 8if (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 () 15endif () 16 17# libc++abi is built with -nodefaultlibs, so we want all our checks to also 18# use this option, otherwise we may end up with an inconsistency between 19# the flags we think we require during configuration (if the checks are 20# performed without -nodefaultlibs) and the flags that are actually 21# required during compilation (which has the -nodefaultlibs). libc is 22# required for the link to go through. We remove sanitizers from the 23# configuration checks to avoid spurious link errors. 24check_c_compiler_flag(-nodefaultlibs LIBCXXABI_HAS_NODEFAULTLIBS_FLAG) 25if (LIBCXXABI_HAS_NODEFAULTLIBS_FLAG) 26 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") 27 if (LIBCXXABI_HAS_C_LIB) 28 list(APPEND CMAKE_REQUIRED_LIBRARIES c) 29 endif () 30 if (LIBCXXABI_USE_COMPILER_RT) 31 list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt) 32 find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY) 33 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}") 34 else () 35 if (LIBCXXABI_HAS_GCC_S_LIB) 36 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) 37 endif () 38 if (LIBCXXABI_HAS_GCC_LIB) 39 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc) 40 endif () 41 endif () 42 if (MINGW) 43 # Mingw64 requires quite a few "C" runtime libraries in order for basic 44 # programs to link successfully with -nodefaultlibs. 45 if (LIBCXXABI_USE_COMPILER_RT) 46 set(MINGW_RUNTIME ${LIBCXXABI_BUILTINS_LIBRARY}) 47 else () 48 set(MINGW_RUNTIME gcc_s gcc) 49 endif() 50 set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32 51 shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME} 52 moldname mingwex msvcrt) 53 list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES}) 54 endif() 55 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) 56 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") 57 endif () 58 if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage) 59 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters") 60 endif () 61endif () 62 63# Check compiler pragmas 64if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 65 cmake_push_check_state() 66 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas") 67 check_c_source_compiles(" 68#pragma comment(lib, \"c\") 69int main() { return 0; } 70" LIBCXXABI_HAS_COMMENT_LIB_PRAGMA) 71 cmake_pop_check_state() 72endif() 73 74# Check compiler flags 75check_cxx_compiler_flag(-nostdinc++ LIBCXXABI_HAS_NOSTDINCXX_FLAG) 76 77# Check libraries 78if(FUCHSIA) 79 set(LIBCXXABI_HAS_DL_LIB NO) 80 set(LIBCXXABI_HAS_PTHREAD_LIB NO) 81 check_library_exists(c __cxa_thread_atexit_impl "" 82 LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) 83 set(LIBCXXABI_HAS_SYSTEM_LIB NO) 84else() 85 check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB) 86 check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB) 87 check_library_exists(c __cxa_thread_atexit_impl "" 88 LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) 89 check_library_exists(System write "" LIBCXXABI_HAS_SYSTEM_LIB) 90endif() 91