blob: 730ee7e164a60f93db341554af2056e133d4cef1 [file] [log] [blame]
Michael J. Spencer626916f2010-12-10 19:47:54 +00001include(CheckLibraryExists)
Petr Hosekeffdf242017-04-06 21:06:33 +00002include(CheckCCompilerFlag)
Michael J. Spencer626916f2010-12-10 19:47:54 +00003include(CheckCXXCompilerFlag)
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +00004
Saleem Abdulrasoolcfe109b2017-01-01 20:20:38 +00005if(WIN32 AND NOT MINGW)
6 # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
7 # let the default linking take care of that.
8 set(LIBCXX_HAS_C_LIB NO)
9else()
10 check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
11endif()
12
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000013if (NOT LIBCXX_USE_COMPILER_RT)
Saleem Abdulrasoolcfe109b2017-01-01 20:20:38 +000014 if(WIN32 AND NOT MINGW)
15 set(LIBCXX_HAS_GCC_S_LIB NO)
16 else()
17 check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB)
18 endif()
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000019endif()
20
21# libc++ is built with -nodefaultlibs, so we want all our checks to also
22# use this option, otherwise we may end up with an inconsistency between
23# the flags we think we require during configuration (if the checks are
24# performed without -nodefaultlibs) and the flags that are actually
25# required during compilation (which has the -nodefaultlibs). libc is
26# required for the link to go through. We remove sanitizers from the
27# configuration checks to avoid spurious link errors.
Petr Hosekeffdf242017-04-06 21:06:33 +000028check_c_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000029if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG)
30 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
31 if (LIBCXX_HAS_C_LIB)
32 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
33 endif ()
34 if (LIBCXX_USE_COMPILER_RT)
Petr Hosek1662a852017-04-05 22:53:05 +000035 list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt)
36 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
37 list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXX_BUILTINS_LIBRARY}")
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000038 elseif (LIBCXX_HAS_GCC_S_LIB)
39 list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
40 endif ()
Reid Klecknerccc0f582017-03-31 00:34:05 +000041 if (MINGW)
42 # Mingw64 requires quite a few "C" runtime libraries in order for basic
43 # programs to link successfully with -nodefaultlibs.
Martell Malonefa3bd282017-05-25 22:37:15 +000044 if (LIBCXX_USE_COMPILER_RT)
Eric Fiselierafb54762017-05-25 22:43:42 +000045 set(MINGW_RUNTIME ${LIBCXX_BUILTINS_LIBRARY})
Martell Malonefa3bd282017-05-25 22:37:15 +000046 else ()
47 set(MINGW_RUNTIME gcc_s gcc)
48 endif()
49 set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
50 shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
51 moldname mingwex msvcrt)
52 list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
Reid Klecknerccc0f582017-03-31 00:34:05 +000053 endif()
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000054 if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
55 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
56 endif ()
Ivan Krasin25a93c52016-09-01 01:38:32 +000057 if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
58 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
59 endif ()
Saleem Abdulrasooleb930a52016-08-29 21:33:37 +000060endif ()
61
Saleem Abdulrasoolcfe109b2017-01-01 20:20:38 +000062if(NOT WIN32 OR MINGW)
63 include(CheckLibcxxAtomic)
64endif()
Michael J. Spencer626916f2010-12-10 19:47:54 +000065
66# Check compiler flags
Eric Fiseliereb6e2ea2015-07-30 22:30:34 +000067
Eric Fiselier25a15162014-08-18 05:03:46 +000068check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG)
69check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG)
70check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG)
71check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG)
72check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG)
73check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG)
Michael J. Spencer626916f2010-12-10 19:47:54 +000074
Eric Fiseliereb6e2ea2015-07-30 22:30:34 +000075
Michael J. Spencer626916f2010-12-10 19:47:54 +000076# Check libraries
Saleem Abdulrasoolcfe109b2017-01-01 20:20:38 +000077if(WIN32 AND NOT MINGW)
78 # TODO(compnerd) do we want to support an emulation layer that allows for the
79 # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
80 set(LIBCXX_HAS_PTHREAD_LIB NO)
81 set(LIBCXX_HAS_M_LIB NO)
82 set(LIBCXX_HAS_RT_LIB NO)
83else()
84 check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
85 check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
86 check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
87endif()