Browse Source

Add android support, Update README.md

Compiles and runs fine on Android platform
Jayanth-L 6 years ago
parent
commit
77cde5bb3a
2 changed files with 57 additions and 4 deletions
  1. 22 1
      README.md
  2. 35 3
      SConstruct

+ 22 - 1
README.md

@@ -76,8 +76,16 @@ $ cd godot-cpp
 $ scons platform=<your platform> generate_bindings=yes
 $ scons platform=<your platform> generate_bindings=yes
 $ cd ..
 $ 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++
 > 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*
 *macOS*
 For OSX you need to find out what compiler flags need to be used.
 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
 ### 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` 
 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` 
 
 

+ 35 - 3
SConstruct

@@ -29,7 +29,7 @@ opts.Add(EnumVariable(
     'platform',
     'platform',
     'Target platform',
     'Target platform',
     host_platform,
     host_platform,
-    allowed_values=('linux', 'osx', 'windows'),
+    allowed_values=('linux', 'osx', 'windows', 'android'),
     ignorecase=2
     ignorecase=2
 ))
 ))
 opts.Add(EnumVariable(
 opts.Add(EnumVariable(
@@ -73,8 +73,14 @@ opts.Add(BoolVariable(
     'Generate GDNative API bindings',
     'Generate GDNative API bindings',
     False
     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)
 opts.Update(env)
 Help(opts.GenerateHelpText(env))
 Help(opts.GenerateHelpText(env))
 
 
@@ -82,7 +88,8 @@ is64 = sys.maxsize > 2**32
 if (
 if (
     env['TARGET_ARCH'] == 'amd64' or
     env['TARGET_ARCH'] == 'amd64' or
     env['TARGET_ARCH'] == 'emt64' or
     env['TARGET_ARCH'] == 'emt64' or
-    env['TARGET_ARCH'] == 'x86_64'
+    env['TARGET_ARCH'] == 'x86_64' or
+    env['TARGET_ARCH'] == 'arm64-v8a'
 ):
 ):
     is64 = True
     is64 = True
 
 
@@ -119,6 +126,31 @@ if env['platform'] == 'linux':
         env.Append(CCFLAGS=['-m32'])
         env.Append(CCFLAGS=['-m32'])
         env.Append(LINKFLAGS=['-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':
 elif env['platform'] == 'osx':
     # Use Clang on macOS by default
     # Use Clang on macOS by default
     env['CXX'] = 'clang++'
     env['CXX'] = 'clang++'