From af5fb3d6e73ac5e7f015011974c7a7443ae6744b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 13 Sep 2016 12:11:52 -0700 Subject: Fix the libatomic check --- CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 825e36b6..4195be43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,12 +171,22 @@ IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}") ENDIF() -# Some systems may need libatomic for (C11) atomic functions to work -CHECK_LIBRARY_EXISTS(atomic atomic_fetch_add "" HAVE_LIBATOMIC) -IF(HAVE_LIBATOMIC) +# Some systems may need libatomic for C11 atomic functions to work +SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic) +CHECK_C_SOURCE_COMPILES("#include +int _Atomic foo = ATOMIC_VAR_INIT(0); +int main() +{ + return atomic_fetch_add(&foo, 2); +}" +HAVE_LIBATOMIC) +IF(NOT HAVE_LIBATOMIC) + SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}") +ELSE() SET(EXTRA_LIBS atomic ${EXTRA_LIBS}) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) ENDIF() +UNSET(OLD_REQUIRED_LIBRARIES) # Check if we have C99 variable length arrays CHECK_C_SOURCE_COMPILES( -- cgit v1.2.3