aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJaroslav Škarvada <jskarvad@redhat.com>2022-02-01 00:23:07 +0100
committerAaron Rossetto <aaron.rossetto@ni.com>2022-02-01 14:37:53 -0600
commit3a249aa0b11e24d2663b720316ed6edc1e2fd8ad (patch)
tree2508187df8e70af8640f5f47815da8669d57873b /host
parentef30ed1743f470756eadab4067587caf0341be8e (diff)
downloaduhd-3a249aa0b11e24d2663b720316ed6edc1e2fd8ad.tar.gz
uhd-3a249aa0b11e24d2663b720316ed6edc1e2fd8ad.tar.bz2
uhd-3a249aa0b11e24d2663b720316ed6edc1e2fd8ad.zip
cmake: added libatomic check for boost/lockfree/queue.hpp
The boost/lockfree/queue.hpp requires linking with the libatomic on some platforms (e.g. s390x). Fixes #410 Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
Diffstat (limited to 'host')
-rw-r--r--host/cmake/Modules/UHDAtomics.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/host/cmake/Modules/UHDAtomics.cmake b/host/cmake/Modules/UHDAtomics.cmake
index 4d53a2d0b..410687387 100644
--- a/host/cmake/Modules/UHDAtomics.cmake
+++ b/host/cmake/Modules/UHDAtomics.cmake
@@ -33,6 +33,18 @@ function(CHECK_WORKING_CXX_ATOMICS64 varname)
" ${varname})
endfunction(CHECK_WORKING_CXX_ATOMICS64)
+# Note: If we reach this, we have already checked for the existence of Boost,
+# and Boost.Lockfree is a header-only library so no linker options required.
+function(CHECK_WORKING_CXX_BOOST_ATOMICS varname)
+ CHECK_CXX_SOURCE_COMPILES("
+ #include <boost/lockfree/queue.hpp>
+ boost::lockfree::queue<int> queue(1);
+ int main() {
+ return queue.is_lock_free();
+ }
+ " ${varname})
+endfunction(CHECK_WORKING_CXX_BOOST_ATOMICS)
+
macro(CHECK_ATOMICS_LIB_REQUIRED required_var)
set(${required_var} FALSE)
if(MSVC)
@@ -76,5 +88,24 @@ macro(CHECK_ATOMICS_LIB_REQUIRED required_var)
"Host compiler appears to require libatomic for 64-bit operations, but cannot find it.")
endif()
endif()
+ # Check whether boost requires atomic.
+ CHECK_WORKING_CXX_BOOST_ATOMICS(HAVE_CXX_BOOST_ATOMICS_WITHOUT_LIB)
+ # If not, check if the library exists, and atomics work with it.
+ if(NOT HAVE_CXX_BOOST_ATOMICS_WITHOUT_LIB)
+ check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
+ if(HAVE_LIBATOMIC)
+ set(${required_var} TRUE)
+ set(CMAKE_REQUIRED_LIBRARIES "atomic")
+ CHECK_WORKING_CXX_BOOST_ATOMICS(HAVE_CXX_BOOST_ATOMICS_WITH_LIB)
+ unset(CMAKE_REQUIRED_LIBRARIES)
+ if (NOT HAVE_CXX_BOOST_ATOMICS_WITH_LIB)
+ message(FATAL_ERROR "Host compiler must support std::atomic!")
+ endif()
+ else()
+ message(
+ FATAL_ERROR
+ "Boost appears to require libatomic, but cannot find it.")
+ endif()
+ endif()
endif()
endmacro(CHECK_ATOMICS_LIB_REQUIRED)