Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 1 | include(CheckLibraryExists) |
Logan Chien | dbcd7a3 | 2015-01-22 13:39:08 +0000 | [diff] [blame] | 2 | include(CheckCCompilerFlag) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 3 | include(CheckCXXCompilerFlag) |
| 4 | |
Petr Hosek | 5f3d5be | 2017-04-07 20:10:41 +0000 | [diff] [blame] | 5 | check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB) |
| 6 | if (NOT LIBCXXABI_USE_COMPILER_RT) |
| 7 | check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_S_LIB) |
| 8 | endif () |
| 9 | |
| 10 | # libc++abi is built with -nodefaultlibs, so we want all our checks to also |
| 11 | # use this option, otherwise we may end up with an inconsistency between |
| 12 | # the flags we think we require during configuration (if the checks are |
| 13 | # performed without -nodefaultlibs) and the flags that are actually |
| 14 | # required during compilation (which has the -nodefaultlibs). libc is |
| 15 | # required for the link to go through. We remove sanitizers from the |
| 16 | # configuration checks to avoid spurious link errors. |
| 17 | check_c_compiler_flag(-nodefaultlibs LIBCXXABI_HAS_NODEFAULTLIBS_FLAG) |
| 18 | if (LIBCXXABI_HAS_NODEFAULTLIBS_FLAG) |
| 19 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") |
| 20 | if (LIBCXXABI_HAS_C_LIB) |
| 21 | list(APPEND CMAKE_REQUIRED_LIBRARIES c) |
| 22 | endif () |
| 23 | if (LIBCXXABI_USE_COMPILER_RT) |
| 24 | list(APPEND CMAKE_REQUIRED_FLAGS -rtlib=compiler-rt) |
| 25 | find_compiler_rt_library(builtins LIBCXXABI_BUILTINS_LIBRARY) |
| 26 | list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBCXXABI_BUILTINS_LIBRARY}") |
| 27 | elseif (LIBCXXABI_HAS_GCC_S_LIB) |
| 28 | list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) |
| 29 | endif () |
| 30 | if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) |
| 31 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") |
| 32 | endif () |
| 33 | if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage) |
| 34 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters") |
| 35 | endif () |
| 36 | endif () |
| 37 | |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 38 | # Check compiler flags |
Logan Chien | dbcd7a3 | 2015-01-22 13:39:08 +0000 | [diff] [blame] | 39 | check_c_compiler_flag(-funwind-tables LIBCXXABI_HAS_FUNWIND_TABLES) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 40 | check_cxx_compiler_flag(-fPIC LIBCXXABI_HAS_FPIC_FLAG) |
Saleem Abdulrasool | 123f44a | 2015-02-06 17:47:57 +0000 | [diff] [blame] | 41 | check_cxx_compiler_flag(-fno-exceptions LIBCXXABI_HAS_NO_EXCEPTIONS_FLAG) |
| 42 | check_cxx_compiler_flag(-fno-rtti LIBCXXABI_HAS_NO_RTTI_FLAG) |
Dan Albert | 3c4780e | 2014-07-10 22:23:03 +0000 | [diff] [blame] | 43 | check_cxx_compiler_flag(-fstrict-aliasing LIBCXXABI_HAS_FSTRICT_ALIASING_FLAG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 44 | check_cxx_compiler_flag(-nostdinc++ LIBCXXABI_HAS_NOSTDINCXX_FLAG) |
| 45 | check_cxx_compiler_flag(-Wall LIBCXXABI_HAS_WALL_FLAG) |
| 46 | check_cxx_compiler_flag(-W LIBCXXABI_HAS_W_FLAG) |
Eric Fiselier | 6aa4f1d | 2017-03-04 01:02:35 +0000 | [diff] [blame] | 47 | check_cxx_compiler_flag(-Wunused-function LIBCXXABI_HAS_WUNUSED_FUNCTION_FLAG) |
Dan Albert | 3c4780e | 2014-07-10 22:23:03 +0000 | [diff] [blame] | 48 | check_cxx_compiler_flag(-Wunused-variable LIBCXXABI_HAS_WUNUSED_VARIABLE_FLAG) |
| 49 | check_cxx_compiler_flag(-Wunused-parameter LIBCXXABI_HAS_WUNUSED_PARAMETER_FLAG) |
| 50 | check_cxx_compiler_flag(-Wstrict-aliasing LIBCXXABI_HAS_WSTRICT_ALIASING_FLAG) |
| 51 | check_cxx_compiler_flag(-Wstrict-overflow LIBCXXABI_HAS_WSTRICT_OVERFLOW_FLAG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 52 | check_cxx_compiler_flag(-Wwrite-strings LIBCXXABI_HAS_WWRITE_STRINGS_FLAG) |
Dan Albert | 3c4780e | 2014-07-10 22:23:03 +0000 | [diff] [blame] | 53 | check_cxx_compiler_flag(-Wchar-subscripts LIBCXXABI_HAS_WCHAR_SUBSCRIPTS_FLAG) |
| 54 | check_cxx_compiler_flag(-Wmismatched-tags LIBCXXABI_HAS_WMISMATCHED_TAGS_FLAG) |
| 55 | check_cxx_compiler_flag(-Wmissing-braces LIBCXXABI_HAS_WMISSING_BRACES_FLAG) |
| 56 | check_cxx_compiler_flag(-Wshorten-64-to-32 LIBCXXABI_HAS_WSHORTEN_64_TO_32_FLAG) |
| 57 | check_cxx_compiler_flag(-Wsign-conversion LIBCXXABI_HAS_WSIGN_CONVERSION_FLAG) |
| 58 | check_cxx_compiler_flag(-Wsign-compare LIBCXXABI_HAS_WSIGN_COMPARE_FLAG) |
| 59 | check_cxx_compiler_flag(-Wshadow LIBCXXABI_HAS_WSHADOW_FLAG) |
| 60 | check_cxx_compiler_flag(-Wconversion LIBCXXABI_HAS_WCONVERSION_FLAG) |
| 61 | check_cxx_compiler_flag(-Wnewline-eof LIBCXXABI_HAS_WNEWLINE_EOF_FLAG) |
Dan Albert | 3bd13ca | 2015-02-05 01:33:15 +0000 | [diff] [blame] | 62 | check_cxx_compiler_flag(-Wundef LIBCXXABI_HAS_WUNDEF_FLAG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 63 | check_cxx_compiler_flag(-pedantic LIBCXXABI_HAS_PEDANTIC_FLAG) |
| 64 | check_cxx_compiler_flag(-Werror LIBCXXABI_HAS_WERROR_FLAG) |
| 65 | check_cxx_compiler_flag(-Wno-error LIBCXXABI_HAS_WNO_ERROR_FLAG) |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 66 | check_cxx_compiler_flag(/WX LIBCXXABI_HAS_WX_FLAG) |
| 67 | check_cxx_compiler_flag(/WX- LIBCXXABI_HAS_NO_WX_FLAG) |
| 68 | check_cxx_compiler_flag(/EHsc LIBCXXABI_HAS_EHSC_FLAG) |
| 69 | check_cxx_compiler_flag(/EHs- LIBCXXABI_HAS_NO_EHS_FLAG) |
| 70 | check_cxx_compiler_flag(/EHa- LIBCXXABI_HAS_NO_EHA_FLAG) |
| 71 | check_cxx_compiler_flag(/GR- LIBCXXABI_HAS_NO_GR_FLAG) |
Chris Bieneman | 8223a1d | 2016-08-29 22:12:21 +0000 | [diff] [blame] | 72 | check_cxx_compiler_flag(-std=c++11 LIBCXXABI_HAS_STD_CXX11) |
| 73 | |
| 74 | if(LIBCXXABI_HAS_STD_CXX11) |
Chris Bieneman | fafcb85 | 2016-08-29 22:26:00 +0000 | [diff] [blame] | 75 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Chris Bieneman | 8223a1d | 2016-08-29 22:12:21 +0000 | [diff] [blame] | 76 | endif() |
Dan Albert | 0ed2e2f | 2014-07-03 19:35:48 +0000 | [diff] [blame] | 77 | |
| 78 | # Check libraries |
Jonathan Roelofs | 79b5701 | 2014-08-18 23:43:43 +0000 | [diff] [blame] | 79 | check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB) |
Dan Albert | d321747 | 2014-07-14 17:00:29 +0000 | [diff] [blame] | 80 | check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB) |
Dan Albert | 12c0c8b | 2014-12-18 00:03:57 +0000 | [diff] [blame] | 81 | check_library_exists(c __cxa_thread_atexit_impl "" |
| 82 | LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) |