Merge pull request #609 from asuessenbach/windows

Add some workarounds to not include windows.h on _WIN32 platform.
This commit is contained in:
Andreas Süßenbach 2020-05-14 11:58:58 +02:00 committed by GitHub
commit ae3460a715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 36 deletions

View File

@ -1404,6 +1404,15 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str )
{ {
str += R"( str += R"(
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL #if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
# if defined( _WIN32 )
namespace detail
{
extern "C" __declspec( dllimport ) void * __stdcall LoadLibraryA( char const * lpLibFileName );
extern "C" __declspec( dllimport ) int __stdcall FreeLibrary( void * hLibModule );
extern "C" __declspec( dllimport ) void * __stdcall GetProcAddress( void * hModule, char const * lpProcName );
} // namespace detail
# endif
class DynamicLoader class DynamicLoader
{ {
public: public:
@ -1418,9 +1427,9 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str )
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL ); m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
m_library = LoadLibrary( vulkanLibraryName.c_str() ); m_library = detail::LoadLibraryA( vulkanLibraryName.c_str() );
# else # else
VULKAN_HPP_ASSERT( false && "unsupported platform" ); # error unsupported platform
# endif # endif
} }
else else
@ -1434,9 +1443,9 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str )
# elif defined( __APPLE__ ) # elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL ); m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
m_library = LoadLibrary( TEXT( "vulkan-1.dll" ) ); m_library = detail::LoadLibraryA( "vulkan-1.dll" );
# else # else
VULKAN_HPP_ASSERT( false && "unsupported platform" ); # error unsupported platform
# endif # endif
} }
@ -1472,35 +1481,37 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str )
{ {
if ( m_library ) if ( m_library )
{ {
#if defined(__linux__) || defined(__APPLE__) # if defined( __linux__ ) || defined( __APPLE__ )
dlclose( m_library ); dlclose( m_library );
#elif defined(_WIN32) # elif defined( _WIN32 )
FreeLibrary( m_library ); detail::FreeLibrary( m_library );
#endif # else
# error unsupported platform
# endif
} }
} }
template <typename T> template <typename T>
T getProcAddress( const char* function ) const VULKAN_HPP_NOEXCEPT T getProcAddress( const char* function ) const VULKAN_HPP_NOEXCEPT
{ {
#if defined(__linux__) || defined(__APPLE__) # if defined( __linux__ ) || defined( __APPLE__ )
return (T)dlsym( m_library, function ); return (T)dlsym( m_library, function );
#elif defined(_WIN32) # elif defined( _WIN32 )
return (T)GetProcAddress( m_library, function ); return (T)detail::GetProcAddress( m_library, function );
#endif # else
# error unsupported platform
# endif
} }
bool success() const VULKAN_HPP_NOEXCEPT { return m_success; } bool success() const VULKAN_HPP_NOEXCEPT { return m_success; }
private: private:
bool m_success; bool m_success;
#if defined(__linux__) || defined(__APPLE__) # if defined( __linux__ ) || defined( __APPLE__ ) || defined( _WIN32 )
void *m_library; void * m_library;
#elif defined(_WIN32) # else
HMODULE m_library; # error unsupported platform
#else # endif
#error unsupported platform
#endif
}; };
#endif #endif
@ -7811,10 +7822,6 @@ int main( int argc, char ** argv )
# if defined(__linux__) || defined(__APPLE__) # if defined(__linux__) || defined(__APPLE__)
# include <dlfcn.h> # include <dlfcn.h>
# endif # endif
# if defined(_WIN32)
# include <windows.h>
# endif
#endif #endif
#if 201711 <= __cpp_impl_three_way_comparison #if 201711 <= __cpp_impl_three_way_comparison

View File

@ -69,10 +69,6 @@
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ )
# include <dlfcn.h> # include <dlfcn.h>
# endif # endif
# if defined( _WIN32 )
# include <windows.h>
# endif
#endif #endif
#if 201711 <= __cpp_impl_three_way_comparison #if 201711 <= __cpp_impl_three_way_comparison
@ -96704,6 +96700,15 @@ namespace VULKAN_HPP_NAMESPACE
}; };
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL #if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
# if defined( _WIN32 )
namespace detail
{
extern "C" __declspec( dllimport ) void * __stdcall LoadLibraryA( char const * lpLibFileName );
extern "C" __declspec( dllimport ) int __stdcall FreeLibrary( void * hLibModule );
extern "C" __declspec( dllimport ) void * __stdcall GetProcAddress( void * hModule, char const * lpProcName );
} // namespace detail
# endif
class DynamicLoader class DynamicLoader
{ {
public: public:
@ -96718,9 +96723,9 @@ namespace VULKAN_HPP_NAMESPACE
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ )
m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL ); m_library = dlopen( vulkanLibraryName.c_str(), RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
m_library = LoadLibrary( vulkanLibraryName.c_str() ); m_library = detail::LoadLibraryA( vulkanLibraryName.c_str() );
# else # else
VULKAN_HPP_ASSERT( false && "unsupported platform" ); # error unsupported platform
# endif # endif
} }
else else
@ -96734,9 +96739,9 @@ namespace VULKAN_HPP_NAMESPACE
# elif defined( __APPLE__ ) # elif defined( __APPLE__ )
m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL ); m_library = dlopen( "libvulkan.dylib", RTLD_NOW | RTLD_LOCAL );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
m_library = LoadLibrary( TEXT( "vulkan-1.dll" ) ); m_library = detail::LoadLibraryA( "vulkan-1.dll" );
# else # else
VULKAN_HPP_ASSERT( false && "unsupported platform" ); # error unsupported platform
# endif # endif
} }
@ -96776,7 +96781,9 @@ namespace VULKAN_HPP_NAMESPACE
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ )
dlclose( m_library ); dlclose( m_library );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
FreeLibrary( m_library ); detail::FreeLibrary( m_library );
# else
# error unsupported platform
# endif # endif
} }
} }
@ -96787,7 +96794,9 @@ namespace VULKAN_HPP_NAMESPACE
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ )
return (T)dlsym( m_library, function ); return (T)dlsym( m_library, function );
# elif defined( _WIN32 ) # elif defined( _WIN32 )
return (T)GetProcAddress( m_library, function ); return (T)detail::GetProcAddress( m_library, function );
# else
# error unsupported platform
# endif # endif
} }
@ -96798,10 +96807,8 @@ namespace VULKAN_HPP_NAMESPACE
private: private:
bool m_success; bool m_success;
# if defined( __linux__ ) || defined( __APPLE__ ) # if defined( __linux__ ) || defined( __APPLE__ ) || defined( _WIN32 )
void * m_library; void * m_library;
# elif defined( _WIN32 )
HMODULE m_library;
# else # else
# error unsupported platform # error unsupported platform
# endif # endif