Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -1,4 +1,5 @@ +include(CMakePushCheckState) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLibraryExists) @@ -10,6 +11,28 @@ check_library_exists(gcc __absvdi2 "" LIBUNWIND_HAS_GCC_LIB) endif() +if (LIBUNWIND_USE_COMPILER_RT) + find_compiler_rt_library(builtins LIBUNWIND_BUILTINS_LIBRARY) +elseif(LIBUNWIND_HAS_GCC_S_LIB) + set(LIBUNWIND_BUILTINS_LIBRARY gcc_s) +elseif(LIBUNWIND_HAS_GCC_LIB) + set(LIBUNWIND_BUILTINS_LIBRARY gcc) +endif() + +function(check_linker_flag flag out_var) + cmake_push_check_state() + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") + if(MINGW) + set(CMAKE_REQUIRED_LIBRARIES mingw32 mingwex moldname msvcrt kernel32 "${LIBUNWIND_BUILTINS_LIBRARY}") + elseif(APPLE) + set(CMAKE_REQUIRED_LIBRARIES System) + elseif(LIBUNWIND_HAS_C_LIB) + set(CMAKE_REQUIRED_LIBRARIES c) + endif() + check_c_compiler_flag("" ${out_var}) + cmake_pop_check_state() +endfunction() + # libunwind is built with -nodefaultlibs, so we want all our checks to also # use this option, otherwise we may end up with an inconsistency between # the flags we think we require during configuration (if the checks are @@ -17,14 +40,15 @@ # required during compilation (which has the -nodefaultlibs). libc is # required for the link to go through. We remove sanitizers from the # configuration checks to avoid spurious link errors. -check_c_compiler_flag(-nodefaultlibs LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) +check_linker_flag(-nodefaultlibs LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs") - if (LIBUNWIND_HAS_C_LIB) + if (APPLE) + list(APPEND CMAKE_REQUIRED_LIBRARIES System) + elseif (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}") else () if (LIBUNWIND_HAS_GCC_S_LIB)