-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds function for detection if linking against libatomic is required.
- Loading branch information
1 parent
63396d6
commit c690e32
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |