From b000f0a0e15b1779bd3a189f7d3febd6a8605528 Mon Sep 17 00:00:00 2001 From: Waterdish Date: Tue, 7 Nov 2023 15:38:31 -0800 Subject: [PATCH 1/3] Android support --- ZAPD/CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++++++++- ZAPD/CrashHandler.cpp | 6 +++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ZAPD/CMakeLists.txt b/ZAPD/CMakeLists.txt index 96c42d0..fdd37dd 100644 --- a/ZAPD/CMakeLists.txt +++ b/ZAPD/CMakeLists.txt @@ -332,7 +332,34 @@ endif() if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(CMAKE_FIND_FRAMEWORK LAST) endif() -find_package(PNG REQUIRED) + +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(CMAKE_FIND_FRAMEWORK LAST) +endif() + +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android") + find_package(PNG REQUIRED) +endif() + +################################################################################ +# Find/download PNG for Android +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "Android") + find_package(PNG QUIET) + if (NOT ${PNG_FOUND}) + include(FetchContent) + FetchContent_Declare( + png + GIT_REPOSITORY https://github.com/glennrp/libpng.git + GIT_TAG v1.6.37 + ) + message("PNG not found. Downloading now...") + FetchContent_MakeAvailable(png) + message("PNG downloaded to " ${FETCHCONTENT_BASE_DIR}/png-src) + set (PNG_PNG_INCLUDE_DIR ${png_BINARY_DIR} ${png_SOURCE_DIR}) + endif() +endif() + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../libultraship/extern/ZAPDUtils @@ -476,6 +503,17 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS") "libultraship;" PNG::PNG ) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "ZAPDUtils;" + -Wl,--whole-archive $/$ -Wl,--no-whole-archive + "libultraship;" + png + ${CMAKE_DL_LIBS} + Threads::Threads + ) else() set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp index 3568665..fb4cd30 100644 --- a/ZAPD/CrashHandler.cpp +++ b/ZAPD/CrashHandler.cpp @@ -50,7 +50,7 @@ static std::array crashEasterEgg = { "\tOh! MY GOD!!", }; -#if HAS_POSIX == 1 +#if HAS_POSIX == 1 && !defined(__ANDROID__) void ErrorHandler(int sig) { std::array arr; @@ -193,12 +193,12 @@ LONG seh_filter(_EXCEPTION_POINTERS* ex) void CrashHandler_Init() { -#if HAS_POSIX == 1 +#if HAS_POSIX == 1 && !defined(__ANDROID__) signal(SIGSEGV, ErrorHandler); signal(SIGABRT, ErrorHandler); #elif defined(_MSC_VER) SetUnhandledExceptionFilter(seh_filter); -#else +#elif !defined(__ANDROID__) HANDLE_WARNING(WarningType::Always, "tried to set error handler, but this ZAPD build lacks support for one", ""); #endif From 34fdcb042377d50457e4263ec9f407b7fda166c2 Mon Sep 17 00:00:00 2001 From: Waterdish Date: Sat, 18 Nov 2023 10:53:01 -0800 Subject: [PATCH 2/3] Fix Warning Include --- ZAPD/CrashHandler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp index fb4cd30..36230fc 100644 --- a/ZAPD/CrashHandler.cpp +++ b/ZAPD/CrashHandler.cpp @@ -1,7 +1,7 @@ #include "CrashHandler.h" #include "Utils/StringHelper.h" -#if __has_include() +#if __has_include() && !defined(__ANDROID__) #define HAS_POSIX 1 #else #define HAS_POSIX 0 @@ -25,6 +25,8 @@ #include #pragma comment(lib, "Dbghelp.lib") +#else +#include "WarningHandler.h" #endif // Feel free to add more crash messages. @@ -50,7 +52,7 @@ static std::array crashEasterEgg = { "\tOh! MY GOD!!", }; -#if HAS_POSIX == 1 && !defined(__ANDROID__) +#if HAS_POSIX == 1 void ErrorHandler(int sig) { std::array arr; @@ -193,12 +195,12 @@ LONG seh_filter(_EXCEPTION_POINTERS* ex) void CrashHandler_Init() { -#if HAS_POSIX == 1 && !defined(__ANDROID__) +#if HAS_POSIX == 1 signal(SIGSEGV, ErrorHandler); signal(SIGABRT, ErrorHandler); #elif defined(_MSC_VER) SetUnhandledExceptionFilter(seh_filter); -#elif !defined(__ANDROID__) +#else HANDLE_WARNING(WarningType::Always, "tried to set error handler, but this ZAPD build lacks support for one", ""); #endif From 990ef9fcff33b18a10dfc4d8a2936ca29973b3f9 Mon Sep 17 00:00:00 2001 From: Waterdish Date: Sat, 18 Nov 2023 11:00:10 -0800 Subject: [PATCH 3/3] Remove duplicate code --- ZAPD/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ZAPD/CMakeLists.txt b/ZAPD/CMakeLists.txt index fdd37dd..566f590 100644 --- a/ZAPD/CMakeLists.txt +++ b/ZAPD/CMakeLists.txt @@ -333,10 +333,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(CMAKE_FIND_FRAMEWORK LAST) endif() -if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(CMAKE_FIND_FRAMEWORK LAST) -endif() - if (NOT CMAKE_SYSTEM_NAME STREQUAL "Android") find_package(PNG REQUIRED) endif()