Skip to content

Commit 2f359cd

Browse files
barracuda156ConorWilliams
authored andcommitted
Test for hardware support for atomics, link to libatomic if not detected
1 parent c67ada2 commit 2f359cd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ message(STATUS "CMAKE_BUILD_TYPE is set to '${CMAKE_BUILD_TYPE}'")
2525

2626
find_package(Threads REQUIRED)
2727

28+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
29+
include(cmake/atomic.cmake)
30+
endif()
31+
2832
# ------ Declare library ------
2933

3034
add_library(libfork_libfork INTERFACE)
3135
add_library(libfork::libfork ALIAS libfork_libfork)
3236

33-
target_link_libraries(libfork_libfork INTERFACE Threads::Threads)
37+
target_link_libraries(libfork_libfork INTERFACE Threads::Threads ${LIBFORK_EXTRA_LIBS})
3438

3539
set_property(TARGET libfork_libfork PROPERTY EXPORT_NAME libfork)
3640

cmake/atomic.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include(CheckCXXSourceCompiles)
2+
check_cxx_source_compiles("#include <atomic>
3+
int main() {
4+
std::atomic<uint8_t> w1;
5+
std::atomic<uint64_t> w8;
6+
return ++w1 + ++w8;
7+
}" NATIVE_ATOMICS_SUPPORTED)
8+
9+
if(NOT NATIVE_ATOMICS_SUPPORTED)
10+
set(LIBFORK_EXTRA_LIBS ${LIBFORK_EXTRA_LIBS} atomic)
11+
endif()

0 commit comments

Comments
 (0)