Important: Please read the Qt Code of Conduct -

How to get same compiler flags with QMake and CMake?

  • We are switching over to using CMake for our projects and I noticed some slight compiler flag differences after switching. This is with MSVC 2019 x64. One difference is that UNICODE and _UNICODE are defined using a QMake project file but not with CMake (these defines are in Makefile.Release when using QMake). I think this is being set in the appropriate mkspec file, but would expect Qt's CMake files to add the same compiler flags/defines. Is there a way to ensure the same compiler flags when using CMake and QMake?

  • Lifetime Qt Champion

    Why do you need it? Do you have WinAPI calls in your source? I'm pretty sure it's added automatically, at least for MSVC.


  • @Christian-Ehrlicher Yes, we do have some WinAPI calls and the unicode-related defines weren't added when using MSVC with CMake. I know how to add definitions with CMake, but I would expect anything that is automatically defined by default by Qt with a QMake project file to be automatically defined by default when using CMake and find_package(Qt5Core REQUIRED).

  • Lifetime Qt Champion

    Why? It's not needed to use Qt and only added by qmake due to backwards compatibility concerns or due to the fact that noone removed it during Qt5 porting.

  • My concern was more with any other compiler flags that I don't know about and not specifically the unicode defines which are just an example.

  • Lifetime Qt Champion

    Since these are two different build systems there are for sure different flags. If you need a specific flag you have to make sure it's there for both build systems. Both can create a running Qt application.

Log in to reply