From ce6ec5389a7c4cce8efd4eb09ca311eac624ed39 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 31 Dec 2020 23:20:48 +0200 Subject: [PATCH] check for semaphore header, dl and rt libraries during build Signed-off-by: Ivailo Monev --- CMakeLists.txt | 1 + src/core/CMakeLists.txt | 25 +++++++++---------------- src/core/kernel/qsharedmemory.cpp | 2 +- src/core/kernel/qsharedmemory_p.h | 4 ++-- src/core/kernel/qsharedmemory_unix.cpp | 24 ++++++++++++------------ src/core/kernel/qsystemsemaphore.cpp | 2 +- src/core/kernel/qsystemsemaphore_p.h | 6 +++--- src/core/kernel/qsystemsemaphore_unix.cpp | 16 ++++++++-------- 8 files changed, 37 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac296bf7..39c65880e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,6 +331,7 @@ check_type_size(size_t QT_POINTER_SIZE) # used in components, tests and JavaScriptCore katie_check_header("cxxabi.h") +katie_check_header("semaphore.h") katie_check_function(getpwnam_r "pwd.h") katie_check_function(getpwuid_r "pwd.h") katie_check_function(getgrgid_r "grp.h") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index df4a54432..9a619d719 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,7 +1,4 @@ -add_definitions( - # that conditional is probably going to become default in the future - -DQT_POSIX_IPC -) +# add_definitions() set(EXTRA_CORE_LIBS ${ZLIB_LIBRARIES} ${ICU_LIBRARIES} @@ -421,18 +418,14 @@ set(CORE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tools/qelapsedtimer_unix.cpp ) -if(KATIE_PLATFORM MATCHES "(linux|hurd)") - set(EXTRA_CORE_LIBS - ${EXTRA_CORE_LIBS} - dl - rt - ) -elseif(KATIE_PLATFORM STREQUAL "netbsd") - set(EXTRA_CORE_LIBS - ${EXTRA_CORE_LIBS} - rt - ) -endif() +# on some platforms these are not needed as the functionality may be part of +# standard C library +foreach(lib dl rt) + find_path(libpath NAMES ${lib}) + if(libpath) + set(EXTRA_CORE_LIBS ${EXTRA_CORE_LIBS} ${lib}) + endif() +endforeach() if(WITH_INTL AND INTL_FOUND) set(EXTRA_CORE_LIBS diff --git a/src/core/kernel/qsharedmemory.cpp b/src/core/kernel/qsharedmemory.cpp index 1aaafd414..5016b804f 100644 --- a/src/core/kernel/qsharedmemory.cpp +++ b/src/core/kernel/qsharedmemory.cpp @@ -55,7 +55,7 @@ QString QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, return QString(); QString result = prefix + key.toUtf8().toHex(); -#if defined(QT_POSIX_IPC) +#if defined(QT_HAVE_SEMAPHORE_H) return QLatin1Char('/') + result; #else return QDir::tempPath() + QLatin1Char('/') + result; diff --git a/src/core/kernel/qsharedmemory_p.h b/src/core/kernel/qsharedmemory_p.h index 288d76719..cd39bd607 100644 --- a/src/core/kernel/qsharedmemory_p.h +++ b/src/core/kernel/qsharedmemory_p.h @@ -118,7 +118,7 @@ public: static int createUnixKeyFile(const QString &fileName); static QString makePlatformSafeKey(const QString &key, const QString &prefix = QLatin1String("qipc_sharedmemory_")); -#if defined(QT_POSIX_IPC) +#if defined(QT_HAVE_SEMAPHORE_H) int handle(); #else key_t handle(); @@ -143,7 +143,7 @@ public: #endif // QT_NO_SYSTEMSEMAPHORE private: -#if defined(QT_POSIX_IPC) +#if defined(QT_HAVE_SEMAPHORE_H) int hand; #else key_t unix_key; diff --git a/src/core/kernel/qsharedmemory_unix.cpp b/src/core/kernel/qsharedmemory_unix.cpp index 19453976d..07d96cd20 100644 --- a/src/core/kernel/qsharedmemory_unix.cpp +++ b/src/core/kernel/qsharedmemory_unix.cpp @@ -42,7 +42,7 @@ #ifndef QT_NO_SHAREDMEMORY #include #include -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H #include #else #include @@ -66,7 +66,7 @@ QSharedMemoryPrivate::QSharedMemoryPrivate() #ifndef QT_NO_SYSTEMSEMAPHORE systemSemaphore(QString()), lockedByMe(false), #endif -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H unix_key(0) #else hand(0) @@ -118,7 +118,7 @@ void QSharedMemoryPrivate::setErrorString(const QString &function) If not already made create the handle used for accessing the shared memory. */ -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H key_t QSharedMemoryPrivate::handle() { // already made @@ -152,7 +152,7 @@ int QSharedMemoryPrivate::handle() return 1; } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H #endif // QT_NO_SHAREDMEMORY @@ -168,7 +168,7 @@ int QSharedMemoryPrivate::handle() */ int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName) { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H if (QFile::exists(fileName)) return 0; @@ -194,7 +194,7 @@ int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName) void QSharedMemoryPrivate::cleanHandle() { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H unix_key = 0; #else qt_safe_close(hand); @@ -204,7 +204,7 @@ void QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H // build file if needed int built = createUnixKeyFile(nativeKey); if (built == -1) { @@ -268,14 +268,14 @@ bool QSharedMemoryPrivate::create(int size) } qt_safe_close(fd); -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H return true; } bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H // grab the shared memory segment id int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600)); if (-1 == id) { @@ -340,14 +340,14 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode) size = 0; return false; } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H return true; } bool QSharedMemoryPrivate::detach() { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H // detach from the memory segment if (-1 == shmdt(memory)) { QString function = QLatin1String("QSharedMemory::detach"); @@ -417,7 +417,7 @@ bool QSharedMemoryPrivate::detach() if (::shm_unlink(shmName.constData()) == -1 && errno != ENOENT) setErrorString(QLatin1String("QSharedMemory::detach (shm_unlink)")); } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H return true; } diff --git a/src/core/kernel/qsystemsemaphore.cpp b/src/core/kernel/qsystemsemaphore.cpp index 580a5775c..b6f57088e 100644 --- a/src/core/kernel/qsystemsemaphore.cpp +++ b/src/core/kernel/qsystemsemaphore.cpp @@ -201,7 +201,7 @@ void QSystemSemaphore::setKey(const QString &key, int initialValue, AccessMode m return; d->error = NoError; d->errorString = QString(); -#if !defined(QT_POSIX_IPC) +#if !defined(QT_HAVE_SEMAPHORE_H) // optimization to not destroy/create the file & semaphore if (key == d->key && mode == Create && d->createdSemaphore && d->createdFile) { d->initialValue = initialValue; diff --git a/src/core/kernel/qsystemsemaphore_p.h b/src/core/kernel/qsystemsemaphore_p.h index 9707f7a59..bb9e99003 100644 --- a/src/core/kernel/qsystemsemaphore_p.h +++ b/src/core/kernel/qsystemsemaphore_p.h @@ -52,7 +52,7 @@ #include "qsharedmemory_p.h" #include -#ifdef QT_POSIX_IPC +#ifdef QT_HAVE_SEMAPHORE_H # include #endif @@ -69,7 +69,7 @@ public: return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemsem_")); } -#if defined(QT_POSIX_IPC) +#if defined(QT_HAVE_SEMAPHORE_H) bool handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open); void setErrorString(const QString &function); #else @@ -82,7 +82,7 @@ public: QString key; QString fileName; int initialValue; -#if defined(QT_POSIX_IPC) +#if defined(QT_HAVE_SEMAPHORE_H) sem_t *semaphore; bool createdSemaphore; #else diff --git a/src/core/kernel/qsystemsemaphore_unix.cpp b/src/core/kernel/qsystemsemaphore_unix.cpp index 415eaabb6..35254d43c 100644 --- a/src/core/kernel/qsystemsemaphore_unix.cpp +++ b/src/core/kernel/qsystemsemaphore_unix.cpp @@ -42,7 +42,7 @@ #include #include -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H #include #endif #include @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE QSystemSemaphorePrivate::QSystemSemaphorePrivate() : -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H unix_key(-1), semaphore(-1), createdFile(false), #else semaphore(QT_SEM_FAILED), @@ -123,7 +123,7 @@ void QSystemSemaphorePrivate::setErrorString(const QString &function) Initialise the semaphore */ -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) { if (-1 != unix_key) @@ -232,7 +232,7 @@ bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) createdSemaphore = (oflag & O_EXCL) != 0; return true; } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H /*! \internal @@ -241,7 +241,7 @@ bool QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode) */ void QSystemSemaphorePrivate::cleanHandle() { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H unix_key = -1; // remove the file if we made it @@ -282,7 +282,7 @@ void QSystemSemaphorePrivate::cleanHandle() } createdSemaphore = false; } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H } /*! @@ -290,7 +290,7 @@ void QSystemSemaphorePrivate::cleanHandle() */ bool QSystemSemaphorePrivate::modifySemaphore(int count) { -#ifndef QT_POSIX_IPC +#ifndef QT_HAVE_SEMAPHORE_H if (-1 == handle()) return false; @@ -352,7 +352,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count) return false; } } -#endif // QT_POSIX_IPC +#endif // QT_HAVE_SEMAPHORE_H return true; } -- 2.11.0