[Cogl] [1.18][Patch]: Update cogl-sdl.h to avoid linking to the SDL libraries for Cogl-based applications

Fan Chun-wei fanc999 at yahoo.com.tw
Thu Mar 6 04:28:48 PST 2014


Hi,

I have updated this patch as it seems the more correct way of avoiding 
having to link to SDLmain.lib and SDL.lib for Cogl builds with SDL 
support is to define SDL_MAIN_HANDLED before including the SDL headers. 
So here it comes-or maybe if people still want to use SDL's main() 
implementation, perhaps we could use a macro to define SDL_MAIN_HANDLED 
conditionally or so. Please let me know which seems better for uses in Cogl.

With blessings, thank you!

於 2014/2/27 19:27, Fan Chun-wei 提到:
> Hi,
>
> Currently, on MSVC builds, applications built against Cogl builds with 
> SDL support enabled will incur a dependency on the SDL/SDL2 DLL, which 
> is not optimal as those applications may well be not really needing 
> SDL directly. This updates the cogl-sdl.h header so that it will undef 
> main on Windows after the SDL headers are included, so that SDL's 
> special main() will not be needed, eliminating the need to link to the 
> SDLmain (and therefore the SDL DLL). Applications needing SDL 
> functionality and Cogl can then link to SDL as needed.
>
> With blessings, thanks for the reviews!
>
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


-------------- next part --------------
From 9b3b8ac5f40218701a947308ef3af864dc1b827b Mon Sep 17 00:00:00 2001
From: Chun-wei Fan <fanchunwei at src.gnome.org>
Date: Thu, 6 Mar 2014 20:24:42 +0800
Subject: [PATCH] cogl/cogl.h: Avoid Linking to SDLmain on Windows

This defines the SDL_MAIN_HANDLED macro before including the SDL headers so
that SDL's custom main function will not be used, so that it will not be
necessary to link to the SDLmain (and hence SDL) libraries.

The advantage to this approach is that applications based on Cogl (and
therefore Clutter) will not have a implicit dependency on the SDL/SDL2
DLL, unless Cogl itself is built and linked against SDL.
---
 cogl/cogl-sdl.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/cogl/cogl-sdl.h b/cogl/cogl-sdl.h
index 220e004..c3a8fa0 100644
--- a/cogl/cogl-sdl.h
+++ b/cogl/cogl-sdl.h
@@ -50,17 +50,17 @@
 
 #include <cogl/cogl-context.h>
 #include <cogl/cogl-onscreen.h>
-#include <SDL.h>
 
-#ifdef _MSC_VER
-/* We need to link to SDL.lib/SDLmain.lib
- * if we are using Cogl
- * that uses the SDL winsys
- */
-#pragma comment (lib, "SDL.lib")
-#pragma comment (lib, "SDLmain.lib")
+#ifdef COGL_HAS_WIN32_SUPPORT
+/* Avoid the necessity of linking to the SDL libraries, as
+ * it adds an implicit run-time depenency for Cogl-based
+ * apps on the SDL DLLs */
+
+#define SDL_MAIN_HANDLED 1
 #endif
 
+#include <SDL.h>
+
 COGL_BEGIN_DECLS
 
 /**
-- 
1.8.3.msysgit.0


More information about the Cogl mailing list