[runtimes] Check if pragma comment(lib, ...) is supported first
authorPetr Hosek <phosek@chromium.org>
Thu, 30 May 2019 04:40:21 +0000 (04:40 +0000)
committerPetr Hosek <phosek@chromium.org>
Thu, 30 May 2019 04:40:21 +0000 (04:40 +0000)
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.

llvm-svn: 362055

20 files changed:
libcxx/CMakeLists.txt
libcxx/cmake/config-ix.cmake
libcxx/src/algorithm.cpp
libcxx/src/chrono.cpp
libcxx/src/debug.cpp
libcxx/src/experimental/memory_resource.cpp
libcxx/src/filesystem/operations.cpp
libcxx/src/mutex.cpp
libcxx/src/shared_mutex.cpp
libcxx/src/thread.cpp
libcxxabi/CMakeLists.txt
libcxxabi/cmake/config-ix.cmake
libcxxabi/src/cxa_exception_storage.cpp
libcxxabi/src/cxa_guard_impl.h
libcxxabi/src/cxa_thread_atexit.cpp
libcxxabi/src/fallback_malloc.cpp
libunwind/CMakeLists.txt
libunwind/cmake/config-ix.cmake
libunwind/src/AddressSpace.hpp
libunwind/src/RWMutex.hpp

index 1096898..50ccbf6 100644 (file)
@@ -552,6 +552,10 @@ if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
   add_definitions(-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
 endif()
 
+if (LIBCXX_HAS_COMMENT_LIB_PRAGMA)
+  add_definitions(-D_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
 # Warning flags ===============================================================
 add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 add_compile_flags_if_supported(
index 23ae710..b2d275b 100644 (file)
@@ -1,6 +1,7 @@
 include(CheckLibraryExists)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
+include(CheckCSourceCompiles)
 
 if(WIN32 AND NOT MINGW)
   # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, lets
@@ -59,6 +60,14 @@ if (LIBCXX_SUPPORTS_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; }
+" LIBCXX_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
 if(NOT WIN32 OR MINGW)
   include(CheckLibcxxAtomic)
 endif()
@@ -72,7 +81,6 @@ check_cxx_compiler_flag(/EHs-                   LIBCXX_HAS_NO_EHS_FLAG)
 check_cxx_compiler_flag(/EHa-                   LIBCXX_HAS_NO_EHA_FLAG)
 check_cxx_compiler_flag(/GR-                    LIBCXX_HAS_NO_GR_FLAG)
 
-
 # Check libraries
 if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for the
index 5ce2a23..a110ae8 100644 (file)
@@ -10,7 +10,7 @@
 #include "random"
 #ifndef _LIBCPP_HAS_NO_THREADS
 #include "mutex"
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index a2f88c9..8f533f1 100644 (file)
@@ -37,7 +37,7 @@
 #endif
 #endif
 
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "rt")
 #endif
 
index 9502413..c4cc281 100644 (file)
@@ -15,7 +15,7 @@
 #include "__hash_table"
 #ifndef _LIBCPP_HAS_NO_THREADS
 #include "mutex"
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index 84c9508..9aa0779 100644 (file)
@@ -12,7 +12,7 @@
 #include "atomic"
 #elif !defined(_LIBCPP_HAS_NO_THREADS)
 #include "mutex"
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index 319d9f6..69350dd 100644 (file)
@@ -44,7 +44,7 @@
 #include <sys/time.h> // for gettimeofday and timeval
 #endif                // !defined(CLOCK_REALTIME)
 
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "rt")
 #endif
 
index d100f2d..33a8197 100644 (file)
@@ -13,7 +13,7 @@
 #include "__undef_macros"
 
 #ifndef _LIBCPP_HAS_NO_THREADS
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index 3f1aecf..eb3f5f3 100644 (file)
@@ -10,7 +10,7 @@
 #ifndef _LIBCPP_HAS_NO_THREADS
 
 #include "shared_mutex"
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 
index 92690f6..39bb9e9 100644 (file)
@@ -35,7 +35,7 @@
 #include <windows.h>
 #endif
 
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 
index 75c83cc..e197727 100644 (file)
@@ -441,6 +441,10 @@ if (LIBCXXABI_BAREMETAL)
     add_definitions(-DLIBCXXABI_BAREMETAL)
 endif()
 
+if (LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+  add_definitions(-D_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")
index 379b554..30d2ae2 100644 (file)
@@ -1,6 +1,7 @@
 include(CheckLibraryExists)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
+include(CheckCSourceCompiles)
 
 check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
 if (NOT LIBCXXABI_USE_COMPILER_RT)
@@ -48,6 +49,14 @@ if (LIBCXXABI_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; }
+" LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+endif()
+
 # Check compiler flags
 check_c_compiler_flag(-funwind-tables         LIBCXXABI_HAS_FUNWIND_TABLES)
 check_cxx_compiler_flag(-fno-exceptions       LIBCXXABI_HAS_NO_EXCEPTIONS_FLAG)
index 93506ac..81ba5f0 100644 (file)
@@ -46,6 +46,10 @@ extern "C" {
 #include "abort_message.h"
 #include "fallback_malloc.h"
 
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
+#pragma comment(lib, "pthread")
+#endif
+
 //  In general, we treat all threading errors as fatal.
 //  We cannot call std::terminate() because that will in turn
 //  call __cxa_get_globals() and cause infinite recursion.
index bd6b15f..935ba80 100644 (file)
@@ -50,7 +50,7 @@
 #include <stdlib.h>
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index 38787f1..3b60c29 100644 (file)
@@ -10,7 +10,7 @@
 #include "cxxabi.h"
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index bae0fa4..73ea28e 100644 (file)
@@ -13,7 +13,7 @@
 
 #include <__threading_support>
 #ifndef _LIBCXXABI_HAS_NO_THREADS
-#if defined(__unix__) &&  defined(__ELF__) && defined(__clang__)
+#if defined(__unix__) &&  defined(__ELF__) && defined(_LIBCXXABI_HAS_COMMENT_LIB_PRAGMA)
 #pragma comment(lib, "pthread")
 #endif
 #endif
index 65cd5b2..16bfb9a 100644 (file)
@@ -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
 #===============================================================================
index 670c31f..2c27ecf 100644 (file)
@@ -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)
-
index 6643953..fb07c80 100644 (file)
@@ -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
index 4f234a7..a37ac77 100644 (file)
@@ -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