blob: 4f13b787ae357fc8ad08d653be8b88f648d309a1 [file] [log] [blame]
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001include(CheckLibraryExists)
2include(CheckCXXCompilerFlag)
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +00003
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +00004if(WIN32 AND NOT MINGW)
5 # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
6 # let the default linking take care of that.
7 set(LIBCXX_HAS_C_LIB NO)
8else()
9 check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
10endif()
11
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000012if (NOT LIBCXX_USE_COMPILER_RT)
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +000013 if(WIN32 AND NOT MINGW)
14 set(LIBCXX_HAS_GCC_S_LIB NO)
15 else()
16 check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
17 endif()
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000018endif()
19
20# libc++ is built with -nodefaultlibs, so we want all our checks to also
21# use this option, otherwise we may end up with an inconsistency between
22# the flags we think we require during configuration (if the checks are
23# performed without -nodefaultlibs) and the flags that are actually
24# required during compilation (which has the -nodefaultlibs). libc is
25# required for the link to go through. We remove sanitizers from the
26# configuration checks to avoid spurious link errors.
27check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
28if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
29 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
30 if (LIBCXX_HAS_C_LIB)
31 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
32 endif ()
33 if (LIBCXX_USE_COMPILER_RT)
34 list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt)
35 elseif (LIBCXX_HAS_GCC_S_LIB)
36 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
37 endif ()
38 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
39 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
40 endif ()
Ivan Krasin575076d2016-09-01 01:38:32 +000041 if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
42 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
43 endif ()
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000044endif ()
45
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +000046if(NOT WIN32 OR MINGW)
47 include(CheckLibcxxAtomic)
48endif()
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000049
50# Check compiler flags
Eric Fiselier156a46d2015-07-30 22:30:34 +000051
Eric Fiselier2ff6e5a2014-08-18 05:03:46 +000052check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG)
53check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG)
54check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG)
55check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG)
56check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG)
57check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG)
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000058
Eric Fiselier156a46d2015-07-30 22:30:34 +000059
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000060# Check libraries
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +000061if(WIN32 AND NOT MINGW)
62 # TODO(compnerd) do we want to support an emulation layer that allows for the
63 # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
64 set(LIBCXX_HAS_PTHREAD_LIB NO)
65 set(LIBCXX_HAS_M_LIB NO)
66 set(LIBCXX_HAS_RT_LIB NO)
67else()
68 check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
69 check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
70 check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
71endif()