Fixed typedef redefinition errors when including both SDL_vulkan.h and vulkan.h
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Aug 2017 23:13:15 -0700
changeset 1137691e5e5a2cb71
parent 11375 2dd1cac9e43a
child 11377 d91e89acb756
Fixed typedef redefinition errors when including both SDL_vulkan.h and vulkan.h
You should always include vulkan/vulkan.h first, then include SDL_vulkan.h
include/SDL.h
include/SDL_vulkan.h
src/dynapi/SDL_dynapi.c
src/video/SDL_sysvideo.h
src/video/SDL_vulkan_internal.h
test/testvulkan.c
     1.1 --- a/include/SDL.h	Sun Aug 27 22:36:03 2017 -0700
     1.2 +++ b/include/SDL.h	Sun Aug 27 23:13:15 2017 -0700
     1.3 @@ -40,10 +40,10 @@
     1.4  #include "SDL_error.h"
     1.5  #include "SDL_events.h"
     1.6  #include "SDL_filesystem.h"
     1.7 -#include "SDL_joystick.h"
     1.8  #include "SDL_gamecontroller.h"
     1.9  #include "SDL_haptic.h"
    1.10  #include "SDL_hints.h"
    1.11 +#include "SDL_joystick.h"
    1.12  #include "SDL_loadso.h"
    1.13  #include "SDL_log.h"
    1.14  #include "SDL_messagebox.h"
    1.15 @@ -51,12 +51,12 @@
    1.16  #include "SDL_power.h"
    1.17  #include "SDL_render.h"
    1.18  #include "SDL_rwops.h"
    1.19 +#include "SDL_shape.h"
    1.20  #include "SDL_system.h"
    1.21  #include "SDL_thread.h"
    1.22  #include "SDL_timer.h"
    1.23  #include "SDL_version.h"
    1.24  #include "SDL_video.h"
    1.25 -#include "SDL_vulkan.h"
    1.26  
    1.27  #include "begin_code.h"
    1.28  /* Set up for C function definitions, even when using C++ */
     2.1 --- a/include/SDL_vulkan.h	Sun Aug 27 22:36:03 2017 -0700
     2.2 +++ b/include/SDL_vulkan.h	Sun Aug 27 23:13:15 2017 -0700
     2.3 @@ -1,23 +1,23 @@
     2.4  /*
     2.5 - Simple DirectMedia Layer
     2.6 - Copyright (C) 2017, Mark Callow.
     2.7 - 
     2.8 - This software is provided 'as-is', without any express or implied
     2.9 - warranty.  In no event will the authors be held liable for any damages
    2.10 - arising from the use of this software.
    2.11 - 
    2.12 - Permission is granted to anyone to use this software for any purpose,
    2.13 - including commercial applications, and to alter it and redistribute it
    2.14 - freely, subject to the following restrictions:
    2.15 - 
    2.16 - 1. The origin of this software must not be misrepresented; you must not
    2.17 - claim that you wrote the original software. If you use this software
    2.18 - in a product, an acknowledgment in the product documentation would be
    2.19 - appreciated but is not required.
    2.20 - 2. Altered source versions must be plainly marked as such, and must not be
    2.21 - misrepresented as being the original software.
    2.22 - 3. This notice may not be removed or altered from any source distribution.
    2.23 - */
    2.24 +  Simple DirectMedia Layer
    2.25 +  Copyright (C) 2017, Mark Callow
    2.26 +
    2.27 +  This software is provided 'as-is', without any express or implied
    2.28 +  warranty.  In no event will the authors be held liable for any damages
    2.29 +  arising from the use of this software.
    2.30 +
    2.31 +  Permission is granted to anyone to use this software for any purpose,
    2.32 +  including commercial applications, and to alter it and redistribute it
    2.33 +  freely, subject to the following restrictions:
    2.34 +
    2.35 +  1. The origin of this software must not be misrepresented; you must not
    2.36 +     claim that you wrote the original software. If you use this software
    2.37 +     in a product, an acknowledgment in the product documentation would be
    2.38 +     appreciated but is not required.
    2.39 +  2. Altered source versions must be plainly marked as such, and must not be
    2.40 +     misrepresented as being the original software.
    2.41 +  3. This notice may not be removed or altered from any source distribution.
    2.42 +*/
    2.43  
    2.44  /**
    2.45   *  \file SDL_vulkan.h
    2.46 @@ -36,8 +36,11 @@
    2.47  extern "C" {
    2.48  #endif
    2.49  
    2.50 -/* Avoid including vulkan.h */
    2.51 -#ifndef VULKAN_H_
    2.52 +/* Avoid including vulkan.h, don't define VkInstance if it's already included */
    2.53 +#ifdef VULKAN_H_
    2.54 +#define NO_SDL_VULKAN_TYPEDEFS
    2.55 +#endif
    2.56 +#ifndef NO_SDL_VULKAN_TYPEDEFS
    2.57  #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
    2.58  
    2.59  #if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
    2.60 @@ -49,7 +52,7 @@
    2.61  VK_DEFINE_HANDLE(VkInstance)
    2.62  VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
    2.63  
    2.64 -#endif /* !VULKAN_H_ */
    2.65 +#endif /* !NO_SDL_VULKAN_TYPEDEFS */
    2.66  
    2.67  typedef VkInstance SDL_vulkanInstance;
    2.68  typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
     3.1 --- a/src/dynapi/SDL_dynapi.c	Sun Aug 27 22:36:03 2017 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi.c	Sun Aug 27 23:13:15 2017 -0700
     3.3 @@ -32,9 +32,9 @@
     3.4  
     3.5  #include "SDL.h"
     3.6  
     3.7 -/* !!! FIXME: Shouldn't these be included in SDL.h? */
     3.8 -#include "SDL_shape.h"
     3.9 +/* These headers have system specific definitions, so aren't included above */
    3.10  #include "SDL_syswm.h"
    3.11 +#include "SDL_vulkan.h"
    3.12  
    3.13  /* This is the version of the dynamic API. This doesn't match the SDL version
    3.14     and should not change until there's been a major revamp in API/ABI.
     4.1 --- a/src/video/SDL_sysvideo.h	Sun Aug 27 22:36:03 2017 -0700
     4.2 +++ b/src/video/SDL_sysvideo.h	Sun Aug 27 23:13:15 2017 -0700
     4.3 @@ -26,7 +26,8 @@
     4.4  #include "SDL_messagebox.h"
     4.5  #include "SDL_shape.h"
     4.6  #include "SDL_thread.h"
     4.7 -#include "SDL_vulkan.h"
     4.8 +
     4.9 +#include "SDL_vulkan_internal.h"
    4.10  
    4.11  /* The SDL video driver */
    4.12  
     5.1 --- a/src/video/SDL_vulkan_internal.h	Sun Aug 27 22:36:03 2017 -0700
     5.2 +++ b/src/video/SDL_vulkan_internal.h	Sun Aug 27 23:13:15 2017 -0700
     5.3 @@ -18,8 +18,8 @@
     5.4       misrepresented as being the original software.
     5.5    3. This notice may not be removed or altered from any source distribution.
     5.6  */
     5.7 -#ifndef _SDL_vulkan_internal_h
     5.8 -#define _SDL_vulkan_internal_h
     5.9 +#ifndef SDL_vulkan_internal_h_
    5.10 +#define SDL_vulkan_internal_h_
    5.11  
    5.12  #include "../SDL_internal.h"
    5.13  
    5.14 @@ -53,14 +53,13 @@
    5.15  #define VK_USE_PLATFORM_XCB_KHR
    5.16  #endif
    5.17  
    5.18 -#if SDL_VIDEO_VULKAN_SURFACE
    5.19 -
    5.20 -/* Need vulkan.h for the following declarations. Must ensure the first
    5.21 - * inclusion of vulkan has the appropriate USE_PLATFORM defined, hence
    5.22 - * the above. */
    5.23  #define VK_NO_PROTOTYPES
    5.24  #include "./khronos/vulkan/vulkan.h"
    5.25  
    5.26 +#include "SDL_vulkan.h"
    5.27 +
    5.28 +#if SDL_VIDEO_VULKAN_SURFACE
    5.29 +
    5.30  extern const char *SDL_Vulkan_GetResultString(VkResult result);
    5.31  
    5.32  extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
    5.33 @@ -73,8 +72,8 @@
    5.34                                                          const char **userNames,
    5.35                                                          unsigned nameCount,
    5.36                                                          const char *const *names);
    5.37 +#endif /* SDL_VIDEO_VULKAN_SURFACE */
    5.38  
    5.39 -#endif
    5.40 +#endif /* SDL_vulkan_internal_h_ */
    5.41  
    5.42 -#endif
    5.43  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/test/testvulkan.c	Sun Aug 27 22:36:03 2017 -0700
     6.2 +++ b/test/testvulkan.c	Sun Aug 27 23:13:15 2017 -0700
     6.3 @@ -33,6 +33,7 @@
     6.4  /* SDL includes a copy for building on systems without the Vulkan SDK */
     6.5  #include "../src/video/khronos/vulkan/vulkan.h"
     6.6  #endif
     6.7 +#include "SDL_vulkan.h"
     6.8  
     6.9  #ifndef UINT64_MAX /* VS2008 */
    6.10  #define UINT64_MAX 18446744073709551615