diff options
author | Chris Robinson <[email protected]> | 2016-09-12 12:42:11 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-09-12 12:42:11 -0700 |
commit | a004ccfa1ad482d001c2c891b14e22ab7300ad04 (patch) | |
tree | 2c681206e0737bc1fb0e58276e81d10ef238fede /CMakeLists.txt | |
parent | 53d8a496736c61b9cde5d982737bed98b2f72004 (diff) |
Check for libatomic, in case C11 atomics need it
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d3bb5cd..825e36b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,13 @@ 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) + SET(EXTRA_LIBS atomic ${EXTRA_LIBS}) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) +ENDIF() + # Check if we have C99 variable length arrays CHECK_C_SOURCE_COMPILES( "int main(int argc, char *argv[]) @@ -213,8 +220,10 @@ HAVE_C11_ALIGNAS) CHECK_C_SOURCE_COMPILES( "#include <stdatomic.h> const int _Atomic foo = ATOMIC_VAR_INIT(~0); + int _Atomic bar = ATOMIC_VAR_INIT(0); int main() { + atomic_fetch_add(&bar, 2); return atomic_load(&foo); }" HAVE_C11_ATOMIC) |