From: Johannes Schauer Marin Rodrigues <josch@debian.org>
Date: Mon, 10 Feb 2025 09:33:56 +0100
Subject: Link with libatomic on armel

Instead of checking whether atomics are needed, always add the linker
flag. The compiler will figure out itself whether it should link with
libatomic or not using --as-needed. Adding a configure-time check
whether linking against atomic is needed are error-prone and thus we
leave it up to the compiler to decide. See this for more information:
https://lists.debian.org/msgid-search/f9e55618-ba4b-4ad0-8390-69daf6813a84@debian.org
---
 client/CMakeLists.txt    | 4 ++++
 clientapp/CMakeLists.txt | 4 ++++
 lib/CMakeLists.txt       | 4 ++++
 server/CMakeLists.txt    | 4 ++++
 4 files changed, 16 insertions(+)

diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 8750ad4..6d41508 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -472,6 +472,10 @@ endif()
 
 target_link_libraries(vcmiclientcommon PRIVATE vcmiservercommon)
 
+if (CMAKE_LIBRARY_ARCHITECTURE STREQUAL "arm-linux-gnueabi")
+	target_link_options(vcmiclientcommon PRIVATE "-Wl,--push-state,--as-needed,-latomic,--pop-state")
+endif()
+
 target_link_libraries(vcmiclientcommon PUBLIC
 		vcmi SDL2::SDL2 SDL2::Image SDL2::Mixer SDL2::TTF
 )
diff --git a/clientapp/CMakeLists.txt b/clientapp/CMakeLists.txt
index 2fbed60..97708cb 100644
--- a/clientapp/CMakeLists.txt
+++ b/clientapp/CMakeLists.txt
@@ -34,6 +34,10 @@ endif()
 
 target_link_libraries(vcmiclient PRIVATE vcmiclientcommon)
 
+if (CMAKE_LIBRARY_ARCHITECTURE STREQUAL "arm-linux-gnueabi")
+	target_link_libraries(vcmiclient PRIVATE "-Wl,--push-state,--as-needed,-latomic,--pop-state")
+endif()
+
 if(ENABLE_SINGLE_APP_BUILD AND ENABLE_LAUNCHER)
 	target_link_libraries(vcmiclient PRIVATE vcmilauncher)
 endif()
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index c829e3f..b9e152e 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -762,6 +762,10 @@ target_link_libraries(vcmi PUBLIC
 	${SYSTEM_LIBS} Boost::boost Boost::thread Boost::filesystem Boost::program_options Boost::locale Boost::date_time
 )
 
+if (CMAKE_LIBRARY_ARCHITECTURE STREQUAL "arm-linux-gnueabi")
+	target_link_options(vcmi PRIVATE "-Wl,--push-state,--as-needed,-latomic,--pop-state")
+endif()
+
 if(ENABLE_STATIC_LIBS AND ENABLE_CLIENT)
 	target_compile_definitions(vcmi PRIVATE STATIC_AI)
 	target_link_libraries(vcmi PRIVATE
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index a65c3ee..2f0cb7b 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -65,6 +65,10 @@ endif()
 
 target_link_libraries(vcmiservercommon PRIVATE ${vcmiservercommon_LIBS} minizip::minizip)
 
+if (CMAKE_LIBRARY_ARCHITECTURE STREQUAL "arm-linux-gnueabi")
+	target_link_options(vcmiservercommon PRIVATE "-Wl,--push-state,--as-needed,-latomic,--pop-state")
+endif()
+
 target_include_directories(vcmiservercommon
 	PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
 )
