Skip to content

Commit

Permalink
#27 Insert updated plugin version to work with "release_debug"
Browse files Browse the repository at this point in the history
  • Loading branch information
gumaciel committed Jan 24, 2021
1 parent 1ee04e1 commit 699ab34
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ example/android
example/ios

ios/admob/lib
ios/extracted_headers
ios/godot
ios/lib
ios/bin
Expand Down
205 changes: 129 additions & 76 deletions ios/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ opts = Variables([], ARGUMENTS)
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(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release', "release_debug"]))
opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'armv7', 'x86_64']))
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
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"
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'admob_plugin']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.2', '4.0']))

# Updates the environment with the option variables.
opts.Update(env)
Expand All @@ -40,11 +35,16 @@ if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'

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

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

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

# For the reference:
Expand All @@ -55,82 +55,135 @@ if env['platform'] == '':
# - 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 = ''
# Enable Obj-C modules
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
xcframework_directory = ''

if env['simulator']:
xcframework_directory = 'ios-arm64_i386_x86_64-simulator'
sdk_name = 'iphonesimulator'
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
env.Append(LINKFLAGS=["-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(LINKFLAGS=["-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.Append(CCFLAGS=[
'-fobjc-arc',
'-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', '-fno-exceptions',
'-Wno-ambiguous-macro',
'-Wall', '-Werror=return-type',
# '-Wextra',
])

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'])
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
env.Prepend(CXXFLAGS=[
'-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON',
'-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
])
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])

if env['arch'] == 'armv7':
env.Prepend(CXXFLAGS=['-fno-aligned-allocation'])

if env['version'] == '3.2':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])

if env['target'] == 'debug':
env.Prepend(CXXFLAGS=[
'-gdwarf-2', '-O0',
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
'-DPTRCALL_ENABLED',
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=['-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
'-DPTRCALL_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
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'])
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
'-DPTRCALL_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
elif env['version'] == '4.0':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DVULKAN_ENABLED', '-std=gnu++17'])

if env['target'] == 'debug':
env.Prepend(CXXFLAGS=[
'-gdwarf-2', '-O0',
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
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.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
])

if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
print("No valid version to set flags for.")
quit();

# Adding header files
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/',
'godot',
'godot/main',
'godot/core',
'godot/core/os',
'godot/core/platform',
'godot/platform/iphone',
'godot/modules',
'godot/scene',
'godot/servers',
'godot/drivers',
'godot/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)
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone")
library_name = env['plugin'] + "." + library_platform + "." + env["target"] + ".a"
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)

Default(library)

# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))
Help(opts.GenerateHelpText(env))
3 changes: 3 additions & 0 deletions ios/scripts/extract_headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

rsync -a -m -R --include '*/' --include '*.h' --include '*.inc' --exclude '*' ./ extracted_headers
17 changes: 17 additions & 0 deletions ios/scripts/generate_static_library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Compile static libraries

# ARM64 Device
scons target=$2 arch=arm64 plugin=$1 version=$3
# ARM7 Device
scons target=$2 arch=armv7 plugin=$1 version=$3
# x86_64 Simulator
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" \
"./bin/lib$1.armv7-iphone.$2.a" \
"./bin/lib$1.arm64-iphone.$2.a" \
-output "./bin/$1.$2.a"
23 changes: 23 additions & 0 deletions ios/scripts/generate_xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Compile static libraries

# ARM64 Device
scons target=$2 arch=arm64 plugin=$1 version=$3
# ARM7 Device
scons target=$2 arch=armv7 plugin=$1 version=$3
# x86_64 Simulator
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
# ARM64 Simulator
scons target=$2 arch=arm64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" "./bin/lib$1.arm64-simulator.$2.a" -output "./bin/$1-simulator.$2.a"
lipo -create "./bin/lib$1.armv7-iphone.$2.a" "./bin/lib$1.arm64-iphone.$2.a" -output "./bin/$1-device.$2.a"

# Creating a xcframework
xcodebuild -create-xcframework \
-library "./bin/$1-device.$2.a" \
-library "./bin/$1-simulator.$2.a" \
-output "./bin/$1.$2.xcframework"

0 comments on commit 699ab34

Please sign in to comment.