From b7deb632513795e495e9a3aa76a9400fef4de364 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 5 Feb 2021 22:49:06 +0200 Subject: Experimenting with an iOS build iPlatformApple applies to both macOS and iOS. Added iPlatformAppleDesktop and iPlatformAppleMobile to make a distinction between the two. IssueID #96 --- CMakeLists.txt | 30 +++++++++++++----------------- Depends-iOS.cmake | 21 +++++++++++++++++++++ Depends.cmake | 20 ++++++++++++++++++++ src/app.c | 18 ++++++++++++------ src/ios.h | 27 +++++++++++++++++++++++++++ src/ios.m | 23 +++++++++++++++++++++++ src/main.c | 7 +++++-- src/ui/bindingswidget.c | 4 ++-- src/ui/documentwidget.c | 2 +- src/ui/inputwidget.c | 4 ++-- src/ui/window.c | 8 +++++--- 11 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 Depends-iOS.cmake create mode 100644 Depends.cmake create mode 100644 src/ios.h create mode 100644 src/ios.m diff --git a/CMakeLists.txt b/CMakeLists.txt index ce07c2de..1a0e0f8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,21 +35,7 @@ option (ENABLE_DOWNLOAD_EDIT "Allow changing the Downloads directory" ON) include (BuildType.cmake) include (res/Embed.cmake) -if (NOT EXISTS ${CMAKE_SOURCE_DIR}/lib/the_Foundation/CMakeLists.txt) - set (INSTALL_THE_FOUNDATION YES) - find_package (the_Foundation REQUIRED) -else () - set (INSTALL_THE_FOUNDATION NO) - set (TFDN_STATIC_LIBRARY ON CACHE BOOL "") - set (TFDN_ENABLE_INSTALL OFF CACHE BOOL "") - set (TFDN_ENABLE_TESTS OFF CACHE BOOL "") - set (TFDN_ENABLE_WEBREQUEST OFF CACHE BOOL "") - add_subdirectory (lib/the_Foundation) - add_library (the_Foundation::the_Foundation ALIAS the_Foundation) -endif () -find_package (PkgConfig REQUIRED) -pkg_check_modules (SDL2 REQUIRED sdl2) -pkg_check_modules (MPG123 IMPORTED_TARGET libmpg123) +include (Depends.cmake) # Embedded resources are written to a generated source file. message (STATUS "Preparing embedded resources...") @@ -183,7 +169,10 @@ set (SOURCES ${CMAKE_CURRENT_BINARY_DIR}/embedded.h ) if (IOS) + add_definitions (-DiPlatformAppleMobile=1) + list (APPEND SOURCES src/ios.m src/ios.h) elseif (APPLE) + add_definitions (-DiPlatformAppleDesktop=1) list (APPEND SOURCES src/macos.m src/macos.h) list (APPEND RESOURCES "res/Lagrange.icns") endif () @@ -238,13 +227,20 @@ if (APPLE) else () target_link_libraries (app PUBLIC "-framework AppKit") endif () - if (CMAKE_OSX_DEPLOYMENT_TARGET) + if (CMAKE_OSX_DEPLOYMENT_TARGET AND NOT IOS) target_compile_options (app PUBLIC -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}) target_link_options (app PUBLIC -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}) endif () + if (XCODE_DEVELOPMENT_TEAM) + set_property (TARGET app PROPERTY + XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${XCODE_DEVELOPMENT_TEAM} + ) + endif () + if (SDL2_LIBRARY_DIRS) + set_property (TARGET app PROPERTY BUILD_RPATH ${SDL2_LIBRARY_DIRS}) + endif () set_target_properties (app PROPERTIES OUTPUT_NAME "Lagrange" - BUILD_RPATH ${SDL2_LIBRARY_DIRS} MACOSX_BUNDLE YES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/res/MacOSXBundleInfo.plist.in" MACOSX_BUNDLE_BUNDLE_NAME "Lagrange" diff --git a/Depends-iOS.cmake b/Depends-iOS.cmake new file mode 100644 index 00000000..013ee09a --- /dev/null +++ b/Depends-iOS.cmake @@ -0,0 +1,21 @@ +message (STATUS "iOS dependency directory: ${IOS_DIR}") + +find_package (the_Foundation REQUIRED) + +set (SDL2_INCLUDE_DIRS ${IOS_DIR}/include/SDL2) +set (SDL2_LDFLAGS + ${IOS_DIR}/lib/libSDL2.a + "-framework AudioToolbox" + "-framework AVFoundation" + "-framework CoreAudio" + "-framework CoreGraphics" + "-framework CoreHaptics" + "-framework CoreMotion" + "-framework Foundation" + "-framework Foundation" + "-framework GameController" + "-framework Metal" + "-framework OpenGLES" + "-framework QuartzCore" + "-framework UIKit" +) diff --git a/Depends.cmake b/Depends.cmake new file mode 100644 index 00000000..b4dacf7c --- /dev/null +++ b/Depends.cmake @@ -0,0 +1,20 @@ +if (IOS) + include (Depends-iOS.cmake) + return () +endif () + +if (NOT EXISTS ${CMAKE_SOURCE_DIR}/lib/the_Foundation/CMakeLists.txt) + set (INSTALL_THE_FOUNDATION YES) + find_package (the_Foundation REQUIRED) +else () + set (INSTALL_THE_FOUNDATION NO) + set (TFDN_STATIC_LIBRARY ON CACHE BOOL "") + set (TFDN_ENABLE_INSTALL OFF CACHE BOOL "") + set (TFDN_ENABLE_TESTS OFF CACHE BOOL "") + set (TFDN_ENABLE_WEBREQUEST OFF CACHE BOOL "") + add_subdirectory (lib/the_Foundation) + add_library (the_Foundation::the_Foundation ALIAS the_Foundation) +endif () +find_package (PkgConfig REQUIRED) +pkg_check_modules (SDL2 REQUIRED sdl2) +pkg_check_modules (MPG123 IMPORTED_TARGET libmpg123) diff --git a/src/app.c b/src/app.c index b2b0f53c..43568ba6 100644 --- a/src/app.c +++ b/src/app.c @@ -61,7 +61,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include -#if defined (iPlatformApple) && !defined (iPlatformIOS) +#if defined (iPlatformAppleDesktop) # include "macos.h" #endif #if defined (iPlatformMsys) @@ -73,10 +73,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ iDeclareType(App) -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) #define EMB_BIN "../../Resources/resources.lgr" static const char *defaultDataDir_App_ = "~/Library/Application Support/fi.skyjake.Lagrange"; #endif +#if defined (iPlatformAppleMobile) +#define EMB_BIN "../../Resources/resources.lgr" +static const char *defaultDataDir_App_ = "~/config"; +#endif #if defined (iPlatformMsys) #define EMB_BIN "../resources.lgr" static const char *defaultDataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; @@ -429,7 +433,7 @@ static void init_App_(iApp *d, int argc, char **argv) { d->lastEventTime = 0; d->sleepTimer = SDL_AddTimer(1000, checkAsleep_App_, d); #endif -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) setupApplication_MacOS(); #endif init_Keys(); @@ -628,7 +632,7 @@ void processEvents_App(enum iAppEventMode eventMode) { wasUsed = processEvent_Keys(&ev); } if (ev.type == SDL_USEREVENT && ev.user.code == command_UserEventCode) { -#if defined (iPlatformApple) && !defined (iPlatformIOS) +#if defined (iPlatformAppleDesktop) handleCommand_MacOS(command_UserEvent(&ev)); #endif if (isCommand_UserEvent(&ev, "metrics.changed")) { @@ -1565,9 +1569,10 @@ void openInDefaultBrowser_App(const iString *url) { return; } #endif +#if !defined (iPlatformAppleMobile) iProcess *proc = new_Process(); setArguments_Process(proc, -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) iClob(newStringsCStr_StringList("/usr/bin/env", "open", cstr_String(url), NULL)) #elif defined (iPlatformLinux) || defined (iPlatformOther) iClob(newStringsCStr_StringList("/usr/bin/env", "xdg-open", cstr_String(url), NULL)) @@ -1581,10 +1586,11 @@ void openInDefaultBrowser_App(const iString *url) { ); start_Process(proc); iRelease(proc); +#endif } void revealPath_App(const iString *path) { -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) const char *scriptPath = concatPath_CStr(dataDir_App_(), "revealfile.scpt"); iFile *f = newCStr_File(scriptPath); if (open_File(f, writeOnly_FileMode | text_FileMode)) { diff --git a/src/ios.h b/src/ios.h new file mode 100644 index 00000000..7217e74a --- /dev/null +++ b/src/ios.h @@ -0,0 +1,27 @@ +/* Copyright 2021 Jaakko Keränen + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#pragma once + +#include "ui/util.h" + + diff --git a/src/ios.m b/src/ios.m new file mode 100644 index 00000000..029bd068 --- /dev/null +++ b/src/ios.m @@ -0,0 +1,23 @@ +/* Copyright 2021 Jaakko Keränen + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "ios.h" diff --git a/src/main.c b/src/main.c index 5e4e7284..49487bbf 100644 --- a/src/main.c +++ b/src/main.c @@ -22,9 +22,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "app.h" -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) # include "macos.h" #endif +#if defined (iPlatformAppleMobile) +# include "ios.h" +#endif #if defined (iPlatformMsys) # include "win32.h" # define SDL_MAIN_HANDLED @@ -41,7 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ int main(int argc, char **argv) { printf("Lagrange: A Beautiful Gemini Client\n"); signal(SIGPIPE, SIG_IGN); -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) enableMomentumScroll_MacOS(); registerURLHandler_MacOS(); #endif diff --git a/src/ui/bindingswidget.c b/src/ui/bindingswidget.c index 9a2070ba..558bdcd5 100644 --- a/src/ui/bindingswidget.c +++ b/src/ui/bindingswidget.c @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "command.h" #include "util.h" #include "app.h" -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) # include "macos.h" #endif @@ -140,7 +140,7 @@ static void setActiveItem_BindingsWidget_(iBindingsWidget *d, size_t pos) { item->isWaitingForEvent = iTrue; invalidateItem_ListWidget(d->list, d->activePos); } -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) /* Native menus must be disabled while grabbing keys so the shortcuts don't trigger. */ const iBool enableNativeMenus = (d->activePos == iInvalidPos); enableMenu_MacOS("Edit", enableNativeMenus); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 79a77f61..38e7fcca 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -251,7 +251,7 @@ void init_DocumentWidget(iDocumentWidget *d) { addChildFlags_Widget(w, iClob(new_IndicatorWidget()), resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); -#if !defined (iPlatformApple) /* in system menu */ +#if !defined (iPlatformAppleDesktop) /* in system menu */ addAction_Widget(w, reload_KeyShortcut, "navigate.reload"); addAction_Widget(w, closeTab_KeyShortcut, "tabs.close"); addAction_Widget(w, SDLK_d, KMOD_PRIMARY, "bookmark.add"); diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 1674040b..2d767152 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) # include "macos.h" #endif @@ -39,7 +39,7 @@ static const int refreshInterval_InputWidget_ = 256; static const size_t maxUndo_InputWidget_ = 64; static void enableEditorKeysInMenus_(iBool enable) { -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) enableMenuItemsByKey_MacOS(SDLK_LEFT, KMOD_PRIMARY, enable); enableMenuItemsByKey_MacOS(SDLK_RIGHT, KMOD_PRIMARY, enable); #else diff --git a/src/ui/window.c b/src/ui/window.c index b198dd15..5c7fcaab 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -41,7 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined (iPlatformMsys) # include "../win32.h" #endif -#if defined (iPlatformApple) && !defined (iPlatformIOS) +#if defined (iPlatformAppleDesktop) # include "macos.h" #endif @@ -92,7 +92,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { return iFalse; } -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) # define iHaveNativeMenus #endif @@ -724,8 +724,10 @@ void init_Window(iWindow *d, iRect rect) { d->isMouseInside = iTrue; d->focusGainedAt = 0; uint32_t flags = 0; -#if defined (iPlatformApple) +#if defined (iPlatformAppleDesktop) SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl"); +#elif defined (iPlatformAppleMobile) + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal"); #else flags |= SDL_WINDOW_OPENGL; #endif -- cgit v1.2.3