From 3568ad58f5e273d60f089a1b2d8c91c9535c8cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 7 Feb 2020 14:01:18 +0100 Subject: [PATCH] Introduce a configure-time check for C++17 filesystem Various compilers have various fun ways of failing to compile when it is used so let's check if they will work properly during configure rather than much later. Change-Id: Ia93d4b91b3d269b4cab2a5f677c3c89e06b44ce3 Reviewed-by: Timur Pocheptsov --- src/corelib/configure.json | 16 ++++++++++++++++ src/corelib/global/qconfig-bootstrapped.h | 1 + .../benchmarks/corelib/io/qdiriterator/main.cpp | 8 ++------ .../corelib/io/qdiriterator/qdiriterator.pro | 6 +++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/corelib/configure.json b/src/corelib/configure.json index b607c300dd8..667f6e2104f 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -366,6 +366,15 @@ "main": "std::mt19937 mt(0);" } }, + "cxx17_filesystem": { + "label": "C++17 ", + "type": "compile", + "test": { + "include": "filesystem", + "main": "std::filesystem::path p(\"./file\");", + "qmake": "CONFIG += c++17" + } + }, "eventfd": { "label": "eventfd", "type": "compile", @@ -613,6 +622,13 @@ "condition": "tests.cxx11_future", "output": [ "publicFeature" ] }, + "cxx17_filesystem": { + "label": "C++17 ", + "condition": "tests.cxx17_filesystem", + "output": [ + "publicFeature" + ] + }, "eventfd": { "label": "eventfd", "condition": "!config.wasm && tests.eventfd", diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index 4a8a4598a0a..57338644597 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -79,6 +79,7 @@ #define QT_FEATURE_cborstreamwriter 1 #define QT_CRYPTOGRAPHICHASH_ONLY_SHA1 #define QT_FEATURE_cxx11_random (__has_include() ? 1 : -1) +#define QT_FEATURE_cxx17_filesystem -1 #define QT_NO_DATASTREAM #define QT_FEATURE_datestring 1 #define QT_FEATURE_datetimeparser -1 diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index 60c75ead4db..5b10a4a6895 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/main.cpp @@ -44,11 +44,7 @@ #include "qfilesystemiterator.h" -#if QT_HAS_INCLUDE() && defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L -#define HAS_STD_FILESYSTEM -#endif - -#ifdef HAS_STD_FILESYSTEM +#if QT_CONFIG(cxx17_filesystem) #include #endif @@ -248,7 +244,7 @@ void tst_qdiriterator::fsiterator() void tst_qdiriterator::stdRecursiveDirectoryIterator() { -#ifdef HAS_STD_FILESYSTEM +#if QT_CONFIG(cxx17_filesystem) QFETCH(QByteArray, dirpath); int count = 0; diff --git a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro index 4b28946f18d..609a578321c 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro +++ b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro @@ -4,7 +4,11 @@ QT = core testlib CONFIG += release # Enable c++17 support for std::filesystem -qtConfig(c++1z): CONFIG += c++17 +qtConfig(cxx17_filesystem) { + CONFIG += c++17 + gcc:lessThan(QMAKE_GCC_MAJOR_VERSION, 9): \ + QMAKE_LFLAGS += -lstdc++fs +} SOURCES += main.cpp qfilesystemiterator.cpp HEADERS += qfilesystemiterator.h