[PATCH] D52995: [CMake] Fix the -nodefaultlibs check.

Charles Davis via Phabricator reviews at reviews.llvm.org
Mon Oct 8 11:51:58 PDT 2018


cdavis5x created this revision.
cdavis5x added reviewers: mstorsjo, rnk, beanz.
Herald added subscribers: libcxx-commits, christof, mgorny.

This is a linker flag, so we want to pass it in `CMAKE_REQUIRED_FLAGS`.
That way, it'll get passed during the link step.

Add some libraries on MinGW and Darwin, which need them to successfully
link.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D52995

Files:
  cmake/config-ix.cmake


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,21 +11,44 @@
   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
 # performed without -nodefaultlibs) and the flags that are actually
 # 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52995.168694.patch
Type: text/x-patch
Size: 2249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181008/dcc6d7eb/attachment-0001.bin>


More information about the libcxx-commits mailing list