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 <alexey.edelev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Amir Masoud Abdol 2023-02-09 16:13:30 +01:00
parent 86d8d67146
commit 75ca710370
3 changed files with 27 additions and 9 deletions

View File

@ -21,17 +21,31 @@ if(LIBRT)
endif()
check_cxx_source_compiles("
#include <unistd.h>
#include <time.h>
#include <unistd.h>
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 <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
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)

View File

@ -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

View File

@ -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"