Skip to content

Commit

Permalink
#27 First try on new Plugin
Browse files Browse the repository at this point in the history
Former-commit-id: b5ac43a
  • Loading branch information
gumaciel committed Jan 17, 2021
1 parent a12d26c commit b4b888d
Show file tree
Hide file tree
Showing 24 changed files with 644 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ data_*/
*.pyc

example/android
example/ios

ios/admob/lib
ios/godot
ios/lib
ios/bin
.DS_Store

*.a
*.o
*.d
Binary file added ios/.sconsign.dblite
Binary file not shown.
136 changes: 136 additions & 0 deletions ios/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env python
import os
import sys
import subprocess

if sys.version_info < (3,):
def decode_utf8(x):
return x
else:
import codecs
def decode_utf8(x):
return codecs.utf_8_decode(x)[0]

# Most of the settings are taken from https://github.com/BastiaanOlij/gdnative_cpp_example

opts = Variables([], ARGUMENTS)

# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()

# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'ios']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['','ios']))
opts.Add(EnumVariable('arch', "Compilation platform", '', ['', 'arm64', 'armv7', 'x86_64']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
opts.Add(PathVariable('target_name', 'The library name.', 'gdexample', PathVariable.PathAccept))
opts.Add(EnumVariable('mode', 'Library build mode', 'static', ['static', 'dynamic']))

# Local dependency paths, adapt them to your setup
godot_path = "godot/"
godot_library = "ios.fat.a"

# Updates the environment with the option variables.
opts.Update(env)

# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'

if env['p'] != '':
env['platform'] = env['p']

if env['platform'] == '':
print("No valid target platform selected.")
quit();

# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

# Check our platform specifics
if env['platform'] == "ios":
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])

xcframework_directory = ''


if env['arch'] == 'x86_64':
xcframework_directory = 'ios-arm64_i386_x86_64-simulator'
sdk_name = 'iphonesimulator'
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
else:
xcframework_directory = 'ios-arm64_armv7'
sdk_name = 'iphoneos'
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])

env.Append(FRAMEWORKPATH=['#lib/GoogleMobileAds.xcframework/' + xcframework_directory])
env.Append(FRAMEWORKPATH=['#lib/UserMessagingPlatform.xcframework/' + xcframework_directory])

try:
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
except (subprocess.CalledProcessError, OSError):
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))

env['target_path'] += 'ios/'
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
env.Append(CXXFLAGS=['-std=c++17'])
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])

if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS=['-g', '-O2', '-DDEBUG', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE', '-DTYPED_METHOD_BIND'])
else:
env.Append(CCFLAGS=['-g', '-O3'])


env.Append(
CCFLAGS="-fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=10.0".split()
)
env.Append(LINKFLAGS=[])

env.Append(
LINKFLAGS=[
"-arch",
env['arch'],
"-miphoneos-version-min=10.0",
'-isysroot', sdk_path,
'-F' + sdk_path
]
)

# make sure our binding library is properly includes
env.Append(CPPPATH=[
'.',
godot_path,
godot_path + 'main/',
godot_path + 'core/',
godot_path + 'core/os/',
godot_path + 'core/platform/',
godot_path + 'platform/iphone/',
godot_path + 'modules/',
godot_path + 'scene/',
godot_path + 'servers/',
godot_path + 'drivers/',
godot_path + 'thirdparty/',
])
env.Append(LIBPATH=[godot_path + 'bin/'])
env.Append(LIBS=[godot_library])

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

library = env.StaticLibrary(target=env['target_path'] + env['target_name'] , source=sources)

Default(library)

# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))
7 changes: 0 additions & 7 deletions ios/admob/SCsub

This file was deleted.

15 changes: 0 additions & 15 deletions ios/admob/config.py

This file was deleted.

1 change: 0 additions & 1 deletion ios/admob/lib/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions ios/admob/register_types.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions ios/admob/register_types.h

This file was deleted.

Loading

0 comments on commit b4b888d

Please sign in to comment.