File: 0001-Check-if-libatomic-is-needed.patch

package info (click to toggle)
scitokens-cpp 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,208 kB
  • sloc: cpp: 12,219; ansic: 596; sh: 161; python: 132; makefile: 22
file content (87 lines) | stat: -rw-r--r-- 3,188 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From 5fcfbfe9970a76676f8ded3a79df60e38299c41a Mon Sep 17 00:00:00 2001
From: Mattias Ellert <mattias.ellert@physics.uu.se>
Date: Sun, 1 Feb 2026 10:11:25 +0100
Subject: [PATCH] Check if libatomic is needed

/usr/bin/powerpc-linux-gnu-ld.bfd: CMakeFiles/scitokens-integration-test.dir/integration_test.cpp.o: undefined reference to symbol '__atomic_load_8@@LIBATOMIC_1.0'
/usr/bin/powerpc-linux-gnu-ld.bfd: /usr/lib/powerpc-linux-gnu/libatomic.so.1: error adding symbols: DSO missing from command line

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
 CMakeLists.txt         |  3 ++-
 cmake/FindAtomic.cmake | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 cmake/FindAtomic.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec6d2b2..66118cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,6 +24,7 @@ endif()
 include(GNUInstallDirs)
 
 find_package( jwt-cpp REQUIRED )
+find_package( Atomic REQUIRED )
 find_package( CURL REQUIRED )
 find_package( UUID REQUIRED )
 
@@ -51,7 +52,7 @@ target_include_directories(SciTokens PUBLIC ${JWT_CPP_INCLUDES} "${PROJECT_SOURC
 # Find threading library
 find_package(Threads REQUIRED)
 
-target_link_libraries(SciTokens PUBLIC ${OPENSSL_LIBRARIES} ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES} Threads::Threads)
+target_link_libraries(SciTokens PUBLIC ${OPENSSL_LIBRARIES} ${LIBCRYPTO_LIBRARIES} ${CURL_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES} Threads::Threads std::atomic)
 if (UNIX)
 # pkg_check_modules fails to return an absolute path on RHEL7.  Set the
 # link directories accordingly.
diff --git a/cmake/FindAtomic.cmake b/cmake/FindAtomic.cmake
new file mode 100644
index 0000000..acc5f70
--- /dev/null
+++ b/cmake/FindAtomic.cmake
@@ -0,0 +1,42 @@
+include(CheckCXXSourceCompiles)
+
+function( check_working_cxx_atomics varname )
+  CHECK_CXX_SOURCE_COMPILES("
+    #include <cstdlib>
+    #include <atomic>
+    #include <cstdint>
+
+    int main() {
+      std::atomic<uint8_t> a1;
+      std::atomic<uint16_t> a2;
+      std::atomic<uint32_t> a3;
+      std::atomic<uint64_t> a4;
+      return a1++ + a2++ + a3++ + a4++;
+    }" ${varname}
+  )
+endfunction( check_working_cxx_atomics varname )
+
+set( _found FALSE )
+check_working_cxx_atomics( CXX_ATOMIC_NO_LINK_NEEDED )
+if( CXX_ATOMIC_NO_LINK_NEEDED )
+  set( _found TRUE )
+else()
+  set( OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} )
+  list( APPEND CMAKE_REQUIRED_LIBRARIES "atomic" )
+  check_working_cxx_atomics( HAVE_CXX_ATOMICS_WITH_LIB )
+  set( CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES} )
+  if( HAVE_CXX_ATOMICS_WITH_LIB )
+    set( _found TRUE )
+  endif()
+endif()
+
+add_library( std::atomic INTERFACE IMPORTED GLOBAL )
+
+if( HAVE_CXX_ATOMICS_WITH_LIB )
+  set_property( TARGET std::atomic APPEND PROPERTY INTERFACE_LINK_LIBRARIES atomic )
+endif()
+
+set( Atomic_FOUND ${_found} CACHE BOOL "TRUE if we can run a program using std::atomic" FORCE )
+if( Atomic_FIND_REQUIRED AND NOT Atomic_FOUND )
+    message( FATAL_ERROR "Cannot run simple program using std::atomic" )
+endif()
-- 
2.53.0