summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayanth-L <jayanthl@outlook.com>2019-08-05 13:13:23 -0700
committerTGRCDev <tiger@tgrc.dev>2019-09-18 10:44:46 -0700
commit77cde5bb3acc79309454f65a28f5933564cc03fd (patch)
tree44c17577430ec164e7bbf86008dc9460af9f63b6
parentc2ec46f64a24de9a46b06c3e987c306f549ccadb (diff)
downloadredot-cpp-77cde5bb3acc79309454f65a28f5933564cc03fd.tar.gz
Add android support, Update README.md
Compiles and runs fine on Android platform
-rw-r--r--README.md23
-rw-r--r--SConstruct38
2 files changed, 57 insertions, 4 deletions
diff --git a/README.md b/README.md
index f9d5d2e..31fc1a7 100644
--- a/README.md
+++ b/README.md
@@ -76,8 +76,16 @@ $ cd godot-cpp
$ scons platform=<your platform> generate_bindings=yes
$ cd ..
```
+For android:
+Download latest Android NDK from official website and set NDK path.
+```
+$ export PATH="$PATH:/PATH-TO-ANDROID-NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/"
+$ scons platform=android generate_bindings=yes
+```
+you can also specify architecture by enabling bits=64 (or 32) default is 64
+
-> Replace `<your platform>` with either `windows`, `linux` or `osx`.
+> Replace `<your platform>` with either `windows`, `linux`, `osx` or `android`.
> Include `use_llvm=yes` for using clang++
@@ -189,6 +197,19 @@ $ link /nologo /dll /out:bin\libtest.dll /implib:bin\libsimple.lib src\init.obj
*macOS*
For OSX you need to find out what compiler flags need to be used.
+*Android*
+```
+$ cd SimpleLibrary
+$ aarch64-linux-android29-clang -fPIC -o src/init.os -c src/init.cpp -g -O3 -std=c++14 -Igodot-cpp/include -Igodot-cpp/include/core -Igodot-cpp/include/gen -Igodot-cpp/godot_headers
+$ aarch64-linux-android29-clang -o bin/libtest.so -shared src/init.os -Lgodot-cpp/bin -l<name of the godot-cpp>
+```
+> use `armv7a-linux-androideabi29-clang` for 32 bit armeabi-v7a library
+
+> This creates the file `libtest.so` in your `SimpleLibrary/bin` directory.
+
+> You will need to replace `<name of the godot-cpp>` with the file that was created in [**Compiling the cpp bindings library**](#compiling-the-cpp-bindings-library)
+
+
### Creating `.gdnlib` and `.gdns` files
follow [godot_header/README.md](https://github.com/GodotNativeTools/godot_headers/blob/master/README.md#how-do-i-use-native-scripts-from-the-editor) to create the `.gdns`
diff --git a/SConstruct b/SConstruct
index 8d4a2a0..2f3f811 100644
--- a/SConstruct
+++ b/SConstruct
@@ -29,7 +29,7 @@ opts.Add(EnumVariable(
'platform',
'Target platform',
host_platform,
- allowed_values=('linux', 'osx', 'windows'),
+ allowed_values=('linux', 'osx', 'windows', 'android'),
ignorecase=2
))
opts.Add(EnumVariable(
@@ -73,8 +73,14 @@ opts.Add(BoolVariable(
'Generate GDNative API bindings',
False
))
+opts.Add(EnumVariable(
+ 'android_api_level',
+ 'Target Android API Level',
+ '29',
+ ('29', '28', '27', '26')
+))
-env = Environment()
+env = Environment(ENV = os.environ)
opts.Update(env)
Help(opts.GenerateHelpText(env))
@@ -82,7 +88,8 @@ is64 = sys.maxsize > 2**32
if (
env['TARGET_ARCH'] == 'amd64' or
env['TARGET_ARCH'] == 'emt64' or
- env['TARGET_ARCH'] == 'x86_64'
+ env['TARGET_ARCH'] == 'x86_64' or
+ env['TARGET_ARCH'] == 'arm64-v8a'
):
is64 = True
@@ -119,6 +126,31 @@ if env['platform'] == 'linux':
env.Append(CCFLAGS=['-m32'])
env.Append(LINKFLAGS=['-m32'])
+# Add android target as it works for both armeabi-v7a and arm64-v8a architectures
+elif env['platform'] == 'android':
+ # Use clang by default on android(NDK provides only clang)
+ env['use_llvm'] = 'yes'
+ if env['use_llvm']:
+ if(env['bits'] == '64'):
+ env['CXX'] = 'aarch64-linux-android' + env['android_api_level'] + '-clang++'
+ elif(env['bits'] == '32'):
+ env['CXX'] = 'armv7a-linux-androideabi' + env['android_api_level'] +'-clang++'
+
+ env.Append(CCFLAGS=['-fPIC', '-g', '-std=c++14', '-Wwrite-strings'])
+ env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
+
+ if env['target'] == 'debug':
+ env.Append(CCFLAGS=['-Og'])
+ elif env['target'] == 'release':
+ env.Append(CCFLAGS=['-O3'])
+
+ if env['bits'] == '64':
+ env.Append(CCFLAGS=['-m64'])
+ env.Append(LINKFLAGS=['-m64'])
+ elif env['bits'] == '32':
+ env.Append(CCFLAGS=['-m32'])
+ env.Append(LINKFLAGS=['-m32'])
+
elif env['platform'] == 'osx':
# Use Clang on macOS by default
env['CXX'] = 'clang++'