From 719799234136570c1dda6c649e39d08989bb5ec1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 21 Jan 2025 08:29:40 +0100 Subject: [PATCH] Long live qstdlibdetection.h! I've been meaning to add this since at least 2012 (cf. commit message of 9180d9aa8bfb9e9f66fad13f194398a98698eb77), this is as good a time as any. Detection taken from qcompare.h, except for - libstdc++: using version macro instead of date one - Dinkumware, which is taken from the above-mentioned commit (adjusted for the LIBCPP->CPPLIB typo), - STLport/SGI, which are taken from stlport's _stlport_version.h, - RogueWave, which is taken from Apache stdcxx's rw/_config.h, a fork of RogueWave, contributed to Apache by RogueWave themselves. It looks like not all STLs provide a version macro, and those that do vary a lot in granularity, so for the time being, just define these macros to nothing and not to some form of version. [ChangeLog][QtCore] Added Q_STL_ macros for stdlib detection (libc++, libstdc++, MSSTL, Dinkumware, STLport, SGI, RogueWave). If your STL is lacking, please file a bug report. Note that these macros are not considered public API just yet. Picking to all active branches, since not picking is more risky (code that assumed these macros existed in older branches could silently change behavior if they don't). Fixes: QTBUG-132908 Fixes: QTBUG-132909 Pick-to: 6.8 6.5 6.2 5.15 Change-Id: I8f956d131292483b7727f11f69b460b12a06b583 Reviewed-by: Thiago Macieira (cherry picked from commit b6f825a857d0d2266ea89879f26703f86ddf669a) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/CMakeLists.txt | 1 + src/corelib/global/qstdlibdetection.h | 60 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/corelib/global/qstdlibdetection.h diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index f2c7519aba5..8c1c214808b 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -68,6 +68,7 @@ qt_internal_add_module(Core global/qoverload.h global/qprocessordetection.h global/qrandom.cpp global/qrandom.h global/qrandom_p.h + global/qstdlibdetection.h global/qswap.h global/qsysinfo.cpp global/qsysinfo.h global/qsystemdetection.h diff --git a/src/corelib/global/qstdlibdetection.h b/src/corelib/global/qstdlibdetection.h new file mode 100644 index 00000000000..64c588237f9 --- /dev/null +++ b/src/corelib/global/qstdlibdetection.h @@ -0,0 +1,60 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#if 0 +#pragma qt_class(QtStdLibDetection) +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif + +#ifndef QSTDLIBDETECTION_H +#define QSTDLIBDETECTION_H + +#include + +#ifdef __cplusplus + +/* If exists, qtconfiginclude.h will have included it. */ +/* If not, we need to include _something_, and is included by qcompilerdetection.h, too */ +#if !__has_include() +# include +#endif + +/* + The std lib, must be one of: (Q_STL_x) + + LIBCPP - libc++ (shipped with Clang, e.g.) + LIBSTDCPP - libstdc++ (shipped with GCC, e.g.) + MSSTL - Microsoft STL + DINKUMWARE - Dinkumware (shipped with QNX, VxWorks, Integrity, origin of MSSTL) + STLPORT - STLport (merged with SGI) + SGI - The original STL + ROGUEWAVE - RogueWave ((used to be) popular on ARM?) + + Not included: + EASTL - EASTL (this is not a drop-in STL, e.g. it doesn't have -style headers) + + Should be sorted most to least authoritative. +*/ + +#if defined(_LIBCPP_VERSION) /* libc++ */ +# define Q_STL_LIBCPP +#elif defined(_GLIBCXX_RELEASE) /* libstdc++ */ +# define Q_STL_LIBSTDCPP +#elif defined(_MSVC_STL_VERSION) /* MSSTL (must be before Dinkumware) */ +# define Q_STL_MSSTL +#elif defined(_YVALS) || defined(_CPPLIB_VER) /* Dinkumware */ +# define Q_STL_DINKUMWARE +#elif defined(_STLPORT_VERSION) /* STLport, cf. _stlport_version.h */ +# define Q_STL_STLPORT +#elif defined(__SGI_STL) /* must be after STLport, which mimics as SGI STL */ +# define Q_STL_SGI +#elif defined(_RWSTD_VER) /* RogueWave, at least as contributed to Apache stdcxx, cf. rw/_config.h */ +# define Q_STL_ROGUEWAVE +#else +# error Unknown std library implementation, please file a report at bugreports.qt.io. +#endif + +#endif // __cplusplus + +#endif // QSTDLIBDETECTION_H