Skip to content

Commit

Permalink
Add Module For Checking Atomic
Browse files Browse the repository at this point in the history
Adds function for detection if linking against libatomic is
required.
  • Loading branch information
jungleraptor committed Jun 24, 2022
1 parent 63396d6 commit c690e32
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions CheckAtomic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include(CheckCXXSourceCompiles)

# Some toolchains require explicitly linking against libatomic
#
# If such linking is required, then this function sets the
# value of result to "atomic". Otherwise it remains untouched.
# This makes it so that the function only needs to be called once
# per project.
#
# It can be used as follows:
#
# check_cxx_needs_atomic(LINK_ATOMIC)
# target_link_libraries(foo PRIVATE ${LINK_ATOMIC})
# ...
# target_link_libraries(bar PRIVATE ${LINK_ATOMIC})
#
function(check_cxx_needs_atomic result)
check_cxx_source_compiles("
#include <atomic>
#include <cstdint>
int main() {
return std::atomic<uint64_t>(0).load();
}
" success)

if(NOT success)
set(${result} atomic PARENT_SCOPE)
endif()
endfunction()

0 comments on commit c690e32

Please sign in to comment.