fixed RC files encoding on Windows 🙌🎆

Use utf8 on MinGW and ANSI with msvc.

The core of the problem is in the $$cat() and write_file() qmake
functions they don't know process UTF-8 encoded files, they use
the ANSI encoding.
This commit is contained in:
silverqx
2022-05-05 10:31:29 +02:00
parent b196e7b756
commit 2f455f7f4a
11 changed files with 50 additions and 223 deletions
@@ -53,6 +53,9 @@ ${TINY_UNPARSED_ARGUMENTS}")
set(tiny_manifest_basename ${rcBasename})
# CMake doesn't have problem with UTF-8 encoded files
set(pragma_codepage "65001")
# Start configuring
configure_file(
"${TINY_RESOURCES_DIR}/${rcBasename}.rc.in"
+11 -6
View File
@@ -55,12 +55,7 @@ defineReplace(tiny_configure_cmake_rc) {
defined(3, var):!isEmpty(3): rcBasename = $$3
else: rcBasename = $$TARGET
# This solved problem with the © character, problem with the encoding
# MinGW
win32-g++|win32-clang-g++: \
rcFile = $$absolute_path($$1/$${rcBasename}.rc.in)
else: \
rcFile = $$absolute_path($$1/$${rcBasename}.nopragma.rc.in)
rcFile = $$absolute_path($$1/$${rcBasename}.rc.in)
exists(rcFile) {
error( "Windows RC file $$rcFile does not exists, the path passed to the\
@@ -81,6 +76,15 @@ defineReplace(tiny_configure_cmake_rc) {
defined(4, var):!isEmpty(4): token = $$4
else: token = $$rcBasename
# This solves the problem with the © character, problem with the encoding
# Use utf8 on MinGW and ANSI with msvc
# The core of the problem is in the $$cat() and write_file() qmake functions they
# don't know process UTF-8 encoded files, they use the ANSI encoding.
win32-g++|win32-clang-g++: \
pragmaCodepage = 65001
else: \
pragmaCodepage = DEFAULT
rcFileContent = $$cat($$rcFile, blob)
# Support OriginalFilename in the Windows RC file
@@ -91,6 +95,7 @@ defineReplace(tiny_configure_cmake_rc) {
rcFileContent ~= s/@tiny_manifest_basename@/$$tiny_manifest_basename
rcFileContent ~= s/\\$<TARGET_FILE_NAME:$$TARGET>/$$basename(QMAKE_RESOLVED_TARGET)
rcFileContent ~= s/\\$<TARGET_FILE_SUFFIX:$$TARGET>/$$2
rcFileContent ~= s/@pragma_codepage@/$$pragmaCodepage
!write_file($$rcFilepath, rcFileContent) {
error( "Can not write to the file $${rcFilepath}." )
-55
View File
@@ -1,55 +0,0 @@
//#pragma code_page(65001) // UTF-8
IDI_ICON1 ICON "icons/@TinyOrm_target@.ico"
#include <windows.h>
#include "orm/version.hpp"
#define VER_FILEVERSION TINYORM_VERSION_MAJOR,TINYORM_VERSION_MINOR,TINYORM_VERSION_BUGFIX,TINYORM_VERSION_BUILD
#define VER_FILEVERSION_STR TINYORM_FILEVERSION_STR "\0"
#define VER_PRODUCTVERSION TINYORM_VERSION_MAJOR,TINYORM_VERSION_MINOR,TINYORM_VERSION_BUGFIX,TINYORM_VERSION_BUILD
#define VER_PRODUCTVERSION_STR TINYORM_VERSION_STR "\0"
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyOrm_target@>\0"
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VER_DEBUG
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Crystal Studio\0"
VALUE "FileDescription", "TinyORM user-friendly ORM\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "TinyOrm\0"
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
VALUE "ProductName", "TinyORM\0"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/* End of Version info */
#ifdef __MINGW32__
ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "@TinyOrm_target@$<TARGET_FILE_SUFFIX:@TinyOrm_target@>.manifest"
#endif
+2 -2
View File
@@ -1,4 +1,4 @@
#pragma code_page(65001) // UTF-8
#pragma code_page(@pragma_codepage@) // DEFAULT on Windows and UTF-8 with msvc
IDI_ICON1 ICON "icons/@TinyOrm_target@.ico"
@@ -36,7 +36,7 @@ VS_VERSION_INFO VERSIONINFO
VALUE "FileDescription", "TinyORM user-friendly ORM\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "TinyOrm\0"
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
VALUE "LegalCopyright", "Copyright (©) 2022 Crystal Studio\0"
VALUE "ProductName", "TinyORM\0"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
@@ -1,55 +0,0 @@
//#pragma code_page(65001) // UTF-8
//IDI_ICON1 ICON "icons/@TinyUtils_target@.ico"
#include <windows.h>
#include "version.hpp"
#define VER_FILEVERSION TINYUTILS_VERSION_MAJOR,TINYUTILS_VERSION_MINOR,TINYUTILS_VERSION_BUGFIX,TINYUTILS_VERSION_BUILD
#define VER_FILEVERSION_STR TINYUTILS_FILEVERSION_STR "\0"
#define VER_PRODUCTVERSION TINYUTILS_VERSION_MAJOR,TINYUTILS_VERSION_MINOR,TINYUTILS_VERSION_BUGFIX,TINYUTILS_VERSION_BUILD
#define VER_PRODUCTVERSION_STR TINYUTILS_VERSION_STR "\0"
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyUtils_target@>\0"
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VER_DEBUG
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Crystal Studio\0"
VALUE "FileDescription", "Utils library for TinyORM tests\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "TinyUtils\0"
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
VALUE "ProductName", "TinyUtils\0"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/* End of Version info */
#ifdef __MINGW32__
ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "@TinyUtils_target@$<TARGET_FILE_SUFFIX:@TinyUtils_target@>.manifest"
#endif
+2 -2
View File
@@ -1,4 +1,4 @@
#pragma code_page(65001) // UTF-8
#pragma code_page(@pragma_codepage@) // DEFAULT on Windows and UTF-8 with msvc
//IDI_ICON1 ICON "icons/@TinyUtils_target@.ico"
@@ -36,7 +36,7 @@ VS_VERSION_INFO VERSIONINFO
VALUE "FileDescription", "Utils library for TinyORM tests\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "TinyUtils\0"
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
VALUE "LegalCopyright", "Copyright (©) 2022 Crystal Studio\0"
VALUE "ProductName", "TinyUtils\0"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
@@ -60,6 +60,8 @@ private:
const QString productVersion;
/*! FileVersion. */
const QString fileVersion;
/*! LegalCopyright. */
const QString copyright;
};
/*! Obtain a ProductVersion and FileVersion strings from an exe/dll. */
@@ -67,6 +69,12 @@ private:
#endif
};
namespace
{
// All executables has the same LegalCopyright
inline const auto CopyRight = QStringLiteral("Copyright (©) 2022 Crystal Studio");
}
void tst_Version::versions_TinyOrm() const
{
// Test types
@@ -191,6 +199,7 @@ void tst_Version::checkFileVersion_TinyOrm() const
QCOMPARE(fileVersions.productVersion, versionStr);
QCOMPARE(fileVersions.fileVersion, fileVersions.productVersion);
QCOMPARE(fileVersions.copyright, CopyRight);
#endif
}
@@ -212,6 +221,7 @@ void tst_Version::checkFileVersion_TinyUtils() const
QCOMPARE(fileVersions.productVersion, versionStr);
QCOMPARE(fileVersions.fileVersion, fileVersions.productVersion);
QCOMPARE(fileVersions.copyright, CopyRight);
#endif
}
@@ -234,6 +244,7 @@ void tst_Version::checkFileVersion_TomExample() const
QCOMPARE(fileVersions.productVersion, versionStr);
QCOMPARE(fileVersions.fileVersion, fileVersions.productVersion);
QCOMPARE(fileVersions.copyright, CopyRight);
#endif
}
#endif
@@ -259,14 +270,29 @@ tst_Version::getExeVersionString(const QString &fileName) const
return {};
}
// Get the copyright
LPTSTR copyrightPtr = nullptr;
UINT uLen = 0;
if (!VerQueryValue(lpData.get(), LR"(\StringFileInfo\040904b0\LegalCopyright)",
reinterpret_cast<LPVOID *>(&copyrightPtr), &uLen)
) {
qWarning() << "Error in VerQueryValue() for the LegalCopyright.";
return {};
}
// -1 to exclude null character
auto copyright = QString::fromWCharArray(copyrightPtr,
static_cast<QString::size_type>(uLen) - 1);
// VerQueryValue
VS_FIXEDFILEINFO *lpBuffer = nullptr;
UINT uLen = 0;
uLen = 0;
if (!VerQueryValue(lpData.get(), QString("\\").toStdWString().c_str(),
reinterpret_cast<LPVOID *>(&lpBuffer), &uLen)
) {
qWarning() << "Error in VerQueryValue().";
qWarning() << "Error in VerQueryValue() for the version-information resource.";
return {};
}
@@ -283,6 +309,8 @@ tst_Version::getExeVersionString(const QString &fileName) const
.arg(LOWORD(lpBuffer->dwFileVersionMS))
.arg(HIWORD(lpBuffer->dwFileVersionLS))
.arg(LOWORD(lpBuffer->dwFileVersionLS)),
// LegalCopyright
std::move(copyright)
};
}
#endif
-44
View File
@@ -1,44 +0,0 @@
//#pragma code_page(65001) // UTF-8
//IDI_ICON1 ICON "icons/@TinyTest_icon@.ico"
#include <windows.h>
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TinyTest_target@>\0"
#ifdef TINYORM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
FILEFLAGSMASK VER_DEBUG
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Crystal Studio\0"
VALUE "FileDescription", "@TinyTest_target@ QtTest for TinyORM\0"
VALUE "InternalName", "@TinyTest_target@\0"
VALUE "LegalCopyright", "Copyright (©) 2021 Crystal Studio\0"
VALUE "ProductName", "@TinyTest_target@ QtTest\0"
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/* End of Version info */
#ifdef __MINGW32__
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "@tiny_manifest_basename@$<TARGET_FILE_SUFFIX:@TinyTest_target@>.manifest"
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma code_page(65001) // UTF-8
#pragma code_page(@pragma_codepage@) // DEFAULT on Windows and UTF-8 with msvc
//IDI_ICON1 ICON "icons/@TinyTest_icon@.ico"
-55
View File
@@ -1,55 +0,0 @@
//#pragma code_page(65001) // UTF-8
//IDI_ICON1 ICON "icons/@TomExample_target@.ico"
#include <windows.h>
#include "tom/version.hpp"
#define VER_FILEVERSION TINYTOM_VERSION_MAJOR,TINYTOM_VERSION_MINOR,TINYTOM_VERSION_BUGFIX,TINYTOM_VERSION_BUILD
#define VER_FILEVERSION_STR TINYTOM_FILEVERSION_STR "\0"
#define VER_PRODUCTVERSION TINYTOM_VERSION_MAJOR,TINYTOM_VERSION_MINOR,TINYTOM_VERSION_BUGFIX,TINYTOM_VERSION_BUILD
#define VER_PRODUCTVERSION_STR TINYTOM_VERSION_STR "\0"
#define VER_ORIGINALFILENAME_STR "$<TARGET_FILE_NAME:@TomExample_target@>\0"
#ifdef TINYTOM_NO_DEBUG
# define VER_DEBUG 0
#else
# define VER_DEBUG VS_FF_DEBUG
#endif
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VER_DEBUG
FILEFLAGS VER_DEBUG
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Crystal Studio\0"
VALUE "FileDescription", "Tom console for TinyORM\0"
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", "tom console\0"
VALUE "LegalCopyright", "Copyright (©) 2022 Crystal Studio\0"
VALUE "ProductName", "tom\0"
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/* End of Version info */
#ifdef __MINGW32__
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "@TomExample_target@$<TARGET_FILE_SUFFIX:@TomExample_target@>.manifest"
#endif
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma code_page(65001) // UTF-8
#pragma code_page(@pragma_codepage@) // DEFAULT on Windows and UTF-8 with msvc
//IDI_ICON1 ICON "icons/@TomExample_target@.ico"