2022-07-05 11:26:52 +00:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 13:21:34 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2022-07-05 11:26:52 +00:00
|
|
|
|
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>
|
|
|
|
|
|
|
|
int main(int, char **)
|
|
|
|
{
|
2022-04-12 09:40:00 +00:00
|
|
|
volatile std::atomic<char> size_1;
|
|
|
|
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);
|
|
|
|
|
2018-10-24 13:20:27 +00:00
|
|
|
return 0;
|
|
|
|
}")
|
|
|
|
|
|
|
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC)
|
|
|
|
if(NOT HAVE_STDATOMIC)
|
2021-05-08 23:47:32 +00:00
|
|
|
set(_req_libraries "${CMAKE_REQUIRED_LIBRARIES}")
|
2022-05-07 17:51:25 +00:00
|
|
|
set(atomic_LIB "-latomic")
|
2022-04-12 09:40:00 +00:00
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${atomic_LIB})
|
2018-10-24 13:20:27 +00:00
|
|
|
check_cxx_source_compiles("${atomic_test_sources}" HAVE_STDATOMIC_WITH_LIB)
|
2021-05-08 23:47:32 +00:00
|
|
|
set(CMAKE_REQUIRED_LIBRARIES "${_req_libraries}")
|
2018-10-24 13:20:27 +00:00
|
|
|
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)
|
2022-04-12 09:40:00 +00:00
|
|
|
# atomic_LIB is already found above.
|
|
|
|
target_link_libraries(WrapAtomic::WrapAtomic INTERFACE ${atomic_LIB})
|
2018-10-24 13:20:27 +00:00
|
|
|
endif()
|
|
|
|
|
2020-04-28 15:33:29 +00:00
|
|
|
set(WrapAtomic_FOUND 1)
|
2020-06-26 16:32:53 +00:00
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(WrapAtomic DEFAULT_MSG WrapAtomic_FOUND)
|