qconfig.cpp: use qOffsetStringArray

It's been there for ages, we may as well use it and remove unnecessary
complexity from CMake.

Pick-to: 6.2
Change-Id: I2bbf422288924c198645fffd16a9742567a7e4af
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Thiago Macieira 2021-09-29 18:07:23 -07:00
parent 388136e860
commit a887b7750c
4 changed files with 35 additions and 44 deletions

View File

@ -13,35 +13,22 @@ function(qt_to_qmake_path_list out_var)
set("${out_var}" "${result}" PARENT_SCOPE)
endfunction()
macro(qt_add_string_to_qconfig_cpp str)
string(LENGTH "${str}" length)
string(APPEND QT_CONFIG_STRS " \"${str}\\0\"\n")
string(APPEND QT_CONFIG_STR_OFFSETS " ${QT_CONFIG_STR_OFFSET},\n")
math(EXPR QT_CONFIG_STR_OFFSET "${QT_CONFIG_STR_OFFSET}+${length}+1")
endmacro()
function(qt_generate_qconfig_cpp in_file out_file)
set(QT_CONFIG_STR_OFFSET "0")
set(QT_CONFIG_STR_OFFSETS "")
set(QT_CONFIG_STRS "")
# Start first part.
qt_add_string_to_qconfig_cpp("${INSTALL_DOCDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_INCLUDEDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_LIBDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_LIBEXECDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_BINDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_PLUGINSDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_QMLDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_ARCHDATADIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_DATADIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_TRANSLATIONSDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_EXAMPLESDIR}")
qt_add_string_to_qconfig_cpp("${INSTALL_TESTSDIR}")
# Save first part.
set(QT_CONFIG_STR_OFFSETS_FIRST "${QT_CONFIG_STR_OFFSETS}")
set(QT_CONFIG_STRS_FIRST "${QT_CONFIG_STRS}")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_DOCDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_INCLUDEDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_LIBDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_LIBEXECDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_BINDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_PLUGINSDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_QMLDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_ARCHDATADIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_DATADIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_TRANSLATIONSDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_EXAMPLESDIR}\",\n")
string(APPEND QT_CONFIG_STRS " \"${INSTALL_TESTSDIR}\"")
# Settings path / sysconf dir.
set(QT_SYS_CONF_DIR "${INSTALL_SYSCONFDIR}")

View File

@ -5,19 +5,16 @@
*
* - QLibraryInfo::LibraryPath enum in qtbase/src/corelib/global/qlibraryinfo.h
* - qtConfEntries in qtbase/src/corelib/global/qlibraryinfo.cpp
*
* The reason for this is pointer mathematics in the QLibraryInfo implementation when iterating
* qt_configure_strs. Also qtConfEntries are strongly bound to QLibraryInfo::LibraryPath.
*/
#include "private/qoffsetstringarray_p.h"
/* Installation Info */
static const char qt_configure_prefix_path_str [12+256] = "qt_prfxpath=@QT_CONFIGURE_PREFIX_PATH_STR@";
static const short qt_configure_str_offsets[] = {
@QT_CONFIG_STR_OFFSETS_FIRST@
};
static const char qt_configure_strs[] =
@QT_CONFIG_STRS_FIRST@
;
static constexpr auto qt_configure_strs = QT_PREPEND_NAMESPACE(qOffsetStringArray)(
@QT_CONFIG_STRS@
);
#define QT_CONFIGURE_SETTINGS_PATH "@QT_SYS_CONF_DIR@"
#define QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH "@QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH@"
#define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12

View File

@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2021 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@ -51,14 +51,13 @@
#include "qcoreapplication.h"
#include "private/qglobal_p.h"
#include "archdetect.cpp"
#include "qconfig.cpp"
#ifdef Q_OS_DARWIN
# include "private/qcore_mac_p.h"
#endif // Q_OS_DARWIN
#include "archdetect.cpp"
#if QT_CONFIG(relocatable) && QT_CONFIG(dlopen) && !QT_CONFIG(framework)
# include <dlfcn.h>
#endif
@ -454,7 +453,7 @@ static QString getRelocatablePrefix()
// executable within the QT_HOST_BIN directory. We're detecting the latter case by checking
// whether there's an import library corresponding to our QtCore DLL in PREFIX/lib.
const QString libdir = QString::fromLocal8Bit(
qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
qt_configure_strs[QLibraryInfo::LibrariesPath - 1]);
const QLatin1Char slash('/');
#if defined(Q_CC_MINGW)
const QString implibPrefix = QStringLiteral("lib");
@ -486,7 +485,7 @@ static QString getRelocatablePrefix()
// See "Hardware capabilities" in the ld.so documentation and the Qt 5.3.0
// changelog regarding SSE2 support.
const QString libdir = QString::fromLocal8Bit(
qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
qt_configure_strs[QLibraryInfo::LibrariesPath - 1]);
QDir prefixDir(prefixPath);
while (!prefixDir.exists(libdir)) {
prefixDir.cdUp();
@ -596,8 +595,8 @@ QString QLibraryInfo::path(LibraryPath p)
const char * volatile path = nullptr;
if (loc == PrefixPath) {
ret = getPrefix();
} else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) {
path = qt_configure_strs + qt_configure_str_offsets[loc - 1];
} else if (int(loc) <= qt_configure_strs.count()) {
path = qt_configure_strs[loc - 1];
#ifndef Q_OS_WIN // On Windows we use the registry
} else if (loc == SettingsPath) {
path = QT_CONFIGURE_SETTINGS_PATH;
@ -691,6 +690,7 @@ QT_END_NAMESPACE
#include "private/qcoreapplication_p.h"
QT_WARNING_DISABLE_GCC("-Wformat-overflow")
QT_WARNING_DISABLE_GCC("-Wattributes")
QT_WARNING_DISABLE_CLANG("-Wattributes")
QT_WARNING_DISABLE_INTEL(2621)
@ -738,8 +738,8 @@ void qt_core_boilerplate()
"Library path: %s\n"
"Plugin path: %s\n",
qt_configure_prefix_path_str + 12,
qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1],
qt_configure_strs + qt_configure_str_offsets[QT_PREPEND_NAMESPACE(QLibraryInfo)::PluginsPath - 1]);
qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1],
qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::PluginsPath - 1]);
QT_PREPEND_NAMESPACE(qDumpCPUFeatures)();

View File

@ -63,6 +63,12 @@ class tst_QOffsetStringArray;
QT_BEGIN_NAMESPACE
QT_WARNING_PUSH
#if defined(Q_CC_GNU) && Q_CC_GNU >= 1100
// we usually don't overread, but GCC has a false positive
QT_WARNING_DISABLE_GCC("-Wstringop-overread")
#endif
template <typename StaticString, typename OffsetList>
class QOffsetStringArray
@ -172,6 +178,7 @@ constexpr auto qOffsetStringArray(const char (&...strings)[Nx]) noexcept
return QtPrivate::qOffsetStringArray(extractString, QtPrivate::StaticString(strings)...);
}
QT_WARNING_POP
QT_END_NAMESPACE
#endif // QOFFSETSTRINGARRAY_P_H