Skip to content

Commit

Permalink
Automated platform detection using predefined macro's
Browse files Browse the repository at this point in the history
  • Loading branch information
Isho312 authored and LovelySanta committed Oct 5, 2019
1 parent 52ff54c commit 033af46
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
59 changes: 51 additions & 8 deletions Hazel/src/Hazel/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,62 @@

#include <memory>

#ifdef HZ_PLATFORM_WINDOWS
#if HZ_DYNAMIC_LINK
#ifdef HZ_BUILD_DLL
#define HAZEL_API __declspec(dllexport)
// Platform detection using predefined macros
#ifdef _WIN32
/* Windows x64/x86 */
#ifdef _WIN64
/* Windows x64 */
#define HZ_PLATFORM_WINDOWS
#else
/* Windows x86 */
#error "x86 Builds are not supported!"
#endif
#elif defined(__APPLE__) || defined(__MACH__)
#include <TargetConditionals.h>
/* TARGET_OS_MAC exists on all the platforms
* so we must check all of them (in this order)
* to ensure that we're running on MAC
* and not some other Apple platform */
#if TARGET_IPHONE_SIMULATOR == 1
#error "IOS simulator is not supported!"
#elif TARGET_OS_IPHONE == 1
#define HZ_PLATFORM_IOS
#error "IOS is not supported!"
#elif TARGET_OS_MAC == 1
#define HZ_PLATFORM_MACOS
#error "MacOS is not supported!"
#else
#define HAZEL_API __declspec(dllimport)
#error "Unknown Apple platform!"
#endif
/* We also have to check __ANDROID__ before __linux__
* since android is based on the linux kernel
* it has __linux__ defined */
#elif defined(__ANDROID__)
#define HZ_PLATFORM_ANDROID
#error "Android is not supported!"
#elif defined(__linux__)
#define HZ_PLATFORM_LINUX
#error "Linux is not supported!"
#else
#define HAZEL_API
#endif
/* Unknown compiler/platform */
#error "Unknown platform!"
#endif // End of platform detection


// DLL support
#ifdef HZ_PLATFORM_WINDOWS
#if HZ_DYNAMIC_LINK
#ifdef HZ_BUILD_DLL
#define HAZEL_API __declspec(dllexport)
#else
#define HAZEL_API __declspec(dllimport)
#endif
#else
#define HAZEL_API
#endif
#else
#error Hazel only supports Windows!
#endif
#endif // End of DLL support

#ifdef HZ_DEBUG
#define HZ_ENABLE_ASSERTS
Expand Down
8 changes: 1 addition & 7 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ project "Hazel"

defines
{
"HZ_PLATFORM_WINDOWS",
"HZ_BUILD_DLL",
"GLFW_INCLUDE_NONE"
}
Expand Down Expand Up @@ -134,12 +133,7 @@ project "Sandbox"

filter "system:windows"
systemversion "latest"

defines
{
"HZ_PLATFORM_WINDOWS"
}


filter "configurations:Debug"
defines "HZ_DEBUG"
runtime "Debug"
Expand Down

0 comments on commit 033af46

Please sign in to comment.