Skip to content

Allow builds on Windows using Visual Studio without Unix-like tools

Chun-wei Fan requested to merge msvc into main

Hi,

This MR attempts to add builds using Visual Studio and clang-cl with the bog-standard Visual Studio command prompt by doing the following:

Things done include:

  • Force-include msvc_recommended_pragmas.h when building with Visual Studio, that is supplied by GLib. It helps us to silence warnings from Visual Studio that we don't really need to bother about and also treat warnings that we should pay attention to as errors, since Visual Studio have a completely different set of compiler flags and semantics on dealing with compiler warnings.
  • Disable PIC/PIE on Visual Studio and clang-cl.
  • Redo gen-public-types.sh in Python. Unfortunately, Visual Studio does not ship with a *nix shell nor sed.exe, and they can be only obtained with a pretty hefty download via Cygwin or MSYS2.
  • Drop the g_auto*() usage, since sadly Visual Studio do not support them in some manner. Hopefully Microsoft will reconsider, but I don't believe that will be imminent.
  • Drop the portal and appstream items from Windows builds, since they don't (and most likely won't) work on Windows at all.
  • Other minor fixes for building and linking with Visual Studio.

I was able to build with Visual Studio 2015 or later with all the tests passing, except that -Dc_std=c99 must be passed in if building with Visual Studio prior to Visual Studio 2019 16.8.x.

This closes issue #357 (closed).

With blessings, thank you!

Edited by Chun-wei Fan

Merge request reports