blob: 93b511a4b424ca78185260086556c48076d2cbf5 [file] [log] [blame]
Dan Albert0ed2e2f2014-07-03 19:35:48 +00001include(CheckLibraryExists)
Logan Chiendbcd7a32015-01-22 13:39:08 +00002include(CheckCCompilerFlag)
Dan Albert0ed2e2f2014-07-03 19:35:48 +00003include(CheckCXXCompilerFlag)
4
Petr Hosek5f3d5be2017-04-07 20:10:41 +00005check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
6if (NOT LIBCXXABI_USE_COMPILER_RT)
7 check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXXABI_HAS_GCC_S_LIB)
8endif ()
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.
17check_c_compiler_flag(-nodefaultlibs LIBCXXABI_HAS_NODEFAULTLIBS_FLAG)
18if (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 ()
36endif ()
37
Dan Albert0ed2e2f2014-07-03 19:35:48 +000038# Check compiler flags
Logan Chiendbcd7a32015-01-22 13:39:08 +000039check_c_compiler_flag(-funwind-tables LIBCXXABI_HAS_FUNWIND_TABLES)
Dan Albert0ed2e2f2014-07-03 19:35:48 +000040check_cxx_compiler_flag(-fPIC LIBCXXABI_HAS_FPIC_FLAG)
Saleem Abdulrasool123f44a2015-02-06 17:47:57 +000041check_cxx_compiler_flag(-fno-exceptions LIBCXXABI_HAS_NO_EXCEPTIONS_FLAG)
42check_cxx_compiler_flag(-fno-rtti LIBCXXABI_HAS_NO_RTTI_FLAG)
Dan Albert3c4780e2014-07-10 22:23:03 +000043check_cxx_compiler_flag(-fstrict-aliasing LIBCXXABI_HAS_FSTRICT_ALIASING_FLAG)
Dan Albert0ed2e2f2014-07-03 19:35:48 +000044check_cxx_compiler_flag(-nostdinc++ LIBCXXABI_HAS_NOSTDINCXX_FLAG)
45check_cxx_compiler_flag(-Wall LIBCXXABI_HAS_WALL_FLAG)
46check_cxx_compiler_flag(-W LIBCXXABI_HAS_W_FLAG)
Eric Fiselier6aa4f1d2017-03-04 01:02:35 +000047check_cxx_compiler_flag(-Wunused-function LIBCXXABI_HAS_WUNUSED_FUNCTION_FLAG)
Dan Albert3c4780e2014-07-10 22:23:03 +000048check_cxx_compiler_flag(-Wunused-variable LIBCXXABI_HAS_WUNUSED_VARIABLE_FLAG)
49check_cxx_compiler_flag(-Wunused-parameter LIBCXXABI_HAS_WUNUSED_PARAMETER_FLAG)
50check_cxx_compiler_flag(-Wstrict-aliasing LIBCXXABI_HAS_WSTRICT_ALIASING_FLAG)
51check_cxx_compiler_flag(-Wstrict-overflow LIBCXXABI_HAS_WSTRICT_OVERFLOW_FLAG)
Dan Albert0ed2e2f2014-07-03 19:35:48 +000052check_cxx_compiler_flag(-Wwrite-strings LIBCXXABI_HAS_WWRITE_STRINGS_FLAG)
Dan Albert3c4780e2014-07-10 22:23:03 +000053check_cxx_compiler_flag(-Wchar-subscripts LIBCXXABI_HAS_WCHAR_SUBSCRIPTS_FLAG)
54check_cxx_compiler_flag(-Wmismatched-tags LIBCXXABI_HAS_WMISMATCHED_TAGS_FLAG)
55check_cxx_compiler_flag(-Wmissing-braces LIBCXXABI_HAS_WMISSING_BRACES_FLAG)
56check_cxx_compiler_flag(-Wshorten-64-to-32 LIBCXXABI_HAS_WSHORTEN_64_TO_32_FLAG)
57check_cxx_compiler_flag(-Wsign-conversion LIBCXXABI_HAS_WSIGN_CONVERSION_FLAG)
58check_cxx_compiler_flag(-Wsign-compare LIBCXXABI_HAS_WSIGN_COMPARE_FLAG)
59check_cxx_compiler_flag(-Wshadow LIBCXXABI_HAS_WSHADOW_FLAG)
60check_cxx_compiler_flag(-Wconversion LIBCXXABI_HAS_WCONVERSION_FLAG)
61check_cxx_compiler_flag(-Wnewline-eof LIBCXXABI_HAS_WNEWLINE_EOF_FLAG)
Dan Albert3bd13ca2015-02-05 01:33:15 +000062check_cxx_compiler_flag(-Wundef LIBCXXABI_HAS_WUNDEF_FLAG)
Dan Albert0ed2e2f2014-07-03 19:35:48 +000063check_cxx_compiler_flag(-pedantic LIBCXXABI_HAS_PEDANTIC_FLAG)
64check_cxx_compiler_flag(-Werror LIBCXXABI_HAS_WERROR_FLAG)
65check_cxx_compiler_flag(-Wno-error LIBCXXABI_HAS_WNO_ERROR_FLAG)
Dan Albert0ed2e2f2014-07-03 19:35:48 +000066check_cxx_compiler_flag(/WX LIBCXXABI_HAS_WX_FLAG)
67check_cxx_compiler_flag(/WX- LIBCXXABI_HAS_NO_WX_FLAG)
68check_cxx_compiler_flag(/EHsc LIBCXXABI_HAS_EHSC_FLAG)
69check_cxx_compiler_flag(/EHs- LIBCXXABI_HAS_NO_EHS_FLAG)
70check_cxx_compiler_flag(/EHa- LIBCXXABI_HAS_NO_EHA_FLAG)
71check_cxx_compiler_flag(/GR- LIBCXXABI_HAS_NO_GR_FLAG)
Chris Bieneman8223a1d2016-08-29 22:12:21 +000072check_cxx_compiler_flag(-std=c++11 LIBCXXABI_HAS_STD_CXX11)
73
74if(LIBCXXABI_HAS_STD_CXX11)
Chris Bienemanfafcb852016-08-29 22:26:00 +000075 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Chris Bieneman8223a1d2016-08-29 22:12:21 +000076endif()
Dan Albert0ed2e2f2014-07-03 19:35:48 +000077
78# Check libraries
Jonathan Roelofs79b57012014-08-18 23:43:43 +000079check_library_exists(dl dladdr "" LIBCXXABI_HAS_DL_LIB)
Dan Albertd3217472014-07-14 17:00:29 +000080check_library_exists(pthread pthread_once "" LIBCXXABI_HAS_PTHREAD_LIB)
Dan Albert12c0c8b2014-12-18 00:03:57 +000081check_library_exists(c __cxa_thread_atexit_impl ""
82 LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)