smeenai created this revision.
smeenai added reviewers: beanz, compnerd, EricWF, mclow.lists.
smeenai added a subscriber: cfe-commits.

The purpose of the check is to see if atomics are present and if they
require an explicit -latomic to link. We can achieve this equally well
by testing for C11 atomics.

The main motivation is to ease bootstrapping slightly, by cutting down
on the number of configuration steps which require an existing C++
library. It also eases cross compilation against non-standard C++
libraries, which would otherwise require passing a -nostdlib to the
driver and adjusting CMAKE_REQUIRED_LIBRARIES accordingly.

https://reviews.llvm.org/D23719

Files:
  cmake/Modules/CheckLibcxxAtomic.cmake

Index: cmake/Modules/CheckLibcxxAtomic.cmake
===================================================================
--- cmake/Modules/CheckLibcxxAtomic.cmake
+++ cmake/Modules/CheckLibcxxAtomic.cmake
@@ -1,4 +1,4 @@
-INCLUDE(CheckCXXSourceCompiles)
+INCLUDE(CheckCSourceCompiles)
 
 # Sometimes linking against libatomic is required for atomic ops, if
 # the platform doesn't support lock-free atomics.
@@ -9,17 +9,16 @@
 
 function(check_cxx_atomics varname)
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem 
${LIBCXX_SOURCE_DIR}/include")
+  set(CMAKE_REQUIRED_FLAGS "-std=c11")
   if (${LIBCXX_GCC_TOOLCHAIN})
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} 
--gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
   endif()
-  check_cxx_source_compiles("
-#include <cstdint>
-#include <atomic>
-std::atomic<uintptr_t> x;
-std::atomic<uintmax_t> y;
+  check_c_source_compiles("
+#include <stdatomic.h>
+atomic_uintptr_t x;
+atomic_uintmax_t y;
 int main() {
-  return x + y;
+  return atomic_load(&x) + atomic_load(&y);
 }
 " ${varname})
   set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})


Index: cmake/Modules/CheckLibcxxAtomic.cmake
===================================================================
--- cmake/Modules/CheckLibcxxAtomic.cmake
+++ cmake/Modules/CheckLibcxxAtomic.cmake
@@ -1,4 +1,4 @@
-INCLUDE(CheckCXXSourceCompiles)
+INCLUDE(CheckCSourceCompiles)
 
 # Sometimes linking against libatomic is required for atomic ops, if
 # the platform doesn't support lock-free atomics.
@@ -9,17 +9,16 @@
 
 function(check_cxx_atomics varname)
   set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-  set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include")
+  set(CMAKE_REQUIRED_FLAGS "-std=c11")
   if (${LIBCXX_GCC_TOOLCHAIN})
     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
   endif()
-  check_cxx_source_compiles("
-#include <cstdint>
-#include <atomic>
-std::atomic<uintptr_t> x;
-std::atomic<uintmax_t> y;
+  check_c_source_compiles("
+#include <stdatomic.h>
+atomic_uintptr_t x;
+atomic_uintmax_t y;
 int main() {
-  return x + y;
+  return atomic_load(&x) + atomic_load(&y);
 }
 " ${varname})
   set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to