From: Andreas Beckmann Date: Mon, 27 Jun 2022 12:04:28 +0000 (+0200) Subject: [PATCH 3/3] check whether 64bit atomics require -latomic X-Git-Tag: archive/raspbian/3.0-6+rpi1~1^2~9 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f2612aac2dad47f2ecd1b72a84016bfc5cc19a40;p=pocl.git [PATCH 3/3] check whether 64bit atomics require -latomic Gbp-Pq: Name 1020-check-whether-64bit-atomics-require-latomic.patch --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 719b560..727b358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -646,6 +646,37 @@ endif() ###################################################################################### +function(check_64bit_atomics varname) + check_c_source_compiles(" +#include +uint64_t x = 0; +int main() +{ + __atomic_add_fetch(&x, 1, __ATOMIC_SEQ_CST); + __atomic_sub_fetch(&x, 1, __ATOMIC_SEQ_CST); + return x; +} +" ${varname}) +endfunction(check_64bit_atomics) + +# platforms w/o lockfree 64bit atomics need to link with -latomic +if(UNIX) + check_64bit_atomics(HAVE_64BIT_ATOMICS_WITHOUT_LIB) + if(HAVE_64BIT_ATOMICS_WITHOUT_LIB) + set(HAVE_64BIT_ATOMICS_WITH_LIB FALSE) + else() + set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_64bit_atomics(HAVE_64BIT_ATOMICS_WITH_LIB) + set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) + if(NOT HAVE_64BIT_ATOMICS_WITH_LIB) + message(SEND_ERROR "Missing 64-bit atomic increment") + endif() + endif() +endif() + +###################################################################################### + if(UNIX AND ENABLE_LLVM AND HAVE_DLADDR) option(ENABLE_RELOCATION "make libpocl relocatable" ON) else() diff --git a/lib/CL/CMakeLists.txt b/lib/CL/CMakeLists.txt index 342cdac..ed57340 100644 --- a/lib/CL/CMakeLists.txt +++ b/lib/CL/CMakeLists.txt @@ -242,6 +242,10 @@ if(HAVE_CLOCK_GETTIME AND CMAKE_SYSTEM_NAME MATCHES "Linux") list(APPEND POCL_PRIVATE_LINK_LIST "rt") endif() +if(HAVE_64BIT_ATOMICS_WITH_LIB) + list(APPEND POCL_PRIVATE_LINK_LIST "atomic") +endif() + list(APPEND POCL_PRIVATE_LINK_LIST ${LIBMATH} ${CMAKE_DL_LIBS} ${PTHREAD_LIBRARY}) # see lib/CMakeLists.txt