Explicitly check for atomic addition and relaxed load operation support
...and properly find and link against `libatomic` using find_library. This fixes the qtdeclarative build on the RISC-V platform. Initial-patch-by: Sprite <SpriteOvO@gmail.com> Pick-to: 6.2 Pick-to: 6.3 Task-number: QTBUG-99234 Change-Id: I2b5e4812886ce45cb02bed3106ce8c519b294cbe Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
parent
a0858c639e
commit
4088b27b93
@ -10,35 +10,39 @@ include(CheckCXXSourceCompiles)
|
|||||||
set (atomic_test_sources "#include <atomic>
|
set (atomic_test_sources "#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
void test(volatile std::atomic<std::int64_t> &a)
|
|
||||||
{
|
|
||||||
std::int64_t v = a.load(std::memory_order_acquire);
|
|
||||||
while (!a.compare_exchange_strong(v, v + 1,
|
|
||||||
std::memory_order_acq_rel,
|
|
||||||
std::memory_order_acquire)) {
|
|
||||||
v = a.exchange(v - 1);
|
|
||||||
}
|
|
||||||
a.store(v + 1, std::memory_order_release);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int, char **)
|
int main(int, char **)
|
||||||
{
|
{
|
||||||
void *ptr = (void*)0xffffffc0; // any random pointer
|
volatile std::atomic<char> size_1;
|
||||||
test(*reinterpret_cast<std::atomic<std::int64_t> *>(ptr));
|
volatile std::atomic<short> size_2;
|
||||||
|
volatile std::atomic<int> size_4;
|
||||||
|
volatile std::atomic<int64_t> size_8;
|
||||||
|
|
||||||
|
++size_1;
|
||||||
|
++size_2;
|
||||||
|
++size_4;
|
||||||
|
++size_8;
|
||||||
|
|
||||||
|
(void)size_1.load(std::memory_order_relaxed);
|
||||||
|
(void)size_2.load(std::memory_order_relaxed);
|
||||||
|
(void)size_4.load(std::memory_order_relaxed);
|
||||||
|
(void)size_8.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}")
|
}")
|
||||||
|
|
||||||
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC)
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC)
|
||||||
if(NOT HAVE_STDATOMIC)
|
if(NOT HAVE_STDATOMIC)
|
||||||
set(_req_libraries "${CMAKE_REQUIRED_LIBRARIES}")
|
set(_req_libraries "${CMAKE_REQUIRED_LIBRARIES}")
|
||||||
set(CMAKE_REQUIRED_LIBRARIES "atomic")
|
find_library(atomic_LIB atomic REQUIRED)
|
||||||
|
set(CMAKE_REQUIRED_LIBRARIES ${atomic_LIB})
|
||||||
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB)
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB)
|
||||||
set(CMAKE_REQUIRED_LIBRARIES "${_req_libraries}")
|
set(CMAKE_REQUIRED_LIBRARIES "${_req_libraries}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(WrapAtomic::WrapAtomic INTERFACE IMPORTED)
|
add_library(WrapAtomic::WrapAtomic INTERFACE IMPORTED)
|
||||||
if(HAVE_STDATOMIC_WITH_LIB)
|
if(HAVE_STDATOMIC_WITH_LIB)
|
||||||
target_link_libraries(WrapAtomic::WrapAtomic INTERFACE atomic)
|
# atomic_LIB is already found above.
|
||||||
|
target_link_libraries(WrapAtomic::WrapAtomic INTERFACE ${atomic_LIB})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(WrapAtomic_FOUND 1)
|
set(WrapAtomic_FOUND 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user