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 | |
| 4 | check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) |
| 5 | if (NOT LIBCXX_USE_COMPILER_RT) |
| 6 | check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) |
| 7 | endif() |
| 8 | |
| 9 | # libc++ is built with -nodefaultlibs, so we want all our checks to also |
| 10 | # use this option, otherwise we may end up with an inconsistency between |
| 11 | # the flags we think we require during configuration (if the checks are |
| 12 | # performed without -nodefaultlibs) and the flags that are actually |
| 13 | # required during compilation (which has the -nodefaultlibs). libc is |
| 14 | # required for the link to go through. We remove sanitizers from the |
| 15 | # configuration checks to avoid spurious link errors. |
| 16 | check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) |
| 17 | if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) |
| 18 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") |
| 19 | if (LIBCXX_HAS_C_LIB) |
| 20 | list(APPEND CMAKE_REQUIRED_LIBRARIES c) |
| 21 | endif () |
| 22 | if (LIBCXX_USE_COMPILER_RT) |
| 23 | list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt) |
| 24 | elseif (LIBCXX_HAS_GCC_S_LIB) |
| 25 | list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) |
| 26 | endif () |
| 27 | if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) |
| 28 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") |
| 29 | endif () |
| 30 | endif () |
| 31 | |
Vasileios Kalintiris | d5ff320 | 2016-02-11 12:43:04 +0000 | [diff] [blame] | 32 | include(CheckLibcxxAtomic) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 33 | |
| 34 | # Check compiler flags |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 35 | |
Eric Fiselier | 2ff6e5a | 2014-08-18 05:03:46 +0000 | [diff] [blame] | 36 | check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG) |
| 37 | check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG) |
| 38 | check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG) |
| 39 | check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG) |
| 40 | check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG) |
| 41 | check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 42 | |
Eric Fiselier | 156a46d | 2015-07-30 22:30:34 +0000 | [diff] [blame] | 43 | |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 44 | # Check libraries |
| 45 | check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB) |
Michael J. Spencer | 8d8164e | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 46 | check_library_exists(m ccos "" LIBCXX_HAS_M_LIB) |
Howard Hinnant | 9d22b8a | 2011-05-24 12:54:00 +0000 | [diff] [blame] | 47 | check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB) |