2019-06-05 12:28:31 +00:00
|
|
|
# We can't create the same interface imported target multiple times, CMake will complain if we do
|
|
|
|
# that. This can happen if the find_package call is done in multiple different subdirectories.
|
2020-04-28 15:33:29 +00:00
|
|
|
if(TARGET WrapAtomic::WrapAtomic)
|
|
|
|
set(WrapAtomic_FOUND ON)
|
2019-06-05 12:28:31 +00:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
|
|
|
|
set (atomic_test_sources "#include <atomic>
|
|
|
|
#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 **)
|
|
|
|
{
|
|
|
|
void *ptr = (void*)0xffffffc0; // any random pointer
|
|
|
|
test(*reinterpret_cast<std::atomic<std::int64_t> *>(ptr));
|
|
|
|
return 0;
|
|
|
|
}")
|
|
|
|
|
|
|
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC)
|
|
|
|
if(NOT HAVE_STDATOMIC)
|
|
|
|
set(_req_libraries "${CMAKE_REQUIRE_LIBRARIES}")
|
|
|
|
set(CMAKE_REQUIRE_LIBRARIES "atomic")
|
|
|
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB)
|
|
|
|
set(CMAKE_REQUIRE_LIBRARIES "${_req_libraries}")
|
|
|
|
endif()
|
|
|
|
|
2020-04-28 15:33:29 +00:00
|
|
|
add_library(WrapAtomic::WrapAtomic INTERFACE IMPORTED)
|
2018-10-24 13:20:27 +00:00
|
|
|
if(HAVE_STDATOMIC_WITH_LIB)
|
2020-04-28 15:33:29 +00:00
|
|
|
target_link_libraries(WrapAtomic::WrapAtomic INTERFACE atomic)
|
2018-10-24 13:20:27 +00:00
|
|
|
endif()
|
|
|
|
|
2020-04-28 15:33:29 +00:00
|
|
|
set(WrapAtomic_FOUND 1)
|