Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable libepoxy to build with Visual Studio 2008-2012 #56

Closed
wants to merge 15 commits into from
Closed

Enable libepoxy to build with Visual Studio 2008-2012 #56

wants to merge 15 commits into from

Conversation

fanc999
Copy link
Contributor

@fanc999 fanc999 commented Jun 5, 2015

Hi,

As libepoxy is being used with GTK+-3.16.x and later, we would also like to ensure that Visual Studio 2008 and 2012 is supported as well. It turns out that there are very few changes that are needed to make that happen, once we have made the code work with Visual Studio 2013 (i.e. issue #55).

The first 4 commits are the ones that are needed to make the code work for Visual Studio 2013, which are 100% identical to the ones in issue #55:
-Public Headers: Allow Build On Visual Studio
-src/: Allow Build On Visual Studio
-src/gen_dispatch.py: MSVC 2013: Allow Generated Code To Build
-test/wgl_per_context_funcptrs.c: Fix Build on Visual Studio

Which I was not able to filter out from this issue though, sorry, as this work builds upon the work to make the code buildable with Visual Studio 2013.

With blessings, thank you!

Ensure that we also have import/export decorations for the prototypes, as
Visual Studio does not like such decorations on the function definitions
without the prototypes decorated as well, when the function prototypes
exist.
Allow the non-generated sources and headers to build on Visual Studio by:
-Defining a macro that is used to define the suitable constructor according
 to the compiler used, and use that macro when using constructors.
 The current state of the code is a GCCism using
 __attribute__((constructor)).

-Ensure that we use GLAPIENTRY and EPOXY_CALLSPEC after the return type,
 as Visual Studio does not like __stdcall before the return type, which is
 what GLAPIENTRY and EPOXY_CALLSPEC expands to on Windows.

-Ensure we have import/export annotations for functions prototypes and
 variables, since Visual Studio expects such annotations for function
 prototypes if they exist.  We are using EPOXY_IMPORTEXPORT for variables
 as we might try to reference variables, which must be imported by
 __declspec(dllimport) when used.

-Avoid using empty structs and arrays, as it is a C99 feature that is not
 supported (nor will it probably be at any point) on Visual Studio.
This updates the script to generate code that is buildable by Visual Studio
2013 by:

-Using a macro to define the compiler-specific way to do noinline for a
 function, and use it when needed.

-Avoid using empty arrays and structs as that is a C99 feature that will
 likely be never support on Visual Studio as it is now an optional feature
 of C11.
Ensure that we do __stdcall only after the return type, as Visual Studio
will not like it otherwise.
...so that the generated code are buildable by pre-2013 Visual Studio.  The
main thing that this does is that we avoid named initializers, but instead
initialize the structs in old-school C89 way.

The generated code may not look that robust, but since this is generated
code, I think this is not an issue; when the Khronos registry gets updated,
all that is needed is that the code gets re-generated, and we have the
items in the right order.

These are the only changes required, after getting the code to work with
Visual Studio 2013, for libepoxy to build with Visual Studio 2008-2012,
provided that the user finds a suitable implementation of stdint.h,
inttypes.h and stdbool.h.
Since the APIs are meant to be private, don't mark them for export, except
the epoxy_conservative_gl_version(), which was already marked for export in
dispatch_common.c, with PUBLIC.
...so that the build will not fail on Visual Studio builds as the function
definition for epoxy_conservative_gl_version() in src/dispatch_common.c is
already annotated with PUBLIC.  Again, Visual Studio requires that the
function prototype be annotated with dllexport/dllimport annotations when
the function definition is annotated, if the function prototype exists.
Don't mark epoxy_conservative_gl_version() for export, as it is meant to be
a private API to be used within libepoxy only.
@fanc999
Copy link
Contributor Author

fanc999 commented Jun 17, 2015

Hi,

For references, since I am not sure how one can filter out the commits that are also done in my other pull request (#55, "Allow Build on Visual Studio 2013"), as this depends on that pull request, the actual commit that makes the difference from that PR would be "src/gen_dispatch.py: Make Generated Code Build Under C89" (commit 440c7d3).

With blessings, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants