diff options
-rw-r--r-- | cmake/modules/FindAtomic.cmake | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/cmake/modules/FindAtomic.cmake b/cmake/modules/FindAtomic.cmake index 8ea3c815d7..91e0b39c13 100644 --- a/cmake/modules/FindAtomic.cmake +++ b/cmake/modules/FindAtomic.cmake @@ -3,54 +3,45 @@ # ----- # Finds the ATOMIC library # -# This will define the following variables:: +# This will define the following target: # -# ATOMIC_FOUND - system has ATOMIC -# ATOMIC_LIBRARIES - the ATOMIC libraries -# -# and the following imported targets:: -# -# ATOMIC::ATOMIC - The ATOMIC library - +# ${APP_NAME_LC}::ATOMIC - The ATOMIC library -include(CheckCXXSourceCompiles) +if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME}) + include(CheckCXXSourceCompiles) + include(FindPackageMessage) -set(atomic_code - " - #include <atomic> - #include <cstdint> - std::atomic<uint8_t> n8 (0); // riscv64 - std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc - int main() { - ++n8; - ++n64; - return 0; - }") + set(atomic_code + " + #include <atomic> + #include <cstdint> + std::atomic<uint8_t> n8 (0); // riscv64 + std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc + int main() { + ++n8; + ++n64; + return 0; + }") -check_cxx_source_compiles("${atomic_code}" ATOMIC_LOCK_FREE_INSTRUCTIONS) + check_cxx_source_compiles("${atomic_code}" ATOMIC_LOCK_FREE_INSTRUCTIONS) -if(ATOMIC_LOCK_FREE_INSTRUCTIONS) - set(ATOMIC_FOUND TRUE) - set(ATOMIC_LIBRARIES) -else() - set(CMAKE_REQUIRED_LIBRARIES "-latomic") - check_cxx_source_compiles("${atomic_code}" ATOMIC_IN_LIBRARY) - set(CMAKE_REQUIRED_LIBRARIES) - if(ATOMIC_IN_LIBRARY) - set(ATOMIC_LIBRARY atomic) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Atomic DEFAULT_MSG ATOMIC_LIBRARY) - set(ATOMIC_LIBRARIES ${ATOMIC_LIBRARY}) - if(NOT TARGET ATOMIC::ATOMIC) - add_library(ATOMIC::ATOMIC UNKNOWN IMPORTED) - set_target_properties(ATOMIC::ATOMIC PROPERTIES - IMPORTED_LOCATION "${ATOMIC_LIBRARY}") - endif() - unset(ATOMIC_LIBRARY) + if(ATOMIC_LOCK_FREE_INSTRUCTIONS) + find_package_message(Atomic "Found Atomic: Lock Free" "") else() - if(Atomic_FIND_REQUIRED) - message(FATAL_ERROR "Neither lock free instructions nor -latomic found.") + set(CMAKE_REQUIRED_LIBRARIES "-latomic") + check_cxx_source_compiles("${atomic_code}" ATOMIC_IN_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES) + if(ATOMIC_IN_LIBRARY) + find_package_message(Atomic "Found Atomic library: -latomic" "") + + add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED) + set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES + IMPORTED_LOCATION "-latomic") + else() + if(Atomic_FIND_REQUIRED) + message(FATAL_ERROR "Neither lock free instructions nor -latomic found.") + endif() endif() endif() + unset(atomic_code) endif() -unset(atomic_code) |