diff options
author | Chris Robinson <[email protected]> | 2016-09-13 12:11:52 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-09-13 12:11:52 -0700 |
commit | af5fb3d6e73ac5e7f015011974c7a7443ae6744b (patch) | |
tree | cf4246c4690425bc1f47c171966ed97dd00562bf /CMakeLists.txt | |
parent | a56bbbcf361ecf92487e62b08de131369194eff2 (diff) |
Fix the libatomic check
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 18 |
1 files 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 <stdatomic.h> +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( |