summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2019-05-30 04:40:21 +0000
committerPetr Hosek <phosek@chromium.org>2019-05-30 04:40:21 +0000
commit557ff8053bb36f0eb6ce188c19a74845efcb38d1 (patch)
treee37146b9a4e7eacbdc725f3ea5e8ee209901875a
parent865249f0c4889e491c3717dc7be32a827f316b4e (diff)
[runtimes] Check if pragma comment(lib, ...) is supported first
This fixes the issue introduced by r362048 where we always use pragma comment(lib, ...) for dependent libraries when the compiler is Clang, but older Clang versions don't support this pragma so we need to check first if it's supported before using it. git-svn-id: https://llvm.org/svn/llvm-project/libunwind/trunk@362055 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/config-ix.cmake11
-rw-r--r--src/AddressSpace.hpp2
-rw-r--r--src/RWMutex.hpp2
4 files changed, 15 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65cd5b2..16bfb9a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -362,6 +362,10 @@ if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED)
add_definitions(-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
endif()
+if (LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+ add_definitions(-D_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
#===============================================================================
# Setup Source Code
#===============================================================================
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 670c31f..2c27ecf 100644
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -1,7 +1,7 @@
-
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
+include(CheckCSourceCompiles)
check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
@@ -55,6 +55,14 @@ if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
endif ()
endif ()
+# Check compiler pragmas
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ check_c_source_compiles("
+#pragma comment(lib, \"c\")
+int main() { return 0; }
+" LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
# Check compiler flags
check_c_compiler_flag(-funwind-tables LIBUNWIND_HAS_FUNWIND_TABLES)
check_cxx_compiler_flag(-fno-exceptions LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG)
@@ -96,4 +104,3 @@ endif()
check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
-
diff --git a/src/AddressSpace.hpp b/src/AddressSpace.hpp
index 6643953..fb07c80 100644
--- a/src/AddressSpace.hpp
+++ b/src/AddressSpace.hpp
@@ -27,7 +27,7 @@
#if _LIBUNWIND_USE_DLADDR
#include <dlfcn.h>
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "dl")
#endif
#endif
diff --git a/src/RWMutex.hpp b/src/RWMutex.hpp
index 4f234a7..a37ac77 100644
--- a/src/RWMutex.hpp
+++ b/src/RWMutex.hpp
@@ -17,7 +17,7 @@
#include <windows.h>
#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
#include <pthread.h>
-#if defined(__unix__) && defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif