Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
# Godot iOS Plugin template

This repo contains a *starter* Xcode and SCons configuration to build Godot plugin for iOS.
Xcode project and Scons configuration allows to build static `.a` library, that could be used with `.gdip` file as Godot's plugin to include platform functionality into exported application.
Xcode project and Scons configuration allows user to build static `.a` library, that could be used with `.gdip` file as Godot's plugin to include platform functionality into exported application.

# Initial setup

## Getting Godot engine headers

To build iOS plugin library it's required to have Godot's header files including generated ones. So running `scons platform=iphone target=<release|debug|release_debug>` in `godot` submodule folder is required.

# Working with Xcode

Building project should be enough to build a `.a` library that could be used with `.gdip` file.

# Working with SCons

Running `scons platform=ios arch=<arch> target=<release|debug|release_debug> target_name=<library_name> version=<3.2|4.0>` would result in plugin library for specific platform.
Compiling for multiple archs and using `lipo -create .. -output ..` might be required for release builds.
To build iOS plugin library it's required to have Godot's header files
1. You must use the headers of the same godot engine version as your editor (e.g. version 4.3)
```
cd godot
git fetch
git checkout origin/4.3
```
2. run `scons platform=ios target=<template_debug|template_release|editor>` in `godot` submodule folder to generate header files (use `template_debug` for development and `template_release` for release)
**Note**:
- You don't have to wait for full engine compilation, as header files are generated first. Once the actual compilation starts, you can stop this command by pressing `Ctrl + C`
- The scons command may vary depend on the version of Godot engine. Older version may use `scons platform=iphone target=<release|debug|release_debug>` (Check SConstruct file to construct the right command)

## Building Godot Plugin

- run `scons platform=ios arch=<arm64|armv7|x86_64> target=<release|debug|release_debug> target_name=<library_name> version=<3.2|4.0>` to build GodotShare (the generated `.a` file is found in /bin)
- The above command only generate library that works in IOS device but not in simulator. To test in simulator, run `scons platform=ios arch=<arm64|armv7|x86_64> target=<release|debug|release_debug> target_name=<library_name> version=<3.2|4.0> simulator=yes`

## Using Godot Plugin
- Create the directory [Your_Godot_project]/ios/plugins/[Library_name] in your Godot project and copy both the generated `.a` file and `plugin_example.gdip` file there
- Update `plugin_example.gdip` to point to correct `.a` file (The plugin should show up in the export template)
- Compiling for multiple archs and using `lipo -create .. -output ..` might be required for release builds.
28 changes: 13 additions & 15 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,26 @@ else:
quit();

# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/main',
'godot/core',
'godot/core/os',
'godot/core/platform',
'godot/platform/iphone',
'godot/modules',
'godot/scene',
'godot/servers',
'godot/drivers',
'godot/thirdparty',
])
if env['version'] == '3.x':
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/iphone',
])
else:
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/ios',
])

# tweak this if you want to use different folders, or more folders, to store your source code in.
sources = Glob('godot_plugin/*.cpp')
sources.append(Glob('godot_plugin/*.mm'))
sources.append(Glob('godot_plugin/*.m'))

# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone")
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "ios")
library_name = env['target_name'] + "." + library_platform + "." + env["target"] + ".a"
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)

Expand Down
2 changes: 1 addition & 1 deletion godot_plugin/godot_plugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "godot_plugin.h"
#import "godot_plugin_implementation.h"

#import "core/engine.h"
#import "core/config/engine.h"

PluginExample *plugin;

Expand Down
6 changes: 6 additions & 0 deletions godot_plugin/godot_plugin_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#ifndef godot_plugin_implementation_h
#define godot_plugin_implementation_h

#include "core/version.h"

// #if VERSION_MAJOR == 4
#include "core/object/class_db.h"
#else
#include "core/object.h"
#endif

class PluginExample : public Object {
GDCLASS(PluginExample, Object);
Expand Down
4 changes: 2 additions & 2 deletions godot_plugin/godot_plugin_implementation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#import <Foundation/Foundation.h>

#include "core/project_settings.h"
#include "core/class_db.h"
#include "core/config/project_settings.h"
#include "core/object/class_db.h"

#import "godot_plugin_implementation.h"

Expand Down