Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 1 | include(CheckLibraryExists) |
| 2 | include(CheckCXXCompilerFlag) |
Saleem Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 3 | |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame] | 4 | if(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) |
| 8 | else() |
| 9 | check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) |
| 10 | endif() |
| 11 | |
Saleem Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 12 | if (NOT LIBCXX_USE_COMPILER_RT) |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame] | 13 | 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 Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 18 | endif() |
| 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. |
| 27 | check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) |
| 28 | if (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 Hosek | c868a98 | 2017-04-05 22:53:05 +0000 | [diff] [blame^] | 34 | 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 Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 37 | elseif (LIBCXX_HAS_GCC_S_LIB) |
| 38 | list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) |
| 39 | endif () |
Reid Kleckner | 4c43379 | 2017-03-31 00:34:05 +0000 | [diff] [blame] | 40 | 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 Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 45 | 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 Krasin | 575076d | 2016-09-01 01:38:32 +0000 | [diff] [blame] | 48 | 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 Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 51 | endif () |
| 52 | |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame] | 53 | if(NOT WIN32 OR MINGW) |
| 54 | include(CheckLibcxxAtomic) |
| 55 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 56 | |
| 57 | # Check compiler flags |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 58 | |
Eric Fiselier | 2ff6e5a | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 59 | check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG) |
| 60 | check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG) |
| 61 | check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG) |
| 62 | check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG) |
| 63 | check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG) |
| 64 | check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 65 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 66 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 67 | # Check libraries |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame] | 68 | if(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) |
| 74 | else() |
| 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) |
| 78 | endif() |