From 4306df6f772a04ed1a0311b8c01ef135cf760dab Mon Sep 17 00:00:00 2001 From: Oleksiy Lukin Date: Fri, 6 Sep 2024 14:43:05 +0300 Subject: [PATCH] PS-9379 Fix problem with "-latomic" on some platorms in uuid_vx component https://perconadev.atlassian.net/browse/PS-9379 Fix of problem with -latomic in uuid_vx component of some platofrms. CMakeLists.txtx for the component now check code sample compilation and adds "-latomic" if required. Note! On RHEL platforms the package "gcc-toolset-12-libatomic-devel" must be installed as compile dependency. --- components/uuid_vx_udf/CMakeLists.txt | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/uuid_vx_udf/CMakeLists.txt b/components/uuid_vx_udf/CMakeLists.txt index 469609a68288..c6cecb07de13 100644 --- a/components/uuid_vx_udf/CMakeLists.txt +++ b/components/uuid_vx_udf/CMakeLists.txt @@ -33,6 +33,26 @@ MYSQL_ADD_COMPONENT(uuid_vx_udf target_include_directories(component_uuid_vx_udf SYSTEM PRIVATE ${BOOST_PATCHES_DIR} ${BOOST_INCLUDE_DIR}) -if(NOT APPLE) - target_link_libraries(component_uuid_vx_udf PRIVATE atomic) +# Check if -latomic is required or not +if (NOT MSVC) + include(CheckCXXSourceCompiles) + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) +# Adding "-w" compiler option to suppres all possible warnings + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++17 -w) + check_cxx_source_compiles(" + #include + std::atomic x(0); + int main() { + uint64_t i = x.load(std::memory_order_relaxed); + bool b = x.is_lock_free(); + return 0; + } + " uuid_vx_HAVE_BUILTIN_ATOMICS) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + if (uuid_vx_HAVE_BUILTIN_ATOMICS) + message(STATUS "Building UUID_VX UDF component without libatomic") + else() + message(STATUS "Building UUID_VX UDF component with libatomic") + target_link_libraries(component_uuid_vx_udf PRIVATE atomic) + endif() endif()