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)
18 std::atomic<uint8_t> n8 (0); // riscv64
19 std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
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" "")
31 set(CMAKE_REQUIRED_LIBRARIES "-latomic")
32 check_cxx_source_compiles("${atomic_code}" ATOMIC_IN_LIBRARY)
33 set(CMAKE_REQUIRED_LIBRARIES)
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")
41 if(Atomic_FIND_REQUIRED)
42 message(FATAL_ERROR "Neither lock free instructions nor -latomic found.")