stop defining geode platform macros in 4 different places

This commit is contained in:
HJfod 2022-10-09 21:04:10 +03:00
parent e7f82381a1
commit 75918681ab
8 changed files with 34 additions and 226 deletions
loader
include/Geode
lilac

View file

@ -4,7 +4,7 @@
#include "callconv.hpp"
#include "common.hpp"
#include "function.hpp"
#include "preproc.hpp"
#include "../platform/platform.hpp"
#include "defaultconv.hpp"
namespace geode::core::meta {}

View file

@ -1,73 +0,0 @@
#ifndef GEODE_CORE_META_PREPROC_HPP
#define GEODE_CORE_META_PREPROC_HPP
#if !defined(GEODE_CALL)
// Windows
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define GEODE_WINDOWS(...) __VA_ARGS__
#define GEODE_IS_WINDOWS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "Windows"
#define GEODE_PLATFORM_TARGET PlatformID::Windows
#define GEODE_CALL __stdcall
#define GEODE_PLATFORM_EXTENSION ".dll"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "win"
#else
#define GEODE_WINDOWS(...)
#endif
// Darwin
#if defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define GEODE_MACOS(...)
#define GEODE_IOS(...) __VA_ARGS__
#define GEODE_IS_IOS
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "iOS"
#define GEODE_PLATFORM_TARGET PlatformID::iOS
#define GEODE_PLATFORM_EXTENSION ".ios.dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "ios"
#else
#define GEODE_IOS(...)
#define GEODE_MACOS(...) __VA_ARGS__
#define GEODE_IS_MACOS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "MacOS"
#define GEODE_PLATFORM_TARGET PlatformID::MacOS
#define GEODE_PLATFORM_EXTENSION ".dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "mac"
#endif
#define GEODE_CALL
#else
#define GEODE_MACOS(...)
#define GEODE_IOS(...)
#endif
// Android
#if defined(__ANDROID__)
#define GEODE_ANDROID(...) __VA_ARGS__
#define GEODE_IS_ANDROID
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "Android"
#define GEODE_PLATFORM_TARGET PlatformID::Android
#define GEODE_CALL
#define GEODE_PLATFORM_EXTENSION ".so"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "android"
#else
#define GEODE_ANDROID(...)
#endif
#ifndef GEODE_PLATFORM_NAME
#error "Unsupported PlatformID!"
#endif
#ifdef GEODE_EXPORTING
#define GEODE_DLL GEODE_WINDOWS(__declspec(dllexport))
#else
#define GEODE_DLL GEODE_WINDOWS(__declspec(dllimport))
#endif
#define GEODE_API GEODE_WINDOWS() // idk where this is
#endif
#endif /* GEODE_CORE_META_PREPROC_HPP */

View file

