blob: 5f31cfac3289062f3e976f21d4e492250140097a [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)
Petr Hosekc868a982017-04-05 22:53:05 +000034 list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
35 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
36 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXX_BUILTINS_LIBRARY}")
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000037 elseif (LIBCXX_HAS_GCC_S_LIB)
38 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
39 endif ()
Reid Kleckner4c433792017-03-31 00:34:05 +000040 if (MINGW)
41 # Mingw64 requires quite a few "C" runtime libraries in order for basic
42 # programs to link successfully with -nodefaultlibs.
43 list(APPEND CMAKE_REQUIRED_LIBRARIES mingw32 gcc gcc_eh mingwex msvcrt gcc)
44 endif()
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000045 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
46 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
47 endif ()
Ivan Krasin575076d2016-09-01 01:38:32 +000048 if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
49 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
50 endif ()
Saleem Abdulrasoolbd21dad2016-08-29 21:33:37 +000051endif ()
52
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +000053if(NOT WIN32 OR MINGW)
54 include(CheckLibcxxAtomic)
55endif()
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000056
57# Check compiler flags
Eric Fiselier156a46d2015-07-30 22:30:34 +000058
Eric Fiselier2ff6e5a2014-08-18 05:03:46 +000059check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG)
60check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG)
61check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG)
62check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG)
63check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG)
64check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG)
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000065
Eric Fiselier156a46d2015-07-30 22:30:34 +000066
Michael J. Spencer8d8164e2010-12-10 19:47:54 +000067# Check libraries
Saleem Abdulrasool61de6f22017-01-01 20:20:38 +000068if(WIN32 AND NOT MINGW)
69 # TODO(compnerd) do we want to support an emulation layer that allows for the
70 # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
71 set(LIBCXX_HAS_PTHREAD_LIB NO)
72 set(LIBCXX_HAS_M_LIB NO)
73 set(LIBCXX_HAS_RT_LIB NO)
74else()
75 check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
76 check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
77 check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
78endif()