Merge pull request #25883 from CrystalP/fix-slowscan
[xbmc.git] / cmake / modules / FindAtomic.cmake
blob91e0b39c13a8f252f5abd3e31a503ab50bbb311c
1 #.rst:
2 # FindAtomic
3 # -----
4 # Finds the ATOMIC library
6 # This will define the following target:
8 #   ${APP_NAME_LC}::ATOMIC    - The ATOMIC library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
11   include(CheckCXXSourceCompiles)
12   include(FindPackageMessage)
14   set(atomic_code
15       "
16        #include <atomic>
17        #include <cstdint>
18        std::atomic<uint8_t> n8 (0); // riscv64
19        std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
20        int main() {
21          ++n8;
22          ++n64;
23          return 0;
24        }")
26   check_cxx_source_compiles("${atomic_code}" ATOMIC_LOCK_FREE_INSTRUCTIONS)
28   if(ATOMIC_LOCK_FREE_INSTRUCTIONS)
29     find_package_message(Atomic "Found Atomic: Lock Free" "")
30   else()
31     set(CMAKE_REQUIRED_LIBRARIES "-latomic")
32     check_cxx_source_compiles("${atomic_code}" ATOMIC_IN_LIBRARY)
33     set(CMAKE_REQUIRED_LIBRARIES)
34     if(ATOMIC_IN_LIBRARY)
35       find_package_message(Atomic "Found Atomic library: -latomic" "")
37       add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
38       set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
39                                                                        IMPORTED_LOCATION "-latomic")
40     else()
41       if(Atomic_FIND_REQUIRED)
42         message(FATAL_ERROR "Neither lock free instructions nor -latomic found.")
43       endif()
44     endif()
45   endif()
46   unset(atomic_code)
47 endif()