14

I've tried this condition, but it doesn't work. How to check for MSVC 2013?

win32-msvc2013*{
    QMAKE_CXXFLAGS += /FS
}

I'm using Qt 5.3 Beta which has msvc-2013 mkspec.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335

5 Answers5

17

Sorry for necroposting, but there seems no googleable solution. Seems I found one. There is vcvars.bat file, which is used for setting correct environment variables for VC. QtCreator, for example, use it while setting Tools -> Options -> Build & Run -> Compilers. Also it is used for MSVC Command Promt. Let`s check "VisualStudioVersion" env var in qmake (14.0 for MSVS 2015 in my case):

win32-msvc* {
    MSVC_VER = $$(VisualStudioVersion)
    equals(MSVC_VER, 14.0){
        message("msvc 2015")
    }
}
anatoly
  • 186
  • 1
  • 2
7

Try this way:

win32-msvc* {
    system(cl|grep "Compiler Version 18.") {
        message( "msvc 2013 detected" )
        QMAKE_CXXFLAGS += /FS
    }
}

http://qt-project.org/doc/qt-4.8/qmake-function-reference.html

Can't test it I don't have Windows machine now.

Marek R
  • 32,568
  • 6
  • 55
  • 140
  • Hm. Somehow the message is printed, but `/FS` is not added. How's that possible?.. If I write `QMAKE_CXXFLAGS += /FS` unconditionally, it is added. – Violet Giraffe Apr 30 '14 at 08:39
  • And sometimes when I run `qmake` I get "grep is not recognized as an external or internal command". Which is probably because Windows doesn't have `grep`. But sometimes it works. Very weird. – Violet Giraffe Apr 30 '14 at 08:41
  • you can try modify this solution by trying find another way to detect contents of standard output of `cl`. `grep` is natural way and it is present in widows for a long time, so ti is very strange that it doesn't works sometimes. – Marek R Apr 30 '14 at 09:12
  • 1
    There is no grep on windows, so this is not a good way to do this. Using $$(VisualStudioVersion) is a better solution. – Bill Hoffman Mar 08 '16 at 19:16
  • `find` is Winodws equivalent of `grep`. Anyway `$$(VisualStudioVersion)` is something new. – Marek R Mar 08 '16 at 22:23
5

I use following:

contains(QMAKE_COMPILER_DEFINES, _MSC_VER=1800) { 
# MSVS2013
}
Andrey
  • 927
  • 11
  • 12
1

Check supported platforms and table of Reference Configurations. There is no msvc2013! Newest visual studio supported is 2012.

So when detecting visual studio do not enforce 2013 sufix. Just use approach shown here

Community
  • 1
  • 1
Marek R
  • 32,568
  • 6
  • 55
  • 140
0

found simple and elegant solution:

win32-msvc*: {
    COMPIL = $$find(CONFIG, "^win32-msvc*")
    COMPIL = $$replace(COMPIL,win32-,) # 'win32-msvc2017' -> 'msvc2017'
}

Edit: this only works with Qt 5.9.0 and later. Only then configs win32-msvc2012/win32-msvc2013/etc. are merged into single win32-msvc

Andrei R.
  • 2,374
  • 1
  • 13
  • 27