Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to get same compiler flags with QMake and CMake?
Forum Updated to NodeBB v4.3 + New Features

How to get same compiler flags with QMake and CMake?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 2 Posters 966 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mchinand
    wrote on 2 Jan 2020, 15:15 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 2 Jan 2020, 16:25 last edited by
      #2

      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.

      set(_FLAGS_C " /DUNICODE /D_UNICODE")
      set(_FLAGS_CXX " /DUNICODE /D_UNICODE")
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply 2 Jan 2020, 16:39
      2
      • C Christian Ehrlicher
        2 Jan 2020, 16:25

        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.

        set(_FLAGS_C " /DUNICODE /D_UNICODE")
        set(_FLAGS_CXX " /DUNICODE /D_UNICODE")
        
        M Offline
        M Offline
        mchinand
        wrote on 2 Jan 2020, 16:39 last edited by
        #3

        @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).

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 2 Jan 2020, 16:41 last edited by
          #4

          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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mchinand
            wrote on 2 Jan 2020, 17:01 last edited by
            #5

            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.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 2 Jan 2020, 17:34 last edited by
              #6

              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.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1

              1/6

              2 Jan 2020, 15:15

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved