Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,35 @@ int main() {
}
" BUILTIN_ATOMIC)
if (NOT BUILTIN_ATOMIC)
#TODO: Check if -latomic exists
list(APPEND THIRDPARTY_LIBS atomic)
# Only consider -latomic when not on Apple (macOS has no separate libatomic)
if (APPLE)
message(STATUS "Builtin atomics probe failed, but skipping -latomic on Apple")
else()
# Prefer a positive link test with -latomic; if that succeeds, then add it.
set(_OLD_REQ_LIBS ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
unset(HAVE_WORKING_LIBATOMIC CACHE)
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<unsigned __int128> x{};
int main() { auto v = x.load(std::memory_order_relaxed); (void)v; return 0; }
" HAVE_WORKING_LIBATOMIC)
set(CMAKE_REQUIRED_LIBRARIES ${_OLD_REQ_LIBS})

if (HAVE_WORKING_LIBATOMIC)
list(APPEND THIRDPARTY_LIBS atomic)
message(STATUS "Using -latomic (probe succeeded)")
else()
# Fallback: try to locate the library and add it only if it actually exists
find_library(ATOMIC_LIBRARY atomic)
if (ATOMIC_LIBRARY)
list(APPEND THIRDPARTY_LIBS atomic)
message(STATUS "Using -latomic (found in system)")
else()
message(STATUS "libatomic not found or not required; continuing without it")
endif()
endif()
endif()
endif()
endif()

Expand Down