Solved How to differentiate between VS2017/2019 and older Visual Studio versions in qmake .pro file?
-
According to https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160 the
/permissive-
flag is only supported since VS2017. I wanted to use that compiler flag for my project, but only if it is compiled with VS2017 or later. I am using Qt 5.15.1. I tried usingwin32-msvc2017 | win32-msvc2019 { QMAKE_CXXFLAGS += /permissive- }
but that fails, because there are no
win32-msvc2017
norwin32-msvc2019
in the mkspecs directory of my Qt 5.15.1 install. There is only awin32-msvc
directory. How can I specify that the/permissive-
flag should only be used when compiling my project with VS2017 or later? -
You can try the (undocumented) variable QMAKE_MSC_VER (see mkspecs\common\msvc-version.conf)
-
@Christian-Ehrlicher said in How to differentiate between VS2017/2019 and older Visual Studio versions in qmake .pro file?:
You can try the (undocumented) variable QMAKE_MSC_VER (see mkspecs\common\msvc-version.conf)
To specify that I only want to use the
/permissive-
flag from VS2017 on and later, I just triedgreaterThan(QMAKE_MSC_VER, 1900) { QMAKE_CXXFLAGS += /permissive- }
which is similar to the code in
mkspecs\common\msvc-version.conf
and that seems to work:DEBUG 2: evaluating joined expression DEBUG 2: new string DEBUG 2: literal "QMAKE_MSC_VER" DEBUG 2: evaluated expression => QMAKE_MSC_VER DEBUG 2: evaluating joined expression DEBUG 2: new string DEBUG 2: literal "1900" DEBUG 2: evaluated expression => QMAKE_MSC_VER 1900 DEBUG 1: D:/blablabla.pri:83: calling built-in greaterThan(QMAKE_MSC_VER, 1900) DEBUG 1: D:/blablabla.pri.pri:83: test function returned true DEBUG 1: D:/blablabla.pri.pri:83: taking 'then' branch DEBUG 1: D:/blablabla.pri.pri:83: entering block
Thanks!