Build on Windows with Clang

::: {.warning} ::: {.title} Warning :::

This should be considered experimental and could be broken by future updates of Qt, MSVC, Clang, or seemingly unrelated changes in our own code. :::

Preparation

  • Download Clang binaries for Windows

    • Advice: do not install in the default directory (Program Files)
    • Ensure the bin subdirectory is added to PATH (recommend doing this manually)

Considerations

Things to be aware of:

  • On Linux, Clang tries to mimic GCC, supporting GNU extensions and GNU ABI. On Windows, Clang tries to mimic MSVC, supporting Microsoft extensions and Microsoft ABI.

  • You need to have installed Microsoft Visual C++, as Clang uses Microsoft's implementation of the C++ standard library.

  • The mkspec uses [clang-cl](http://clang.llvm.org/docs/UsersManual.html#clang-cl), which is a wrapper around clang.exe that understands MSVC commandline arguments like /LD, /W3, etc.

  • The following qmake scope test conditions are true when building with Clang on Windows:

    • win32
    • win32-clang-msvc
    • msvc
    • clang_cl
    • llvm
  • The following C++ macros are defined when building with Clang on Windows:

    : - Q_OS_WIN - Q_CC_MSVC - Q_CC_CLANG

Build with qmake and jom

Using the appropriate Visual Studio command prompt:

qmake -Wlogic -r -spec win32-clang-msvc path\to\swift.pro
jom

Build with Qt Creator

::: {.warning} ::: {.title} Warning :::

This does not seem to be working at the moment. (2018-12-01, Qt Creator 4.7.2) :::

Qt Creator should detect your installation of LLVM. If it does not, you can manually add it under the "Compilers" tab. Then create a new kit by cloning one of the existing "Qt Desktop MSVC2017" kits. Adjust the kit by selecting the appropriate Clang compiler from the drop-down list, and entering the Qt mkspec win32-clang-msvc. Finally, add the kit to your swift project in the Projects page, make it the active kit, and start a build.

image

Clang and MinGW

::: {.warning} ::: {.title} Warning :::

This is even more experimental than anything above! :::

It is also possible to build using Clang on MinGW by using the mkspec win32-clang-g++.

  • The following qmake scope test conditions will be true:

    • win32
    • win32-clang-g++
    • gcc
    • mingw
    • llvm
  • The following C++ macros will be defined:

    • Q_OS_WIN
    • Q_CC_GCC
    • Q_CC_CLANG
Last modified 28.06.2020: Add content (0e00ae5)