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) |
| 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 Krasin | 575076d | 2016-09-01 01:38:32 +0000 | [diff] [blame] | 41 | 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 Abdulrasool | bd21dad | 2016-08-29 21:33:37 +0000 | [diff] [blame] | 44 | endif () |
| 45 | |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame^] | 46 | if(NOT WIN32 OR MINGW) |
| 47 | include(CheckLibcxxAtomic) |
| 48 | endif() |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 49 | |
| 50 | # Check compiler flags |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 51 | |
Eric Fiselier | 2ff6e5a | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 52 | check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG) |
| 53 | check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG) |
| 54 | check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG) |
| 55 | check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG) |
| 56 | check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG) |
| 57 | check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 58 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 59 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 60 | # Check libraries |
Saleem Abdulrasool | 61de6f2 | 2017-01-01 20:20:38 +0000 | [diff] [blame^] | 61 | if(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) |
| 67 | else() |
| 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) |
| 71 | endif() |