OK, here's what you do to build an out-of-source Qt on Windows with VS 2022:
0 - Download the Qt 5 source distribution and unzip it where you want it to be.
1 - Open a Visual Studio command prompt window. (Start Menu: Programs -> Visual Studio 2022 -> Visual Studio Tools -> Developer Command Prompt)
2 - CD to your Qt5 "src" directory, then go up one level.
3 - At this level, create a "build" directory and CD to it
4 - Run "..\src\configure -opensource" and reply "y" to the prompt when asked to accept the open source terms.
5 - When this completes, run "nmake" from within the build directory. It will take an hour or more to build Qt.
6 - Optionally, run "nmake install" after this finishes. By default, this will install the binaries to a directory under C:\Qt. There is probably a configure option to change this location; check the Qt documentation.
If you get an error when running the configure script:
"msvc-version.conf loaded but QMAKE_MSC_VER isn't set"
then open the file in the src\qtbase\mkspecs\common\msvc-version.conf and add this line at the top of the file (above where you will see the error message):
QMAKE_MSC_VER = 1920
QMAKE_MSC_VER = 1920
To copy to clipboard, switch view to plain text mode
(This is for my Qt 5.14.2 distribution. A later Qt5 distribution could have support for Visual Studio 2022 already - look towards the bottom of this file for the last entry of the form below that has something like this:
greaterThan(QMAKE_MSC_VER, 1909) {
# Visual Studio 2017 (15.0) / Visual C++ 19.10 and up
MSVC_VER = 15.0
COMPAT_MKSPEC = win32-msvc2017
QMAKE_CXXFLAGS += -Zc:referenceBinding
# Only Visual Studio 2017 version 15.3 / Visual C++ 19.11 & up have support
# for AVX-512. We enable the switches anyway and let configure check if they
# work.
QMAKE_CFLAGS_AVX512F = -arch:AVX512
QMAKE_CFLAGS_AVX512ER = -arch:AVX512
QMAKE_CFLAGS_AVX512CD = -arch:AVX512
QMAKE_CFLAGS_AVX512PF = -arch:AVX512
QMAKE_CFLAGS_AVX512DQ = -arch:AVX512
QMAKE_CFLAGS_AVX512BW = -arch:AVX512
QMAKE_CFLAGS_AVX512VL = -arch:AVX512
QMAKE_CFLAGS_AVX512IFMA = -arch:AVX512
QMAKE_CFLAGS_AVX512VBMI = -arch:AVX512
# For now permissive fails as soon as UWP API comes into play. In qtbase this
# API is used in direct2d, but also in multimedia, positioning and sensors.
# We can try again with a later version of Visual Studio.
# QMAKE_CXXFLAGS_STRICTCXX = -permissive-
# MSVC partially supports the following, but '__cplusplus' definition is set
# as for C++98 until MSVC fully conforms with C++14, see
# https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
# Support became available in MSVC 2017 15.7:
greaterThan(QMAKE_MSC_VER, 1913) {
QMAKE_CXXFLAGS += -Zc:__cplusplus
QMAKE_CXXFLAGS_CXX14 = -std:c++14
QMAKE_CXXFLAGS_CXX1Z = -std:c++17
}
}
greaterThan(QMAKE_MSC_VER, 1909) {
# Visual Studio 2017 (15.0) / Visual C++ 19.10 and up
MSVC_VER = 15.0
COMPAT_MKSPEC = win32-msvc2017
QMAKE_CXXFLAGS += -Zc:referenceBinding
# Only Visual Studio 2017 version 15.3 / Visual C++ 19.11 & up have support
# for AVX-512. We enable the switches anyway and let configure check if they
# work.
QMAKE_CFLAGS_AVX512F = -arch:AVX512
QMAKE_CFLAGS_AVX512ER = -arch:AVX512
QMAKE_CFLAGS_AVX512CD = -arch:AVX512
QMAKE_CFLAGS_AVX512PF = -arch:AVX512
QMAKE_CFLAGS_AVX512DQ = -arch:AVX512
QMAKE_CFLAGS_AVX512BW = -arch:AVX512
QMAKE_CFLAGS_AVX512VL = -arch:AVX512
QMAKE_CFLAGS_AVX512IFMA = -arch:AVX512
QMAKE_CFLAGS_AVX512VBMI = -arch:AVX512
# For now permissive fails as soon as UWP API comes into play. In qtbase this
# API is used in direct2d, but also in multimedia, positioning and sensors.
# We can try again with a later version of Visual Studio.
# QMAKE_CXXFLAGS_STRICTCXX = -permissive-
# MSVC partially supports the following, but '__cplusplus' definition is set
# as for C++98 until MSVC fully conforms with C++14, see
# https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
# Support became available in MSVC 2017 15.7:
greaterThan(QMAKE_MSC_VER, 1913) {
QMAKE_CXXFLAGS += -Zc:__cplusplus
QMAKE_CXXFLAGS_CXX14 = -std:c++14
QMAKE_CXXFLAGS_CXX1Z = -std:c++17
}
}
To copy to clipboard, switch view to plain text mode
In my case (Qt 5.14.2), the last entry is the above, with an entry after that that references the VS 2019 version and modifies a couple of the variables defined above:
greaterThan(QMAKE_MSC_VER, 1919) {
# Visual Studio 2019 (16.0) / Visual C++ 19.20 and up
MSVC_VER = 16.0
QMAKE_CXXFLAGS_CXX2A = -std:c++latest
}
greaterThan(QMAKE_MSC_VER, 1919) {
# Visual Studio 2019 (16.0) / Visual C++ 19.20 and up
MSVC_VER = 16.0
QMAKE_CXXFLAGS_CXX2A = -std:c++latest
}
To copy to clipboard, switch view to plain text mode
Setting QMAKE_MSVC_VER to 1920 will ensure that at least the VS 2019 compiler will be used with the latest C++ version.
Bookmarks