Skip to content

Commit c690e32

Browse files
committed
Add Module For Checking Atomic
Adds function for detection if linking against libatomic is required.
1 parent 63396d6 commit c690e32

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

CheckAtomic.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
include(CheckCXXSourceCompiles)
2+
3+
# Some toolchains require explicitly linking against libatomic
4+
#
5+
# If such linking is required, then this function sets the
6+
# value of result to "atomic". Otherwise it remains untouched.
7+
# This makes it so that the function only needs to be called once
8+
# per project.
9+
#
10+
# It can be used as follows:
11+
#
12+
# check_cxx_needs_atomic(LINK_ATOMIC)
13+
# target_link_libraries(foo PRIVATE ${LINK_ATOMIC})
14+
# ...
15+
# target_link_libraries(bar PRIVATE ${LINK_ATOMIC})
16+
#
17+
function(check_cxx_needs_atomic result)
18+
check_cxx_source_compiles("
19+
#include <atomic>
20+
#include <cstdint>
21+
int main() {
22+
return std::atomic<uint64_t>(0).load();
23+
}
24+
" success)
25+
26+
if(NOT success)
27+
set(${result} atomic PARENT_SCOPE)
28+
endif()
29+
endfunction()

0 commit comments

Comments
 (0)