[neon/extras/qcoro/Neon/release] debian: link to atomic if needed (#1008615)

Pino Toscano null at kde.org
Wed May 4 12:31:29 BST 2022


Git commit ec6809fb9f2e58dcc4799d04aae989bd4dffb72a by Pino Toscano.
Committed on 16/04/2022 at 10:39.
Pushed by jriddell into branch 'Neon/release'.

link to atomic if needed (#1008615)

backport upstream commit 312f2fca861b4c623481da58241a1139e013ef83

M  +3    -0    debian/changelog
A  +1    -0    debian/patches/series
A  +93   -0    debian/patches/upstream_Build-Check-if-libatomic-is-required.patch

https://invent.kde.org/neon/extras/qcoro/commit/ec6809fb9f2e58dcc4799d04aae989bd4dffb72a

diff --git a/debian/changelog b/debian/changelog
index 3de41fe..6aa71cc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,9 @@ qcoro (0.4.0-5) UNRELEASED; urgency=medium
     and qcoro-qt6-dev.
   * Use execute_after_dh_auto_clean & xecute_after_dh_install-indep instead of
     manually calling dh_auto_clean & dh_install.
+  * Backport upstream commit 312f2fca861b4c623481da58241a1139e013ef83 to link
+    to the atomic library if needed on the architecture; patch
+    upstream_Build-Check-if-libatomic-is-required.patch. (Closes: #1008615)
 
  -- Debian KDE Extras Team <pkg-kde-extras at lists.alioth.debian.org>  Sat, 16 Apr 2022 12:18:23 +0200
 
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..0eb985e
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+upstream_Build-Check-if-libatomic-is-required.patch
diff --git a/debian/patches/upstream_Build-Check-if-libatomic-is-required.patch b/debian/patches/upstream_Build-Check-if-libatomic-is-required.patch
new file mode 100644
index 0000000..176f042
--- /dev/null
+++ b/debian/patches/upstream_Build-Check-if-libatomic-is-required.patch
@@ -0,0 +1,93 @@
+From 312f2fca861b4c623481da58241a1139e013ef83 Mon Sep 17 00:00:00 2001
+From: rvalue <i at rvalue.moe>
+Date: Mon, 28 Mar 2022 21:20:32 +0200
+Subject: [PATCH] Build: Check if libatomic is required
+
+Check libatomic and link QCoro against it if necessary.
+---
+ CMakeLists.txt              |  2 ++
+ cmake/AddQCoroLibrary.cmake |  4 ++++
+ cmake/CheckAtomic.cmake     | 40 +++++++++++++++++++++++++++++++++++++
+ tests/CMakeLists.txt        |  3 +++
+ 4 files changed, 49 insertions(+)
+ create mode 100644 cmake/CheckAtomic.cmake
+
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -64,6 +64,8 @@ qcoro_enable_coroutines()
+ 
+ find_package(Threads REQUIRED)
+ 
++include(cmake/CheckAtomic.cmake)
++
+ set(REQUIRED_QT_COMPONENTS Core)
+ if (QCORO_WITH_QTDBUS)
+     list(APPEND REQUIRED_QT_COMPONENTS DBus)
+--- a/cmake/AddQCoroLibrary.cmake
++++ b/cmake/AddQCoroLibrary.cmake
+@@ -73,6 +73,10 @@ function(add_qcoro_library)
+     target_link_libraries(${target_name} ${qcoro_LIBS})
+     target_link_libraries(${target_name} ${qt_LIBS})
+ 
++    if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB AND NOT LIB_INTERFACE)
++        target_link_libraries(${target_name} PUBLIC atomic)
++    endif()
++
+     set_target_properties(
+         ${target_name}
+         PROPERTIES
+--- /dev/null
++++ b/cmake/CheckAtomic.cmake
+@@ -0,0 +1,40 @@
++# std::atomic may need libatomic to function correctly.
++
++INCLUDE(CheckCXXSourceCompiles)
++INCLUDE(CheckLibraryExists)
++
++# Sometimes linking against libatomic is required for atomic ops, if
++# the platform doesn't support lock-free atomics.
++
++function(check_working_cxx_atomics varname)
++  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
++  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
++  CHECK_CXX_SOURCE_COMPILES("
++#include <atomic>
++std::atomic<int> x;
++std::atomic<short> y;
++std::atomic<char> z;
++int main() {
++  ++z;
++  ++y;
++  return ++x;
++}
++" ${varname})
++  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
++endfunction(check_working_cxx_atomics)
++
++# Check for (non-64-bit) atomic operations.
++if(MSVC)
++  set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
++else()
++  # First check if atomics work without the library.
++  check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
++  # If not, check if the library exists, and atomics work with it.
++  if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
++    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
++    check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
++    if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
++      message(FATAL_ERROR "Host compiler must support std::atomic!")
++    endif()
++  endif()
++endif()
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -61,6 +61,9 @@ function(qcoro_add_network_test _name)
+         Threads::Threads
+         ${TEST_LINK_LIBRARIES}
+     )
++    if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
++        target_link_libraries(test-${_name} atomic)
++    endif()
+     add_test(NAME test-${_name} COMMAND test-${_name})
+ endfunction()
+ 



More information about the Neon-commits mailing list