@ -1,10 +1,7 @@
#pragma once
#include <functional>
#if defined(GEODE_CALL)
#undef GEODE_CALL
#endif
#include "cplatform.h"
namespace geode {
class PlatformID {
@ -70,20 +67,13 @@ namespace std {
#endif
// Windows
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#ifdef GEODE_IS_WINDOWS
#define GEODE_WINDOWS(...) __VA_ARGS__
#define GEODE_IS_WINDOWS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "Windows"
#define GEODE_PLATFORM_TARGET PlatformID::Windows
#define GEODE_CALL __stdcall
#define GEODE_HIDDEN
#define GEODE_DUPABLE __forceinline
#define GEODE_VIRTUAL_CONSTEXPR
#define GEODE_NOINLINE __declspec(noinline)
#define GEODE_PLATFORM_EXTENSION ".dll"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "win"
#ifdef GEODE_EXPORTING
#define GEODE_DLL __declspec(dllexport)
@ -96,56 +86,13 @@ namespace std {
#include "windows.hpp"
#else
#define GEODE_WINDOWS(...)
#endif
#elif defined(GEODE_IS_MACOS)
// MacOS / iOS
#if defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define GEODE_MACOS(...)
#define GEODE_IOS(...) __VA_ARGS__
#define GEODE_IS_IOS
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "iOS"
#define GEODE_PLATFORM_TARGET PlatformID::iOS
#define GEODE_CALL
#define GEODE_HIDDEN __attribute__((visibility("hidden")))
#define GEODE_DUPABLE __attribute__((always_inline))
#define GEODE_VIRTUAL_CONSTEXPR constexpr
#define GEODE_NOINLINE __attribute__((noinline))
#define GEODE_PLATFORM_EXTENSION ".ios.dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "ios"
#ifdef GEODE_EXPORTING
#define GEODE_DLL __attribute__((visibility("default")))
#else
#define GEODE_DLL
#endif
#define GEODE_API extern "C" __attribute__((visibility("default")))
#define GEODE_EXPORT __attribute__((visibility("default")))
#include "ios.hpp"
#else
#define GEODE_IOS(...)
#define GEODE_MACOS(...) __VA_ARGS__
#define GEODE_IS_MACOS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "MacOS"
#define GEODE_PLATFORM_TARGET PlatformID::MacOS
#define GEODE_CALL
#define GEODE_HIDDEN __attribute__((visibility("hidden")))
#define GEODE_DUPABLE __attribute__((always_inline))
#define GEODE_VIRTUAL_CONSTEXPR constexpr
#define GEODE_NOINLINE __attribute__((noinline))
#define GEODE_PLATFORM_EXTENSION ".dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "mac"
#ifdef GEODE_EXPORTING
#define GEODE_DLL __attribute__((visibility("default")))
@ -157,28 +104,33 @@ namespace std {
#define GEODE_EXPORT __attribute__((visibility("default")))
#include "macos.hpp"
#endif
#else
#define GEODE_IOS(...)
#define GEODE_MACOS(...)
#elif defined(GEODE_IS_IOS)
#endif
// Android
#if defined(__ANDROID__)
#define GEODE_ANDROID(...) __VA_ARGS__
#define GEODE_IS_ANDROID
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "Android"
#define GEODE_PLATFORM_TARGET PlatformID::Android
#define GEODE_CALL
#define GEODE_PLATFORM_TARGET PlatformID::iOS
#define GEODE_HIDDEN __attribute__((visibility("hidden")))
#define GEODE_DUPABLE __attribute__((always_inline))
#define GEODE_VIRTUAL_CONSTEXPR constexpr
#define GEODE_NOINLINE __attribute__((noinline))
#ifdef GEODE_EXPORTING
#define GEODE_DLL __attribute__((visibility("default")))
#else
#define GEODE_DLL
#endif
#define GEODE_API extern "C" __attribute__((visibility("default")))
#define GEODE_EXPORT __attribute__((visibility("default")))
#include "ios.hpp"
#elif defined(GEODE_IS_ANDROID)
#define GEODE_PLATFORM_TARGET PlatformID::Android
#define GEODE_HIDDEN __attribute__((visibility("hidden")))
#define GEODE_DUPABLE __attribute__((always_inline))
#define GEODE_VIRTUAL_CONSTEXPR constexpr
#define GEODE_NOINLINE __attribute__((noinline))
#define GEODE_PLATFORM_EXTENSION ".so"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "android"
#ifdef GEODE_EXPORTING
#define GEODE_DLL __attribute__((visibility("default")))
@ -189,12 +141,10 @@ namespace std {
#define GEODE_API extern "C" __attribute__((visibility("default")))
#define GEODE_EXPORT __attribute__((visibility("default")))
#include "windows.hpp"
#include "android.hpp"
#else
#define GEODE_ANDROID(...)
#endif
#ifndef GEODE_PLATFORM_NAME
#error "Unsupported PlatformID!"
#error "Unsupported Platform!"
#endif

View file

@ -11,9 +11,12 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_subdirectory("test")
endif()
message(STATUS ${GEODE_LOADER_PATH}/include)
target_include_directories(
lilac_hook INTERFACE
${lilac_SOURCE_DIR}/include/geode
${lilac_SOURCE_DIR}/include/geode/core
${lilac_SOURCE_DIR}/include/geode/core/hook
${GEODE_LOADER_PATH}/include
)

View file

@ -1,7 +1,7 @@
#ifndef GEODE_CORE_HOOK_HPP
#define GEODE_CORE_HOOK_HPP
#include "../meta/preproc.hpp"
#include <Geode/platform/platform.hpp>
#include <cstddef>

View file

@ -5,7 +5,7 @@
#include "common.hpp"
#include "function.hpp"
#include "hook.hpp"
#include "preproc.hpp"
#include <Geode/platform/platform.hpp>
#if defined(LILAC_IS_WINDOWS)
#include "cdecl.hpp"

View file

@ -1,73 +0,0 @@
#ifndef LILAC_CORE_META_PREPROC_HPP
#define LILAC_CORE_META_PREPROC_HPP
#if !defined(GEODE_CALL)
// Windows
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define GEODE_WINDOWS(...) __VA_ARGS__
#define GEODE_IS_WINDOWS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "Windows"
#define GEODE_PLATFORM_TARGET PlatformID::Windows
#define GEODE_CALL __stdcall
#define GEODE_PLATFORM_EXTENSION ".dll"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "win"
#else
#define GEODE_WINDOWS(...)
#endif
// Darwin
#if defined(__APPLE__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define GEODE_MACOS(...)
#define GEODE_IOS(...) __VA_ARGS__
#define GEODE_IS_IOS
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "iOS"
#define GEODE_PLATFORM_TARGET PlatformID::iOS
#define GEODE_PLATFORM_EXTENSION ".ios.dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "ios"
#else
#define GEODE_IOS(...)
#define GEODE_MACOS(...) __VA_ARGS__
#define GEODE_IS_MACOS
#define GEODE_IS_DESKTOP
#define GEODE_PLATFORM_NAME "MacOS"
#define GEODE_PLATFORM_TARGET PlatformID::MacOS
#define GEODE_PLATFORM_EXTENSION ".dylib"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "mac"
#endif
#define GEODE_CALL
#else
#define GEODE_MACOS(...)
#define GEODE_IOS(...)
#endif
// Android
#if defined(__ANDROID__)
#define GEODE_ANDROID(...) __VA_ARGS__
#define GEODE_IS_ANDROID
#define GEODE_IS_MOBILE
#define GEODE_PLATFORM_NAME "Android"
#define GEODE_PLATFORM_TARGET PlatformID::Android
#define GEODE_CALL
#define GEODE_PLATFORM_EXTENSION ".so"
#define GEODE_PLATFORM_SHORT_IDENTIFIER "android"
#else
#define GEODE_ANDROID(...)
#endif
#ifndef GEODE_PLATFORM_NAME
#error "Unsupported PlatformID!"
#endif
#ifdef GEODE_EXPORTING
#define GEODE_DLL GEODE_WINDOWS(__declspec(dllexport))
#else
#define GEODE_DLL GEODE_WINDOWS(__declspec(dllimport))
#endif
#define GEODE_API GEODE_WINDOWS() // idk where this is
#endif
#endif /* LILAC_CORE_META_PREPROC_HPP */

View file

@ -30,6 +30,7 @@ target_compile_features(lilac_hook PUBLIC cxx_std_17)
target_include_directories(lilac_hook
PRIVATE
${lilac_SOURCE_DIR}/include/geode/core/hook
${GEODE_LOADER_PATH}/include
INTERFACE
$<BUILD_INTERFACE:${lilac_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${lilac_SOURCE_DIR}/include/geode>