From b4fd377aa984defea63ecb8951c152872202146e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 7 May 2020 16:32:18 +0200 Subject: [PATCH] Make utf8_source the default for qmake builds We now assume that source code is encoded in UTF-8 by default on all platforms (and verify this with an auto test). Provide a CONFIG+=no_utf8_source option for backwards compatibility. [ChangeLog][qmake] qmake will tell the compiler that source code is encoded in utf-8 by default. This mainly has an effect on Windows, where MSVC still assumes source code is encoded in the current ANSI code page. Use CONFIG+=no_utf8_source to get back the Qt 5 behavior. Change-Id: I6dcafcaeefdea7d3907ccb723aeb7d23ccc0f04f Reviewed-by: Thiago Macieira --- mkspecs/features/default_post.prf | 2 +- qmake/doc/src/qmake-manual.qdoc | 4 ++-- tests/auto/other/compiler/tst_compiler.cpp | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mkspecs/features/default_post.prf b/mkspecs/features/default_post.prf index 9c73eeef69..b2985fe89c 100644 --- a/mkspecs/features/default_post.prf +++ b/mkspecs/features/default_post.prf @@ -166,7 +166,7 @@ c99|c11 { unset(cstd) } -utf8_source { +!no_utf8_source { QMAKE_CFLAGS += $$QMAKE_CFLAGS_UTF8_SOURCE QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_UTF8_SOURCE } diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc index 490d747f1b..16ed37c018 100644 --- a/qmake/doc/src/qmake-manual.qdoc +++ b/qmake/doc/src/qmake-manual.qdoc @@ -1147,8 +1147,8 @@ default is used. \row \li thread \li Thread support is enabled. This is enabled when CONFIG includes \c qt, which is the default. - \row \li utf8_source \li Specifies that the project's source files use the - UTF-8 encoding. By default, the compiler default is used. + \row \li no_utf8_source \li Specifies that the project's source files does not use + the UTF-8 encoding. Instead, the compiler default is used. \row \li hide_symbols \li Set the default visibility of symbols in the binary to hidden. By default, the compiler default is used. \row \li c99 \li C99 support is enabled. This option has no effect if diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp index 78026665be..4d19debd06 100644 --- a/tests/auto/other/compiler/tst_compiler.cpp +++ b/tests/auto/other/compiler/tst_compiler.cpp @@ -115,6 +115,9 @@ private slots: /* Future / Technical specification compiler features */ void runtimeArrays(); + + /* treat source code as utf-8 */ + void utf8source(); }; #if defined(Q_CC_HPACC) @@ -1551,5 +1554,18 @@ void tst_Compiler::runtimeArrays() #endif } + + +void tst_Compiler::utf8source() +{ + const char *str = "Ελληνικά"; + auto u16str = u"Ελληνικά"; + QCOMPARE(QString::fromUtf16(u16str), QString::fromUtf8(str)); + + const char *ae = "\xc3\x86"; + auto u16ae = u"Æ"; + QCOMPARE(QString::fromUtf16(u16ae), QString::fromUtf8(ae)); +} + QTEST_MAIN(tst_Compiler) #include "tst_compiler.moc"