blob: fa3a07f4f198000c259adf711e68c2d625c88bb6 [file] [log] [blame]
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001include(CheckLibraryExists)
2include(CheckCXXCompilerFlag)
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +00003
4check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
5if (NOT LIBCXX_USE_COMPILER_RT)
6 check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
7endif()
8
9# libc++ is built with -nodefaultlibs, so we want all our checks to also
10# use this option, otherwise we may end up with an inconsistency between
11# the flags we think we require during configuration (if the checks are
12# performed without -nodefaultlibs) and the flags that are actually
13# required during compilation (which has the -nodefaultlibs). libc is
14# required for the link to go through. We remove sanitizers from the
15# configuration checks to avoid spurious link errors.
16check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
17if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
18 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
19 if (LIBCXX_HAS_C_LIB)
20 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
21 endif ()
22 if (LIBCXX_USE_COMPILER_RT)
23 list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt)
24 elseif (LIBCXX_HAS_GCC_S_LIB)
25 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
26 endif ()
27 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
28 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
29 endif ()
30endif ()
31
Vasileios Kalintirisd5ff3202016-02-11 12:43:04 +000032include(CheckLibcxxAtomic)
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000033
34# Check compiler flags
Eric Fiselier156a46d2015-07-30 22:30:34 +000035
Eric Fiselier2ff6e5a2014-08-18 05:03:46 +000036check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG)
37check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG)
38check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG)
39check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG)
40check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG)
41check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG)
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000042
Eric Fiselier156a46d2015-07-30 22:30:34 +000043
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000044# Check libraries
45check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000046check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
Howard Hinnant9d22b8a2011-05-24 12:54:00 +000047check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)