Check if libatomic is needed for 64-bit atomic operations (#1465)

This commit is contained in:
Urs Fleisch
2026-10-19 17:37:18 +02:00
committed by GitHub
parent 55ceae49ba
commit 5fb109989d
2 changed files with 29 additions and 0 deletions
+28
View File
@@ -107,3 +107,31 @@ check_cxx_source_compiles("
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(PLATFORM_WINRT 1)
endif()
# Check if 64-bit atomics require -latomic
set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES "")
check_cxx_source_compiles("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x;
int main() {
x.fetch_add(1, std::memory_order_relaxed);
return 0;
}
" HAVE_CXX_ATOMICS_WITHOUT_LIB)
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
set(CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x;
int main() {
x.fetch_add(1, std::memory_order_relaxed);
return 0;
}
" HAVE_CXX_ATOMICS_WITH_LIBATOMIC)
endif()
set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
+1
View File
@@ -542,6 +542,7 @@ target_include_directories(tag INTERFACE
target_link_libraries(tag
PRIVATE $<IF:$<TARGET_EXISTS:utf8::cpp>,utf8::cpp,$<$<TARGET_EXISTS:utf8cpp>:utf8cpp>>
$<$<TARGET_EXISTS:ZLIB::ZLIB>:ZLIB::ZLIB>
$<$<BOOL:${HAVE_CXX_ATOMICS_WITH_LIBATOMIC}>:atomic>
)
set_target_properties(tag PROPERTIES