build: fix linking failure on RPi 32bit

this fixes a linking problem with RPi 3 (and probably others) running
with Raspbian (new Raspberry Pi OS) that can't use the inline
atomic functions but instead require linking against the lib -latomic.

The CMake code is based on SoapyRTLSdr file (licensed under MIT)
https://github.com/pothosware/SoapyRTLSDR/blob/master/CheckAtomic.cmake
master
Andre Puschmann 4 years ago
parent b54bb35343
commit 833ddc3229

@ -118,6 +118,12 @@ if (STOP_ON_WARNING)
add_definitions(-DSTOP_ON_WARNING) add_definitions(-DSTOP_ON_WARNING)
endif() endif()
# Test for Atomics
include(CheckAtomic)
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
set(ATOMIC_LIBS "atomic")
endif()
######################################################################## ########################################################################
# Find dependencies # Find dependencies
######################################################################## ########################################################################

@ -51,6 +51,10 @@ Files: lib/include/srsran/common/backward.hpp
Copyright: 2013, Google Inc. Copyright: 2013, Google Inc.
License: MIT License: MIT
Files: cmake/modules/CheckAtomic.cmake
Copyright: 2015, Charles J. Cliffe
License: MIT
License: AGPL-3+ License: AGPL-3+
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as

@ -0,0 +1,92 @@
#
# Copyright 2013-2021 Software Radio Systems Limited
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the distribution.
#
# Adopted from https://github.com/pothosware/SoapyRTLSDR
# Copyright: 2015, Charles J. Cliffe
# License: MIT
# - Try to find if atomics need -latomic linking
# Once done this will define
# HAVE_CXX_ATOMICS_WITHOUT_LIB - Wether atomic types work without -latomic
# HAVE_CXX_ATOMICS64_WITHOUT_LIB - Wether 64 bit atomic types work without -latomic
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckLibraryExists)
# Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics.
function(check_working_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
std::atomic<int> x;
int main() {
return std::atomic_is_lock_free(&x);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics)
function(check_working_cxx_atomics64 varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return std::atomic_is_lock_free(&x);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics64)
# Check for atomic operations.
if(MSVC)
# This isn't necessary on MSVC.
set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
else()
# First check if atomics work without the library.
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
endif()
# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
if(NOT HAVE_LIBATOMIC)
message(STATUS "Host compiler appears to require libatomic, but cannot locate it.")
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
endif()
# Check for 64 bit atomic operations.
if(MSVC)
set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
else()
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()
# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
check_library_exists(atomic __atomic_load_8 "" HAVE_LIBATOMIC64)
if(NOT HAVE_LIBATOMIC64)
message(STATUS "Host compiler appears to require libatomic, but cannot locate it.")
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
endif()

3
debian/copyright vendored

@ -58,6 +58,9 @@ Files: lib/include/srsran/common/backward.hpp
Copyright: 2013, Google Inc. Copyright: 2013, Google Inc.
License: MIT License: MIT
Files: cmake/modules/CheckAtomic.cmake
Copyright: 2015, Charles J. Cliffe
License: MIT
License: AGPL-3+ License: AGPL-3+
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

@ -8,4 +8,4 @@
set(SOURCES demux.cc dl_harq.cc mac.cc mux.cc proc_bsr.cc proc_phr.cc proc_ra.cc proc_sr.cc ul_harq.cc) set(SOURCES demux.cc dl_harq.cc mac.cc mux.cc proc_bsr.cc proc_phr.cc proc_ra.cc proc_sr.cc ul_harq.cc)
add_library(srsue_mac STATIC ${SOURCES}) add_library(srsue_mac STATIC ${SOURCES})
target_link_libraries(srsue_mac srsue_mac_common) target_link_libraries(srsue_mac srsue_mac_common ${ATOMIC_LIBS})
Loading…
Cancel
Save