GNOME Bugzilla – Bug 753271
Allow Build of glibmm 2.45.x+ on Visual Studio
Last modified: 2015-09-09 11:36:58 UTC
Hi, Recently, glibmm has been updated to support only compilers that supports C++11 sufficiently well, which also means that the code needs to be built on Visual Studio 2013 or later, with some catches: -There is a use of __attribute((warn_unused_result)) which is a GNUism. -Only since Visual Studio 2015 is noexcept supported. I will attach patches so that Visual Studio builds continue to be supported shortly. With blessings.
Created attachment 308765 [details] [review] Define Macros to Allow Build on Visual Studio, in particular Visual Studio 2013 and later Hi, This adds macro definitions in glibmmconfig.h.in so that we can build under non-GCC (for __attribute__((warn_unused_result))) and pre-Visual Studio-2015 (for noexcept)...
Created attachment 308766 [details] [review] refptr.h: Avoid GNUism Hi, This avoids the GNUism in refptr.h by making use of the macros in the previous patch...
Created attachment 308767 [details] [review] glibmm: Allow Build and Use on Visual Studio 2013 Hi, Visual Studio 2013 supports everything else in the code, with the exception of noexcept. This uses the macro in glibmmconfig.h.in so that we can use the _NOEXCEPT macro that does more or less the same thing on Visual Studio 2013, so that builds on it can be fixed. This is supported in Visual Studio 2015, but that was released officially just a couple of weeks ago. With blessings, thank you!
Review of attachment 308766 [details] [review]: ::: glib/glibmm/refptr.h @@ +148,3 @@ * @return an underlying instance. */ + inline GLIBMM_WARN_UNUSED_RESULT T_CppObject* release(); This bug is going to be fixed in bug 752812.
Do you know if Visual Studio 2013 accepts static_assert and variadic templates? There are open bugs with patches that require those C++11 features. Glibmm bug 583399 (static_assert), gtkmm bug 134161 (variadic template).
Hi Kjell, As far as I could tell from MSDN, static_assert is supported since version 2012 and variadic templates since version 2013. With blessings, thank you!
The GNUism __attribute__((warn_unused_result)) has been replaced by the glib macro G_GNUC_WARN_UNUSED_RESULT. See https://git.gnome.org/browse/glibmm/commit/?id=d94115843f38967b5e883f5f7d8057882ae364cb
noexcept has been added in many places by now, not only in glibmm. Instead of adding #if !defined (_MSC_VER) || (_MSC_VER >= 1900) #define GLIBMM_NOEXCEPT noexcept #else #define GLIBMM_NOEXCEPT _NOEXCEPT #endif in glibmmconfig.h.in, and replacing all noexcept by GLIBMM_NOEXCEPT, it would be easier to just add #if defined (_MSC_VER) && (_MSC_VER < 1900) #define noexcept _NOEXCEPT #endif Do you think that would work with Visual Studio 2013?
Hi Kjell, I think that would also do. With bleeding, thank you!
Created attachment 310236 [details] [review] patch: glibmmconfig.h.in: Define noexcept macro for MSVC Does this small patch alone make it possible to build glibmm with Visual Studio 2013? Note that refptr.h now contains G_GNUC_WARN_UNUSED_RESULT instead of __attribute((warn_unused_result)). Note also that lots of files now contain noexcept, not only the 6 files in the patch in comment 3. gmmproc generates code with noexcept in it.
Review of attachment 310236 [details] [review]: Hi Kjell, ::: glib/glibmmconfig.h.in @@ -138,2 +138,4 @@ #endif /* GLIBMM_DLL */ +#if defined(_MSC_VER) && (_MSC_VER < 1900) + /* MSVC before MSVC 2015 does not support the noexcept keyword. */ Sorry, I forgot about the part why I initially tried to use GLIBMM_NOEXCEPT: MSVC does not allow us to define items that are known keywords, including noexcept, unless we do #define _ALLOW_KEYWORD_MACROS 1 before doing so. Just out of curiosity, does glibmm always gets to include sigc++config.h before using noexcept? With blessings, thank you!
Created attachment 310469 [details] [review] patch: glibmmconfig.h.in: Define noexcept macro for MSVC Hi Kjell, This is the updated patch for glibmmconfig.h.in so that we can have noexcept defined properly for Visual Studio 2013...
Created attachment 310470 [details] [review] glibmm: Enable non-generated Sources to build on Visual Studio 2013 Hi, The timer.cc and random.cc "static" sources in glibmm is not including enough of the headers in glibmm, so that there will be strange errors (C3646) on the use of _NOEXCEPT. The way to fix this is to just include glibmm.h in these source files, as in this patch. With blessings, thank you!
Review of attachment 310469 [details] [review]: This is yet another patch that only affects compilation with MSVC. I suppose you can push it without asking. You seem to know much more about MSVC than Murray and me. I don't know how much Murray has permitted you to modify without asking. > Just out of curiosity, does glibmm always get to include sigc++config.h before using noexcept? No, there's no guarantee. But many glibmm files include sigc++ files that include sigc++config.h.
Review of attachment 310470 [details] [review]: This fix seems quite harmless. If it's enough to add #include <glibmmconfig.h> before #include <glibmm/random.h> #include <glibmm/timer.h> that would be preferable. (Not including much more than necessary) But the patch is ok as it is, if for some reason adding glibmmconfig.h is not enough.
Hi Kjell, Thanks for the reviews, the patches were pushed as: -Attachment 310469 [details]: 4e7bc1a -Attachment 310470 [details]: f98a6d3 (In reply to Kjell Ahlstedt from comment #16) > If it's enough to add > #include <glibmmconfig.h> > before > #include <glibmm/random.h> > #include <glibmm/timer.h> > that would be preferable. I would have liked to do that as well, but no, it was not enough for some reason... With blessings, thank you!
The change in timer.cc breaks the build if G_DISABLE_DEPRECATED is defined. I've fixed that. https://git.gnome.org/browse/glibmm/commit/?id=0f734c6f0a93d79e882b6e30abf37f6a78989381