From 75ca710370aadf5ad230f9b9059cc8295927430d Mon Sep 17 00:00:00 2001 From: Amir Masoud Abdol Date: Thu, 9 Feb 2023 16:13:30 +0100 Subject: [PATCH] Improve FindWrapRt, and SHM detection Apparently, more and more librt functionality are being moved to glibc these days, e.g., clock_gettime, clock_getres, clock_settime, clock_getcpuclockid, clock_nanosleep. As Thiago mentioned, in face, all librt functions are moving into glibc, but unlike the clock_* functions that I can see are ported from 2.17+, I cannot find out when and what functions are already ported. So, here, I added a second test which tries to explicitly look for shm_* functions, if they are there, as well as the clock_* function, then we are more confident that we actually have a useful the libRt in the system. Also, making the FEATURE_posix_SHM depends on UNIX. Pick-to: 6.5 Fixes: QTBUG-111049 Change-Id: I08b7f4656ecd9313b552fb05ca7096f5b987b95a Reviewed-by: Alexey Edelev Reviewed-by: Thiago Macieira --- cmake/FindWrapRt.cmake | 24 +++++++++++++++++++----- src/corelib/CMakeLists.txt | 8 ++++++-- src/corelib/configure.cmake | 4 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cmake/FindWrapRt.cmake b/cmake/FindWrapRt.cmake index 91651c32928..b394b062da0 100644 --- a/cmake/FindWrapRt.cmake +++ b/cmake/FindWrapRt.cmake @@ -21,17 +21,31 @@ if(LIBRT) endif() check_cxx_source_compiles(" -#include #include +#include int main(int, char **) { - timespec ts; clock_gettime(CLOCK_REALTIME, &ts); -}" HAVE_GETTIME) + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return 0; +} +" HAVE_GETTIME) + +check_cxx_source_compiles(" +#include +#include +#include + +int main(int, char **) { + shm_open(\"test\", O_RDWR | O_CREAT | O_EXCL, 0666); + shm_unlink(\"test\"); + return 0; +} +" HAVE_SHM_OPEN_SHM_UNLINK) cmake_pop_check_state() - -if(HAVE_GETTIME) +if(HAVE_GETTIME OR HAVE_SHM_OPEN_SHM_UNLINK) set(WrapRt_FOUND ON) add_library(WrapRt::WrapRt INTERFACE IMPORTED) if (LIBRT) diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index d724833913d..0ae76fe3ecb 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -1140,14 +1140,16 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_glib AND UNIX GLIB2::GLIB2 ) -qt_internal_extend_target(Core CONDITION QT_FEATURE_clock_gettime AND UNIX +qt_internal_extend_target(Core CONDITION QT_FEATURE_clock_gettime LIBRARIES WrapRt::WrapRt ) -qt_internal_extend_target(Core CONDITION QT_FEATURE_posix_shm +qt_internal_extend_target(Core CONDITION QT_FEATURE_posix_shm AND UNIX SOURCES ipc/qsharedmemory_posix.cpp + LIBRARIES + WrapRt::WrapRt ) qt_internal_extend_target(Core CONDITION QT_FEATURE_sysv_shm SOURCES @@ -1156,6 +1158,8 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_sysv_shm qt_internal_extend_target(Core CONDITION QT_FEATURE_posix_sem SOURCES ipc/qsystemsemaphore_posix.cpp + LIBRARIES + WrapRt::WrapRt ) qt_internal_extend_target(Core CONDITION QT_FEATURE_sysv_sem SOURCES diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake index b4a040fb294..d84a52132eb 100644 --- a/src/corelib/configure.cmake +++ b/src/corelib/configure.cmake @@ -331,7 +331,7 @@ int main(void) ") if (LINUX) - set(ipc_posix_TEST_LIBRARIES pthread rt) + set(ipc_posix_TEST_LIBRARIES pthread WrapRt::WrapRt) endif() qt_config_compile_test(posix_shm LABEL "POSIX shared memory" @@ -692,7 +692,7 @@ qt_feature("posix_sem" PRIVATE ) qt_feature("posix_shm" PRIVATE LABEL "POSIX shared memory" - CONDITION TEST_posix_shm + CONDITION TEST_posix_shm AND UNIX ) qt_feature("qqnx_pps" PRIVATE LABEL "PPS"