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. Using a custom mkspec on macOS, and #ifdef blocks aren't being highlighted correctly in Qt Creator
Forum Updated to NodeBB v4.3 + New Features

Using a custom mkspec on macOS, and #ifdef blocks aren't being highlighted correctly in Qt Creator

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 1 Posters 432 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.
  • G Offline
    G Offline
    Guy Gizmo
    wrote on 28 Feb 2023, 16:42 last edited by
    #1

    I've made a mkspec for Qt 6.2.3 that makes use of a custom installation of clang 14 and a separate copy of the macOS SDK. The mkspec is intended to be the same as the standard macx-clang mkspec with just a few variables changed. It looks basically like this, which paths changed to placeholders:

    include(/path/to/qt/6.2.3/macos/mkspecs/macx-clang/qmake.conf)
    
    QMAKE_CC                          = /path/to/clang14/usr/bin/clang
    QMAKE_CXX                         = /path/to/clang14/usr/bin/clang++
    QMAKE_LINK                        = /path/to/clang14/usr/bin/clang++
    DSYMUTIL_PATH                     = /path/to/clang14/usr/bin/dsymutil
    
    QMAKE_MAC_SDK.macosx.Path         = /path/to/Xcode14.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
    QMAKE_MAC_SDK.macosx.PlatformPath = /path/to/Xcode14.app/Contents/Developer/Platforms/MacOSX.platform
    QMAKE_MAC_SDK.macosx.SDKVersion   = 12
    

    When I compile my projects with Qt 6.2.3 and this mkspec, everything works fine. However, in Qt Creator, it's acting as though certain precompiler definitions are not present, resulting in it acting like Q_OS_MAC is not defined and thus highlighting the wrong blocks when I use an #ifdef statement. This makes my code a lot harder to work with.

    I dug into this, and found that Qt Creator is acting as though none of the following preprocessor directives are defined, even though they definitely are when compiling: __GNUC__, __APPLE__, TARGET_OS_MAC, Q_OS_DARWIN, and Q_OS_MAC.

    Anyone know what's going wrong, and how to fix this?

    Things I've tried so far:

    I tried adding something like DEFINES += __GNUC__ __APPLE__ ... to my mkspec, but then I get lots of double definition warnings. Again: these are all defined when compiling, and compilation works just as it should. (If there were a qmake variable I could use that was like DEFINES but only applies to Qt Creator and not actual compilation then that would work.)

    I also tried using Qt Creator's "Additional C++ Preprocessor Directives" feature, but it doesn't work either. Adding __GNUC__, __APPLE__ or even Q_OS_MAC to it still doesn't result in correct highlighting of code in Qt Creator: adding them has no effect at all. But even if it did work, it's already an unacceptable solution to this problem, because I'd have to add these defines for all of the hundreds of files in my project, and I most certainly do not want to do that.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Guy Gizmo
      wrote on 3 Mar 2023, 15:29 last edited by
      #3

      Nevermind! I was looking in the wrong place for a solution this whole time. It turns out it was the kit I had set up in Qt Creator. The path for its compiler was incorrect. As soon as I fixed that, the #ifdef blocks were highlighted correctly. I had assumed the issue was with my mkspec because qmake doesn't use the compiler set up by Qt Creator.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Guy Gizmo
        wrote on 3 Mar 2023, 14:08 last edited by
        #2

        So far the only solution I've found is to add the following to the top of qglobal.h:

        #ifndef __GNUC__
        #define __GNUC__
        #endif
        
        #ifndef __APPLE__
        #define __APPLE__
        #endif
        
        #ifndef TARGET_OS_MAC
        #define TARGET_OS_MAC
        #endif
        

        Obviously modifying Qt's header files is not a great solution. I'm hoping there's a better way.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Guy Gizmo
          wrote on 3 Mar 2023, 15:29 last edited by
          #3

          Nevermind! I was looking in the wrong place for a solution this whole time. It turns out it was the kit I had set up in Qt Creator. The path for its compiler was incorrect. As soon as I fixed that, the #ifdef blocks were highlighted correctly. I had assumed the issue was with my mkspec because qmake doesn't use the compiler set up by Qt Creator.

          1 Reply Last reply
          1
          • G Guy Gizmo has marked this topic as solved on 3 Mar 2023, 15:29

          1/3

          28 Feb 2023, 16:42

          • Login

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