Skip to content

Experimental clang-cl support

Chun-wei Fan requested to merge clang-cl-support into master


This adds preliminary support for building GLib with clang-cl, which is a variation of CLang/LLVM that tries to pretend itself as the MSVC compiler. This, as a result, updates the build system to assume that clang-cl is a msvc-style build for most things, but also has the advantage to enable g_autoptr.

This also updates the glib/gmacros.h header so that

-We use the GCC-style deprecation annotations, not MSVC-style, so that things won't break on clang-cl builds.

-Check for the __clang__ macro to enable the GCC- and CLang-only g_autoptr support, which can be used by clang-cl to build items that use it against the GTK stack that is built by real MSVC. Please note that clang-cl understandably does not define __GNUC__ but instead defines _MSC_VER.

This will depend on MR !980 (merged), as the updates in glib/gmacros.h there are needed for this to work and the updates there will make the GLib headers more usable even if building against a real MSVC-built GTK stack with clang-cl.

Note that this does depend on a recent Visual Studio and Microsoft Windows SDK (2017+) in order to work, so this is likely to be less well-supported than real MSVC, at least for a forseeable amount of time, meaning that this should be considered experimental.

For records, since we are requiring Meson 0.48.0, we couldn't use cc.get_argument_syntax, which looks cleaner. This will also depend on Meson to be updated to fix detection on strcasecmp(), strncasecmp() and stpcpy() on clang-cl (see

With blessings, thank you!

Edited by Philip Withnall

Merge request reports