From faea2c59a95ff609d23a4e4f859edef83d02f417 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Fri, 9 Dec 2022 12:36:11 +0100 Subject: [PATCH] Add cmake check for libatomic requirement when building with gcc (#980) Signed-off-by: John Paul Adrian Glaubitz --- cmake/compilers/GNU.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) Index: oneTBB-2021.11.0/cmake/compilers/GNU.cmake =================================================================== --- oneTBB-2021.11.0.orig/cmake/compilers/GNU.cmake +++ oneTBB-2021.11.0/cmake/compilers/GNU.cmake @@ -42,6 +42,22 @@ endif() set(TBB_COMMON_LINK_LIBS ${CMAKE_DL_LIBS}) +# Check whether code with full atomics can be built without libatomic +# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 +include(CheckCXXSourceCompiles) +check_cxx_source_compiles("#include +int main() { + std::atomic w1; + std::atomic w2; + std::atomic w4; + std::atomic w8; + return ++w1 + ++w2 + ++w4 + ++w8; +}" TBB_BUILDS_WITHOUT_LIBATOMIC) + +if(NOT TBB_BUILDS_WITHOUT_LIBATOMIC) + set(TBB_COMMON_LINK_LIBS ${TBB_COMMON_LINK_LIBS} atomic) +endif() + # Ignore -Werror set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled. if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag) tbb_remove_compile_flag(-Werror)