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 <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Brian Paul brianp@vmware.com
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19472>
This commit is contained in:
Yonggang Luo
2022-11-03 00:00:55 +08:00
committed by Marge Bot
parent afc3d5eff3
commit f40afd1363
2 changed files with 14 additions and 0 deletions
+3
View File
@@ -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;
+11
View File
@@ -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