From f5e1bcdd6f0ede31c0f35fb707a39af27fb9ac9b Mon Sep 17 00:00:00 2001 From: Thomas Krennwallner Date: Wed, 11 Mar 2020 06:50:20 -0400 Subject: [PATCH] link with libatomic on architectures that require it Last-Update: 2020-03-11 Forwarded: no clingo requires c++11 threads with 64bit __atomic_exchange, we need to link with libatomic on armel, powerpc, powerpcspe, m68k, mips, mipsel, and sh4, see also https://gcc.gnu.org/wiki/Atomic and https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary This patch was shamelessly adapted from https://github.com/potassco/clasp/blob/master/CMakeLists.txt https://github.com/potassco/clasp/commit/fe3e176e2813956000bb947479de2c3d80fe34be Gbp-Pq: Name link-libatomic-check.patch --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 068a309..2d58f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,35 @@ include(CMakeDependentOption) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(clingo_functions) +# Add libatomic if necessary +include (CheckCXXSourceCompiles) +set (OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) +set (OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) +find_package(Threads REQUIRED) +list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++11") +list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads) +check_cxx_source_compiles(" +#include +#include +std::atomic x (0); +int main() { + uint64_t i = x.load(std::memory_order_relaxed); + return 0; +} +" CLINGO_HAS_WORKING_LIBATOMIC) +set (CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +set (CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES}) +if (NOT CLINGO_HAS_WORKING_LIBATOMIC) + # clingo requires c++11 threads with 64bit __atomic_exchange, we + # need to link with libatomic on armel, powerpc, powerpcspe, m68k, + # mips, mipsel, and sh4, see also https://gcc.gnu.org/wiki/Atomic + # https://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary + check_library_exists(atomic __atomic_fetch_add_4 "" CLINGO_HAS_LIBATOMIC) + if (CLINGO_HAS_LIBATOMIC) + set_property(TARGET Threads::Threads APPEND PROPERTY INTERFACE_LINK_LIBRARIES "atomic") + endif() +endif() + # Enable folders in IDEs like Visual Studio set_property(GLOBAL PROPERTY USE_FOLDERS ON) -- 2.30.2