Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89951

Why does Qt 6 cmake add `UNICODE` to public definitions on Windows?

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.1.0 Alpha
    • 6.0.0, 6.1.0
    • Build System: CMake
    • None
    • Windows
    • 8b7894cb637d21d8fa9bd129849cd23462632d28 (qt/qtbase/dev) 55522636e302e1a5780b7af72272375d1f588615 (qt/tqtc-qtbase/6.1.1) 5b64e5950cf984abb7d47e0802bcb4b5a21e06fa (qt/tqtc-qtbase/6.2)

    Description

      I've used Qt 4.x and 5.x for basically forever, mostly with cmake. The official cmake integration did not set the define `UNICODE` on Windows, or at least I never encountered it. Since switching to Qt 6.0.0, there is a public, transitive definition of `UNICODE` (and `_UNICODE`) when linking against Qt. Sadly, this breaks some of our code.

      The definition is added in cmake/QtBuild.cmake

      # Platform define path, etc.
      if(WIN32)
          set(QT_DEFAULT_PLATFORM_DEFINITIONS UNICODE _UNICODE WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE)
          if(CMAKE_SIZEOF_VOID_P EQUAL 8)
              list(APPEND QT_DEFAULT_PLATFORM_DEFINITIONS WIN64 _WIN64)
      

      I've googled for why building against Qt may require defining `UNICODE` and/or `_UNICODE`. From what I've found this seems to be mostly done for historic reasons, dating back all the way to Qt 4.x?

      I can understand if Qt wants to keep this define for historic reasons. But if its indeed not strictly required, it would be great if this could be configured at build time.

      On a related note, in recent times even Microsoft promoted the use of UTF8 in some of its build environments. I think many developers may want to move away from UNICODE unless strictly required.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              semlanik Alexey Edelev
              emmenlau Mario Emmenlauer
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews