Module: Mesa
Branch: main
Commit: f40afd1363f9eb586b8d8de59af16683beaf1692
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f40afd1363f9eb586b8d8de59af16683beaf1692

Author: Yonggang Luo <[email protected]>
Date:   Thu Nov  3 00:00:55 2022 +0800

util: Prevent glheader.h from including <windows.h> by defining APIENTRY

When APIENTRY is not defined, GL/gl.h and GL/glext.h will automatically
include <windows.h>, so we save the macro APIENTRY by push_macro and then
define APIENTRY before include of GL/gl.h and GL/glext.h.
After that we use pop_macro to recover the previous macro again.

Because windows.h is not included by glheader.h, mesa/main/errors.c needs
to include <windows.h> directly to prevent the following error:
errors.c:98:10: error: implicit declaration of function 'OutputDebugStringA' 
[-Werror=implicit-function-declaration]
   98 |          OutputDebugStringA(buf);

Signed-off-by: Yonggang Luo <[email protected]>
Reviewed-by: Jesse Natalie <[email protected]>
Acked-by: Brian Paul [email protected]
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19472>

---

 src/mesa/main/errors.c   |  3 +++
 src/mesa/main/glheader.h | 11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 938b6e7c4a3..cf057430928 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -41,6 +41,9 @@
 #if DETECT_OS_ANDROID
 #  include <log/log.h>
 #endif
+#if DETECT_OS_WINDOWS
+#  include <windows.h>
+#endif
 
 static FILE *LogFile = NULL;
 
diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h
index cf17f1ecd50..bf24f6f30d0 100644
--- a/src/mesa/main/glheader.h
+++ b/src/mesa/main/glheader.h
@@ -34,8 +34,19 @@
 
 
 #define GL_GLEXT_PROTOTYPES
+#if defined(_WIN32) && !defined(__CYGWIN__)
+/* Prevent glheader.h from including <windows.h> by defining APIENTRY */
+#pragma push_macro("APIENTRY")
+#ifndef APIENTRY
+#define APIENTRY GLAPIENTRY
+#endif
+#include "GL/gl.h"
+#include "GL/glext.h"
+#pragma pop_macro("APIENTRY")
+#else /* !(defined(_WIN32) && !defined(__CYGWIN__)) */
 #include "GL/gl.h"
 #include "GL/glext.h"
+#endif /* defined(_WIN32) && !defined(__CYGWIN__) */
 
 
 #ifdef __cplusplus

Reply via email to