Skip to content

Commit

Permalink
Add support for older compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
roehling committed Dec 10, 2020
1 parent 73207f2 commit 08b9947
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmake/atomic.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# check for atomic library, which is needed on some architectures
include(CheckCXXSourceCompiles)
function(check_working_cxx_atomic varname)
function(check_cxx_atomic_compiles varname)
check_cxx_source_compiles("
#include <atomic>
std::atomic<bool> x;
Expand All @@ -9,6 +9,29 @@ function(check_working_cxx_atomic varname)
return !x.compare_exchange_strong(y, true);
}" ${varname})
endfunction()
function(check_working_cxx_atomic varname)
check_cxx_atomic_compiles(${varname}_NOFLAG)
if(${varname}_NOFLAG)
set(${varname} TRUE PARENT_SCOPE)
return()
endif()
set(old_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_atomic_compiles(${varname}_STD11)
set(CMAKE_REQUIRED_FLAGS "${old_CMAKE_REQUIRED_FLAGS}")
if(${varname}_STD11)
set(${varname} TRUE PARENT_SCOPE)
return()
endif()
list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++0x")
check_cxx_atomic_compiles(${varname}_STD0X)
set(CMAKE_REQUIRED_FLAGS "${old_CMAKE_REQUIRED_FLAGS}")
if(${varname}_STD0X)
set(${varname} TRUE PARENT_SCOPE)
return()
endif()
set(${varname} FALSE PARENT_SCOPE)
endfunction()
check_working_cxx_atomic(HAVE_CXX_ATOMIC)
if(NOT HAVE_CXX_ATOMIC)
set(old_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
Expand Down

0 comments on commit 08b9947

Please sign in to comment.