2019-05-30 13:38:06 +08:00
|
|
|
include(CMakePushCheckState)
|
2015-04-25 09:46:35 +08:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckLibraryExists)
|
2019-12-06 22:26:35 +08:00
|
|
|
include(CheckSymbolExists)
|
2019-05-30 12:40:21 +08:00
|
|
|
include(CheckCSourceCompiles)
|
2015-04-25 09:46:35 +08:00
|
|
|
|
2019-01-29 03:26:41 +08:00
|
|
|
check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
|
2017-04-12 10:28:07 +08:00
|
|
|
|
|
|
|
if (NOT LIBUNWIND_USE_COMPILER_RT)
|
2020-04-24 12:19:11 +08:00
|
|
|
if (ANDROID)
|
|
|
|
check_library_exists(gcc __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_LIB)
|
|
|
|
else ()
|
|
|
|
check_library_exists(gcc_s __gcc_personality_v0 "" LIBUNWIND_HAS_GCC_S_LIB)
|
|
|
|
check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB)
|
|
|
|
endif ()
|
2017-04-12 10:28:07 +08:00
|
|
|
endif()
|
|
|
|
|
2021-02-17 02:02:22 +08:00
|
|
|
# libunwind is using -nostdlib++ at the link step when available,
|
|
|
|
# otherwise -nodefaultlibs is used. We want all our checks to also
|
|
|
|
# use one of these options, otherwise we may end up with an inconsistency between
|
2017-04-12 10:28:07 +08:00
|
|
|
# the flags we think we require during configuration (if the checks are
|
2021-02-17 02:02:22 +08:00
|
|
|
# performed without one of those options) and the flags that are actually
|
|
|
|
# required during compilation (which has the -nostdlib++ or -nodefaultlibs). libc is
|
2017-04-12 10:28:07 +08:00
|
|
|
# required for the link to go through. We remove sanitizers from the
|
|
|
|
# configuration checks to avoid spurious link errors.
|
2021-02-17 02:02:22 +08:00
|
|
|
|
|
|
|
check_c_compiler_flag(-nostdlib++ LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
|
|
|
|
if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
|
|
|
|
else()
|
|
|
|
check_c_compiler_flag(-nodefaultlibs LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
|
|
|
|
if (LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (LIBUNWIND_SUPPORTS_NOSTDLIBXX_FLAG OR LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
|
2017-04-12 10:28:07 +08:00
|
|
|
if (LIBUNWIND_HAS_C_LIB)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES c)
|
|
|
|
endif ()
|
|
|
|
if (LIBUNWIND_USE_COMPILER_RT)
|
|
|
|
find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBUNWIND_BUILTINS_LIBRARY}")
|
2018-10-09 02:35:00 +08:00
|
|
|
else ()
|
|
|
|
if (LIBUNWIND_HAS_GCC_S_LIB)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
|
|
|
|
endif ()
|
|
|
|
if (LIBUNWIND_HAS_GCC_LIB)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
|
|
|
|
endif ()
|
2017-04-12 10:28:07 +08:00
|
|
|
endif ()
|
2017-10-03 04:46:37 +08:00
|
|
|
if (MINGW)
|
|
|
|
# Mingw64 requires quite a few "C" runtime libraries in order for basic
|
|
|
|
# programs to link successfully with -nodefaultlibs.
|
|
|
|
if (LIBUNWIND_USE_COMPILER_RT)
|
|
|
|
set(MINGW_RUNTIME ${LIBUNWIND_BUILTINS_LIBRARY})
|
|
|
|
else ()
|
|
|
|
set(MINGW_RUNTIME gcc_s gcc)
|
|
|
|
endif()
|
|
|
|
set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
|
|
|
|
shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
|
|
|
|
moldname mingwex msvcrt)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
|
|
|
|
endif()
|
2017-04-12 10:28:07 +08:00
|
|
|
if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
|
|
|
|
endif ()
|
|
|
|
if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2019-05-30 12:40:21 +08:00
|
|
|
# Check compiler pragmas
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-05-30 13:38:06 +08:00
|
|
|
cmake_push_check_state()
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unknown-pragmas")
|
2019-05-30 12:40:21 +08:00
|
|
|
check_c_source_compiles("
|
|
|
|
#pragma comment(lib, \"c\")
|
|
|
|
int main() { return 0; }
|
|
|
|
" LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
|
2019-05-30 13:38:06 +08:00
|
|
|
cmake_pop_check_state()
|
2019-05-30 12:40:21 +08:00
|
|
|
endif()
|
|
|
|
|
2015-04-25 09:46:35 +08:00
|
|
|
# Check compiler flags
|
2019-10-12 06:22:29 +08:00
|
|
|
check_cxx_compiler_flag(-nostdinc++ LIBUNWIND_HAS_NOSTDINCXX_FLAG)
|
2015-04-25 09:46:35 +08:00
|
|
|
|
2019-12-06 22:26:35 +08:00
|
|
|
# Check symbols
|
|
|
|
check_symbol_exists(__arm__ "" LIBUNWIND_TARGET_ARM)
|
|
|
|
check_symbol_exists(__USING_SJLJ_EXCEPTIONS__ "" LIBUNWIND_USES_SJLJ_EXCEPTIONS)
|
|
|
|
check_symbol_exists(__ARM_DWARF_EH__ "" LIBUNWIND_USES_DWARF_EH)
|
|
|
|
|
|
|
|
if(LIBUNWIND_TARGET_ARM AND NOT LIBUNWIND_USES_SJLJ_EXCEPTIONS AND NOT LIBUNWIND_USES_DWARF_EH)
|
|
|
|
# This condition is copied from __libunwind_config.h
|
|
|
|
set(LIBUNWIND_USES_ARM_EHABI ON)
|
|
|
|
endif()
|
2019-12-18 09:18:24 +08:00
|
|
|
|
|
|
|
# Check libraries
|
|
|
|
if(FUCHSIA)
|
|
|
|
set(LIBUNWIND_HAS_DL_LIB NO)
|
|
|
|
set(LIBUNWIND_HAS_PTHREAD_LIB NO)
|
|
|
|
else()
|
|
|
|
check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
|
|
|
|
check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
|
|
|
|
endif()
|