From cf3cbeaeb4112a9ea896c49c20783ce911f27d25 Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Thu, 2 Feb 2023 21:57:39 +0100 Subject: [PATCH 1/8] =?UTF-8?q?Add=20CheckAtomic=20package=20helper=20to?= =?UTF-8?q?=20fix=20build=20on=20riscv64=20architecture=20(=E2=80=A6=20(#4?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add CheckAtomic package helper to fix build on riscv64 architecture (needing latomic library) --- CMakeLists.txt | 6 +++ cmake/Modules/CheckAtomic.cmake | 95 +++++++++++++++++++++++++++++++++ source/CMakeLists.txt | 9 ++++ 3 files changed, 110 insertions(+) create mode 100644 cmake/Modules/CheckAtomic.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 815c5c4..64f3521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,12 @@ if(PTL_USE_TBB) find_package(TBB 2017 REQUIRED) endif() +# Check if compiler provides std::atomic without a library +include(CheckAtomic) +if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + set(PTL_LINK_ATOMIC TRUE) +endif() + # -------------------------------------------------------------------------------------- # # PTL Primary Build add_subdirectory(source) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake new file mode 100644 index 0000000..d154b11 --- /dev/null +++ b/cmake/Modules/CheckAtomic.cmake @@ -0,0 +1,95 @@ +# SPDX-FileCopyrightText: 2003-2018 University of Illinois at Urbana-Champaign. +# +# SPDX-License-Identifier: BSD-3-Clause + +#[=======================================================================[.rst: +CheckAtomic +----------- + +Check if the compiler supports std:atomic out of the box or if libatomic is +needed for atomic support. If it is needed libatomicis added to +``CMAKE_REQUIRED_LIBRARIES``. So after running CheckAtomic you can use +std:atomic. + +Since 5.75.0. +#]=======================================================================] + +include(CheckCXXSourceCompiles) +include(CheckLibraryExists) + +# Sometimes linking against libatomic is required for atomic ops, if +# the platform doesn't support lock-free atomics. + +function(check_working_cxx_atomics varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") + check_cxx_source_compiles(" + #include + std::atomic x; + std::atomic y; + std::atomic z; + int main() { + ++z; + ++y; + return ++x; + } + " ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction() + +function(check_working_cxx_atomics64 varname) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") + check_cxx_source_compiles(" + #include + #include + std::atomic x (0); + int main() { + uint64_t i = x.load(std::memory_order_relaxed); + return 0; + } + " ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) +endfunction() + +# Check for (non-64-bit) atomic operations. +if(MSVC) + set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) +elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) + # First check if atomics work without the library. + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) + if(HAVE_LIBATOMIC) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS_WITH_LIB) + message(FATAL_ERROR "Host compiler must support std::atomic!") + endif() + else() + message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") + endif() + endif() +endif() + +# Check for 64 bit atomic operations. +if(MSVC) + set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) +elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) + # First check if atomics work without the library. + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) + if(HAVE_CXX_LIBATOMICS64) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) + if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) + message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") + endif() + else() + message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.") + endif() + endif() +endif() diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 26c3038..3957e83 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -37,6 +37,9 @@ if(BUILD_OBJECT_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-object PUBLIC TBB::tbb) endif() + if(PTL_LINK_ATOMIC) + target_link_libraries(ptl-object PUBLIC atomic) + endif() target_include_directories( ptl-object PUBLIC $ @@ -55,6 +58,9 @@ if(BUILD_SHARED_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-shared PUBLIC TBB::tbb) endif() + if(PTL_LINK_ATOMIC) + target_link_libraries(ptl-shared PUBLIC atomic) + endif() target_compile_definitions(ptl-shared PUBLIC PTL_BUILD_DLL) @@ -88,6 +94,9 @@ if(BUILD_STATIC_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-static PUBLIC TBB::tbb) endif() + if(PTL_LINK_ATOMIC) + target_link_libraries(ptl-static PUBLIC atomic) + endif() target_include_directories( ptl-static From a90ba593d4a4297300f9826950ac2150d2f2290e Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Thu, 9 Feb 2023 09:02:39 +0100 Subject: [PATCH 2/8] Fix MACOSX build, they don't need atomic library --- cmake/Modules/CheckAtomic.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index d154b11..fb9c636 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -53,7 +53,7 @@ function(check_working_cxx_atomics64 varname) endfunction() # Check for (non-64-bit) atomic operations. -if(MSVC) +if(MSVC OR APPLE) set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) # First check if atomics work without the library. @@ -74,7 +74,7 @@ elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) endif() # Check for 64 bit atomic operations. -if(MSVC) +if(MSVC OR APPLE) set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) # First check if atomics work without the library. From a90a2aab628e539d48c9470d60704a61ebcb5bab Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Thu, 9 Feb 2023 09:05:26 +0100 Subject: [PATCH 3/8] Improve verbosity for CheckAtomic changes --- cmake/Modules/CheckAtomic.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index fb9c636..9831c85 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -53,7 +53,7 @@ function(check_working_cxx_atomics64 varname) endfunction() # Check for (non-64-bit) atomic operations. -if(MSVC OR APPLE) +if(MSVC OR APPLE) # apple do not need latomic link set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) # First check if atomics work without the library. @@ -74,7 +74,7 @@ elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) endif() # Check for 64 bit atomic operations. -if(MSVC OR APPLE) +if(MSVC OR APPLE) # apple do not need latomic link set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) # First check if atomics work without the library. From b194057ec82cb389caba42294f70fa80b594b017 Mon Sep 17 00:00:00 2001 From: Seth Parker Date: Wed, 1 Nov 2023 10:49:56 -0400 Subject: [PATCH 4/8] Small description change --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f3521..cb02d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ if(PTL_USE_TBB) find_package(TBB 2017 REQUIRED) endif() -# Check if compiler provides std::atomic without a library +# Check if compiler provides std::atomic as a library include(CheckAtomic) if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) set(PTL_LINK_ATOMIC TRUE) From bfefb42fcb89254f3c16092cb380f475a3496815 Mon Sep 17 00:00:00 2001 From: Seth Parker Date: Fri, 3 Nov 2023 13:13:38 -0400 Subject: [PATCH 5/8] cmake-format --- cmake/Modules/CheckAtomic.cmake | 125 +++++++++++++++++--------------- 1 file changed, 67 insertions(+), 58 deletions(-) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index 9831c85..6bf18b4 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -17,79 +17,88 @@ Since 5.75.0. include(CheckCXXSourceCompiles) include(CheckLibraryExists) -# Sometimes linking against libatomic is required for atomic ops, if -# the platform doesn't support lock-free atomics. +# Sometimes linking against libatomic is required for atomic ops, if the platform doesn't +# support lock-free atomics. function(check_working_cxx_atomics varname) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") - check_cxx_source_compiles(" - #include - std::atomic x; - std::atomic y; - std::atomic z; - int main() { - ++z; - ++y; - return ++x; - } - " ${varname}) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") + check_cxx_source_compiles( + " + #include + std::atomic x; + std::atomic y; + std::atomic z; + int main() { + ++z; + ++y; + return ++x; + } + " + ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) endfunction() function(check_working_cxx_atomics64 varname) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") - check_cxx_source_compiles(" - #include - #include - std::atomic x (0); - int main() { - uint64_t i = x.load(std::memory_order_relaxed); - return 0; - } - " ${varname}) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") + check_cxx_source_compiles( + " + #include + #include + std::atomic x (0); + int main() { + uint64_t i = x.load(std::memory_order_relaxed); + return 0; + } + " + ${varname}) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) endfunction() # Check for (non-64-bit) atomic operations. if(MSVC OR APPLE) # apple do not need latomic link - set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) + set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) - # First check if atomics work without the library. - check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) - # If not, check if the library exists, and atomics work with it. - if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) - check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) - if(HAVE_LIBATOMIC) - list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") - check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) - if (NOT HAVE_CXX_ATOMICS_WITH_LIB) - message(FATAL_ERROR "Host compiler must support std::atomic!") - endif() - else() - message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.") + # First check if atomics work without the library. + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) + if(HAVE_LIBATOMIC) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) + if(NOT HAVE_CXX_ATOMICS_WITH_LIB) + message(FATAL_ERROR "Host compiler must support std::atomic!") + endif() + else() + message( + FATAL_ERROR + "Host compiler appears to require libatomic, but cannot find it.") + endif() endif() - endif() endif() # Check for 64 bit atomic operations. if(MSVC OR APPLE) # apple do not need latomic link - set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) + set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) - # First check if atomics work without the library. - check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) - # If not, check if the library exists, and atomics work with it. - if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) - check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) - if(HAVE_CXX_LIBATOMICS64) - list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") - check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) - if (NOT HAVE_CXX_ATOMICS64_WITH_LIB) - message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") - endif() - else() - message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.") + # First check if atomics work without the library. + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) + # If not, check if the library exists, and atomics work with it. + if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) + check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) + if(HAVE_CXX_LIBATOMICS64) + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) + if(NOT HAVE_CXX_ATOMICS64_WITH_LIB) + message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") + endif() + else() + message( + FATAL_ERROR + "Host compiler appears to require libatomic for 64-bit operations, but cannot find it." + ) + endif() endif() - endif() endif() From ba0b840f8591cbdb9eff044468677dd6a75c13c7 Mon Sep 17 00:00:00 2001 From: Seth Parker Date: Mon, 6 Nov 2023 06:29:21 -0500 Subject: [PATCH 6/8] Simplify CheckAtomic --- CMakeLists.txt | 4 +- cmake/Modules/CheckAtomic.cmake | 121 ++++++++++++-------------------- source/CMakeLists.txt | 6 +- 3 files changed, 48 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb02d81..a6b2e38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,10 +87,8 @@ if(PTL_USE_TBB) endif() # Check if compiler provides std::atomic as a library +# Sets CXX_ATOMIC_WITH_LINK to TRUE if so include(CheckAtomic) -if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) - set(PTL_LINK_ATOMIC TRUE) -endif() # -------------------------------------------------------------------------------------- # # PTL Primary Build diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index 6bf18b4..7c01e94 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -14,91 +14,58 @@ std:atomic. Since 5.75.0. #]=======================================================================] +include(CMakePushCheckState) include(CheckCXXSourceCompiles) include(CheckLibraryExists) +cmake_push_check_state() + # Sometimes linking against libatomic is required for atomic ops, if the platform doesn't # support lock-free atomics. -function(check_working_cxx_atomics varname) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") - check_cxx_source_compiles( - " - #include - std::atomic x; - std::atomic y; - std::atomic z; - int main() { - ++z; - ++y; - return ++x; - } - " - ${varname}) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) -endfunction() +# 64-bit target test code +if (CMAKE_SIZE_OF_VOID_P EQUAL 8) + set(ATOMIC_CODE_64 " + std::atomic x(0); + uint64_t i = x.load(std::memory_order_relaxed); + ") +endif() + +# Test code +string(CONFIGURE [[ + #include + #include + int main() { + std::atomic a; + std::atomic b; + std::atomic c; + ++c; + ++b; + ++a; + @ATOMIC_CODE_64@ + return a; + } +]] ATOMIC_CODE @ONLY) -function(check_working_cxx_atomics64 varname) - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}") - check_cxx_source_compiles( - " - #include - #include - std::atomic x (0); - int main() { - uint64_t i = x.load(std::memory_order_relaxed); - return 0; - } - " - ${varname}) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) -endfunction() +set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") +check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_NO_LINK) -# Check for (non-64-bit) atomic operations. -if(MSVC OR APPLE) # apple do not need latomic link - set(HAVE_CXX_ATOMICS_WITHOUT_LIB True) -elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) - # First check if atomics work without the library. - check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) - # If not, check if the library exists, and atomics work with it. - if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) - check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) - if(HAVE_LIBATOMIC) - list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") - check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) - if(NOT HAVE_CXX_ATOMICS_WITH_LIB) - message(FATAL_ERROR "Host compiler must support std::atomic!") - endif() - else() - message( - FATAL_ERROR - "Host compiler appears to require libatomic, but cannot find it.") - endif() - endif() +set(ATOMIC_FOUND ${CXX_ATOMIC_NO_LINK}) + +if(NOT CXX_ATOMIC_NO_LINK) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) + check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_WITH_LINK) + set(ATOMIC_FOUND ${CXX_ATOMIC_WITH_LINK}) endif() -# Check for 64 bit atomic operations. -if(MSVC OR APPLE) # apple do not need latomic link - set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True) -elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) - # First check if atomics work without the library. - check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) - # If not, check if the library exists, and atomics work with it. - if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB) - check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) - if(HAVE_CXX_LIBATOMICS64) - list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") - check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) - if(NOT HAVE_CXX_ATOMICS64_WITH_LIB) - message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") - endif() - else() - message( - FATAL_ERROR - "Host compiler appears to require libatomic for 64-bit operations, but cannot find it." - ) - endif() - endif() +cmake_pop_check_state() + +if(ATOMIC_FOUND) + if(CXX_ATOMIC_NO_LINK) + message(VERBOSE "Found std::atomic with no linking") + elseif(CXX_ATOMIC_WITH_LINK) + message(VERBOSE "Found std::atomic with linking") + endif() +else() + message(WARNING "std::atomic not found with compilation checks") endif() diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 3957e83..4f8fef6 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -37,7 +37,7 @@ if(BUILD_OBJECT_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-object PUBLIC TBB::tbb) endif() - if(PTL_LINK_ATOMIC) + if(CXX_ATOMIC_WITH_LINK) target_link_libraries(ptl-object PUBLIC atomic) endif() @@ -58,7 +58,7 @@ if(BUILD_SHARED_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-shared PUBLIC TBB::tbb) endif() - if(PTL_LINK_ATOMIC) + if(CXX_ATOMIC_WITH_LINK) target_link_libraries(ptl-shared PUBLIC atomic) endif() @@ -94,7 +94,7 @@ if(BUILD_STATIC_LIBS) if(PTL_USE_TBB) target_link_libraries(ptl-static PUBLIC TBB::tbb) endif() - if(PTL_LINK_ATOMIC) + if(CXX_ATOMIC_WITH_LINK) target_link_libraries(ptl-static PUBLIC atomic) endif() From e10b44c5d827683a981884b6760dc06e7fc44fbb Mon Sep 17 00:00:00 2001 From: Seth Parker Date: Mon, 6 Nov 2023 06:45:49 -0500 Subject: [PATCH 7/8] cmake-format --- cmake/Modules/CheckAtomic.cmake | 63 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index 7c01e94..df6c933 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -24,28 +24,33 @@ cmake_push_check_state() # support lock-free atomics. # 64-bit target test code -if (CMAKE_SIZE_OF_VOID_P EQUAL 8) - set(ATOMIC_CODE_64 " - std::atomic x(0); - uint64_t i = x.load(std::memory_order_relaxed); - ") -endif() +if(CMAKE_SIZE_OF_VOID_P EQUAL 8) + set(ATOMIC_CODE_64 + " + std::atomic x(0); + uint64_t i = x.load(std::memory_order_relaxed); + ") +endif() # Test code -string(CONFIGURE [[ - #include - #include - int main() { - std::atomic a; - std::atomic b; - std::atomic c; - ++c; - ++b; - ++a; - @ATOMIC_CODE_64@ - return a; - } -]] ATOMIC_CODE @ONLY) +string( + CONFIGURE + [[ + #include + #include + int main() { + std::atomic a; + std::atomic b; + std::atomic c; + ++c; + ++b; + ++a; + @ATOMIC_CODE_64@ + return a; + } + ]] + ATOMIC_CODE + @ONLY) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_NO_LINK) @@ -53,19 +58,19 @@ check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_NO_LINK) set(ATOMIC_FOUND ${CXX_ATOMIC_NO_LINK}) if(NOT CXX_ATOMIC_NO_LINK) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) - check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_WITH_LINK) - set(ATOMIC_FOUND ${CXX_ATOMIC_WITH_LINK}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) + check_cxx_source_compiles("${ATOMIC_CODE}" CXX_ATOMIC_WITH_LINK) + set(ATOMIC_FOUND ${CXX_ATOMIC_WITH_LINK}) endif() cmake_pop_check_state() if(ATOMIC_FOUND) - if(CXX_ATOMIC_NO_LINK) - message(VERBOSE "Found std::atomic with no linking") - elseif(CXX_ATOMIC_WITH_LINK) - message(VERBOSE "Found std::atomic with linking") - endif() + if(CXX_ATOMIC_NO_LINK) + message(VERBOSE "Found std::atomic with no linking") + elseif(CXX_ATOMIC_WITH_LINK) + message(VERBOSE "Found std::atomic with linking") + endif() else() - message(WARNING "std::atomic not found with compilation checks") + message(WARNING "std::atomic not found with compilation checks") endif() From 11ab0671bb989c34d72fcb8573dbeac53082c6e3 Mon Sep 17 00:00:00 2001 From: Seth P Date: Mon, 6 Nov 2023 06:50:48 -0500 Subject: [PATCH 8/8] Update cmake/Modules/CheckAtomic.cmake --- cmake/Modules/CheckAtomic.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/Modules/CheckAtomic.cmake b/cmake/Modules/CheckAtomic.cmake index df6c933..44d919e 100644 --- a/cmake/Modules/CheckAtomic.cmake +++ b/cmake/Modules/CheckAtomic.cmake @@ -16,7 +16,6 @@ Since 5.75.0. include(CMakePushCheckState) include(CheckCXXSourceCompiles) -include(CheckLibraryExists) cmake_push_check_state()