After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 753271 - Allow Build of glibmm 2.45.x+ on Visual Studio
Allow Build of glibmm 2.45.x+ on Visual Studio
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: build
unspecified
Other Windows
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2015-08-05 07:00 UTC by Fan, Chun-wei
Modified: 2015-09-09 11:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Define Macros to Allow Build on Visual Studio, in particular Visual Studio 2013 and later (1.25 KB, patch)
2015-08-05 07:03 UTC, Fan, Chun-wei
none Details | Review
refptr.h: Avoid GNUism (1.02 KB, patch)
2015-08-05 07:04 UTC, Fan, Chun-wei
none Details | Review
glibmm: Allow Build and Use on Visual Studio 2013 (3.08 KB, patch)
2015-08-05 07:06 UTC, Fan, Chun-wei
none Details | Review
patch: glibmmconfig.h.in: Define noexcept macro for MSVC (810 bytes, patch)
2015-08-29 08:16 UTC, Kjell Ahlstedt
none Details | Review
patch: glibmmconfig.h.in: Define noexcept macro for MSVC (1.29 KB, patch)
2015-09-02 08:22 UTC, Fan, Chun-wei
committed Details | Review
glibmm: Enable non-generated Sources to build on Visual Studio 2013 (1.09 KB, patch)
2015-09-02 08:30 UTC, Fan, Chun-wei
committed Details | Review

Description Fan, Chun-wei 2015-08-05 07:00:40 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.
Comment 1 Fan, Chun-wei 2015-08-05 07:03:04 UTC
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)...
Comment 2 Fan, Chun-wei 2015-08-05 07:04:07 UTC
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...
Comment 3 Fan, Chun-wei 2015-08-05 07:06:26 UTC
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!
Comment 4 Marcin Kolny (IRC: loganek) 2015-08-05 08:30:20 UTC
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.
Comment 5 Marcin Kolny (IRC: loganek) 2015-08-05 08:30:21 UTC
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.
Comment 6 Kjell Ahlstedt 2015-08-05 18:21:27 UTC
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).
Comment 7 Fan, Chun-wei 2015-08-05 21:53:57 UTC
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!
Comment 8 Kjell Ahlstedt 2015-08-12 17:42:01 UTC
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
Comment 9 Kjell Ahlstedt 2015-08-28 07:13:21 UTC
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?
Comment 10 Fan, Chun-wei 2015-08-28 14:13:49 UTC
Hi Kjell,

I think that would also do.

With bleeding, thank you!
Comment 11 Kjell Ahlstedt 2015-08-29 08:16:18 UTC
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.
Comment 12 Fan, Chun-wei 2015-09-02 05:11:08 UTC
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!
Comment 13 Fan, Chun-wei 2015-09-02 08:22:28 UTC
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...
Comment 14 Fan, Chun-wei 2015-09-02 08:30:29 UTC
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!
Comment 15 Kjell Ahlstedt 2015-09-06 14:59:45 UTC
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.
Comment 16 Kjell Ahlstedt 2015-09-06 15:09:16 UTC
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.
Comment 17 Fan, Chun-wei 2015-09-09 09:11:10 UTC
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!
Comment 18 Kjell Ahlstedt 2015-09-09 11:36:58 UTC
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