diff options
author | Brad King <brad.king@kitware.com> | 2023-07-27 15:01:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-07-27 15:07:21 (GMT) |
commit | 78bbd585451752e7b23eafbfa1dc009fd5cda750 (patch) | |
tree | e815d3a849a5c4f6dfa3eefac0411ab11861c68a | |
parent | 2d8aeaca07ecbcff6e5ac59f462fe99d656a3fce (diff) | |
download | CMake-78bbd585451752e7b23eafbfa1dc009fd5cda750.zip CMake-78bbd585451752e7b23eafbfa1dc009fd5cda750.tar.gz CMake-78bbd585451752e7b23eafbfa1dc009fd5cda750.tar.bz2 |
Source: Link libatomic when needed on Linux 32-bit ARM
Fixes: #25114
-rw-r--r-- | Source/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_atomic.cxx | 6 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_atomic_builtin.cxx | 1 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_atomic_lib.cxx | 1 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_features.cmake | 11 | ||||
-rw-r--r-- | Utilities/cmcppdap/CMakeLists.txt | 3 |
6 files changed, 25 insertions, 7 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index b01e1e7..f022dda 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -938,13 +938,9 @@ if(WIN32 AND NOT CYGWIN) list(APPEND _tools cmcldeps) endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc") - # the atomic instructions are implemented using libatomic on some platforms, - # so linking to that may be required - check_library_exists(atomic __atomic_fetch_add_4 "" LIBATOMIC_NEEDED) - if(LIBATOMIC_NEEDED) - target_link_libraries(CMakeLib PUBLIC atomic) - endif() +# Some atomic instructions are implemented using libatomic on some platforms. +if(CMake_HAVE_CXX_ATOMIC_LIB) + target_link_libraries(CMakeLib PUBLIC atomic) endif() # On Apple we need CoreFoundation and CoreServices diff --git a/Source/Checks/cm_cxx_atomic.cxx b/Source/Checks/cm_cxx_atomic.cxx new file mode 100644 index 0000000..098a7a7 --- /dev/null +++ b/Source/Checks/cm_cxx_atomic.cxx @@ -0,0 +1,6 @@ +#include <atomic> +int main() +{ + std::atomic<long long>(0).load(); + return 0; +} diff --git a/Source/Checks/cm_cxx_atomic_builtin.cxx b/Source/Checks/cm_cxx_atomic_builtin.cxx new file mode 100644 index 0000000..d284f6c --- /dev/null +++ b/Source/Checks/cm_cxx_atomic_builtin.cxx @@ -0,0 +1 @@ +#include "cm_cxx_atomic.cxx" diff --git a/Source/Checks/cm_cxx_atomic_lib.cxx b/Source/Checks/cm_cxx_atomic_lib.cxx new file mode 100644 index 0000000..d284f6c --- /dev/null +++ b/Source/Checks/cm_cxx_atomic_lib.cxx @@ -0,0 +1 @@ +#include "cm_cxx_atomic.cxx" diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index f5b7587..98d5eff 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -17,6 +17,7 @@ function(cm_check_cxx_feature name) try_run(CMake_RUN_CXX_${FEATURE} CMake_COMPILE_CXX_${FEATURE} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/cm_cxx_${name}.cxx + LINK_LIBRARIES ${cm_check_cxx_feature_LINK_LIBRARIES} CMAKE_FLAGS ${maybe_cxx_standard} OUTPUT_VARIABLE OUTPUT ) @@ -29,6 +30,7 @@ function(cm_check_cxx_feature name) try_compile(CMake_HAVE_CXX_${FEATURE} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/cm_cxx_${name}.cxx + LINK_LIBRARIES ${cm_check_cxx_feature_LINK_LIBRARIES} CMAKE_FLAGS ${maybe_cxx_standard} OUTPUT_VARIABLE OUTPUT ) @@ -93,3 +95,12 @@ if (NOT CMAKE_CXX_STANDARD LESS "17") else() set(CMake_HAVE_CXX_FILESYSTEM FALSE) endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l|sparc") + cm_check_cxx_feature(atomic_builtin) + if(NOT CMake_HAVE_CXX_ATOMIC_BUILTIN) + set(cm_check_cxx_feature_LINK_LIBRARIES atomic) + cm_check_cxx_feature(atomic_lib) # defines CMake_HAVE_CXX_ATOMIC_LIB + unset(cm_check_cxx_feature_LINK_LIBRARIES) + endif() +endif() diff --git a/Utilities/cmcppdap/CMakeLists.txt b/Utilities/cmcppdap/CMakeLists.txt index 39f72a2..b6841f1 100644 --- a/Utilities/cmcppdap/CMakeLists.txt +++ b/Utilities/cmcppdap/CMakeLists.txt @@ -33,5 +33,8 @@ if(WIN32) elseif(NOT APPLE) target_link_libraries(cmcppdap PRIVATE Threads::Threads) endif() +if(CMake_HAVE_CXX_ATOMIC_LIB) + target_link_libraries(cmcppdap PRIVATE atomic) +endif() install(FILES NOTICE DESTINATION ${CMAKE_DOC_DIR}/cmcppdap) |