2019-03-26 23:51:51 +00:00
|
|
|
#!/usr/bin/env python
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2018-02-22 22:16:25 +00:00
|
|
|
|
|
|
|
def add_sources(sources, dir, extension):
|
2019-03-26 23:51:51 +00:00
|
|
|
for f in os.listdir(dir):
|
|
|
|
if f.endswith('.' + extension):
|
|
|
|
sources.append(dir + '/' + f)
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
|
|
|
|
# Try to detect the host platform automatically.
|
2018-08-16 14:14:35 +00:00
|
|
|
# This is used if no `platform` argument is passed
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
host_platform = 'linux'
|
|
|
|
elif sys.platform == 'darwin':
|
|
|
|
host_platform = 'osx'
|
2019-05-16 01:09:39 +00:00
|
|
|
elif sys.platform == 'win32' or sys.platform == 'msys':
|
2018-08-16 14:14:35 +00:00
|
|
|
host_platform = 'windows'
|
|
|
|
else:
|
2019-03-26 23:51:51 +00:00
|
|
|
raise ValueError(
|
|
|
|
'Could not detect platform automatically, please specify with '
|
|
|
|
'platform=<platform>'
|
|
|
|
)
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
opts = Variables([], ARGUMENTS)
|
2019-03-26 23:51:51 +00:00
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'platform',
|
|
|
|
'Target platform',
|
|
|
|
host_platform,
|
2019-08-05 20:13:23 +00:00
|
|
|
allowed_values=('linux', 'osx', 'windows', 'android'),
|
2019-03-26 23:51:51 +00:00
|
|
|
ignorecase=2
|
|
|
|
))
|
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'bits',
|
|
|
|
'Target platform bits',
|
|
|
|
'default',
|
|
|
|
('default', '32', '64')
|
|
|
|
))
|
|
|
|
opts.Add(BoolVariable(
|
|
|
|
'use_llvm',
|
|
|
|
'Use the LLVM compiler - only effective when targeting Linux',
|
|
|
|
False
|
|
|
|
))
|
|
|
|
opts.Add(BoolVariable(
|
|
|
|
'use_mingw',
|
|
|
|
'Use the MinGW compiler instead of MSVC - only effective on Windows',
|
|
|
|
False
|
|
|
|
))
|
2018-08-16 14:14:35 +00:00
|
|
|
# Must be the same setting as used for cpp_bindings
|
2019-03-26 23:51:51 +00:00
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'target',
|
|
|
|
'Compilation target',
|
|
|
|
'debug',
|
|
|
|
allowed_values=('debug', 'release'),
|
|
|
|
ignorecase=2
|
|
|
|
))
|
|
|
|
opts.Add(PathVariable(
|
|
|
|
'headers_dir',
|
|
|
|
'Path to the directory containing Godot headers',
|
|
|
|
'godot_headers',
|
|
|
|
PathVariable.PathIsDir
|
|
|
|
))
|
|
|
|
opts.Add(PathVariable(
|
|
|
|
'custom_api_file',
|
|
|
|
'Path to a custom JSON API file',
|
|
|
|
None,
|
|
|
|
PathVariable.PathIsFile
|
|
|
|
))
|
|
|
|
opts.Add(BoolVariable(
|
|
|
|
'generate_bindings',
|
|
|
|
'Generate GDNative API bindings',
|
|
|
|
False
|
|
|
|
))
|
2019-08-05 20:13:23 +00:00
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'android_api_level',
|
|
|
|
'Target Android API Level',
|
|
|
|
'29',
|
|
|
|
('29', '28', '27', '26')
|
|
|
|
))
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2019-08-05 20:13:23 +00:00
|
|
|
env = Environment(ENV = os.environ)
|
2018-08-16 14:14:35 +00:00
|
|
|
opts.Update(env)
|
|
|
|
Help(opts.GenerateHelpText(env))
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
is64 = sys.maxsize > 2**32
|
|
|
|
if (
|
|
|
|
env['TARGET_ARCH'] == 'amd64' or
|
|
|
|
env['TARGET_ARCH'] == 'emt64' or
|
2019-08-05 20:13:23 +00:00
|
|
|
env['TARGET_ARCH'] == 'x86_64' or
|
|
|
|
env['TARGET_ARCH'] == 'arm64-v8a'
|
2019-03-26 23:51:51 +00:00
|
|
|
):
|
|
|
|
is64 = True
|
|
|
|
|
|
|
|
if env['bits'] == 'default':
|
|
|
|
env['bits'] = '64' if is64 else '32'
|
|
|
|
|
|
|
|
# This makes sure to keep the session environment variables on Windows.
|
|
|
|
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
|
|
|
|
# all the required tools
|
|
|
|
if host_platform == 'windows':
|
2018-10-25 16:35:33 +00:00
|
|
|
if env['bits'] == '64':
|
|
|
|
env = Environment(TARGET_ARCH='amd64')
|
|
|
|
elif env['bits'] == '32':
|
|
|
|
env = Environment(TARGET_ARCH='x86')
|
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
opts.Update(env)
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
if env['platform'] == 'linux':
|
|
|
|
if env['use_llvm']:
|
2018-02-25 16:03:55 +00:00
|
|
|
env['CXX'] = 'clang++'
|
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
env.Append(CCFLAGS=['-fPIC', '-g', '-std=c++14', '-Wwrite-strings'])
|
2019-08-05 20:13:23 +00:00
|
|
|
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'])
|
|
|
|
|
|
|
|
# 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'])
|
2018-08-16 14:14:35 +00:00
|
|
|
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':
|
2019-03-26 23:51:51 +00:00
|
|
|
# Use Clang on macOS by default
|
|
|
|
env['CXX'] = 'clang++'
|
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
if env['bits'] == '32':
|
2019-03-26 23:51:51 +00:00
|
|
|
raise ValueError(
|
|
|
|
'Only 64-bit builds are supported for the macOS target.'
|
|
|
|
)
|
2018-08-16 14:14:35 +00:00
|
|
|
|
|
|
|
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', 'x86_64'])
|
2019-03-26 23:51:51 +00:00
|
|
|
env.Append(LINKFLAGS=[
|
|
|
|
'-arch',
|
|
|
|
'x86_64',
|
|
|
|
'-framework',
|
|
|
|
'Cocoa',
|
|
|
|
'-Wl,-undefined,dynamic_lookup',
|
|
|
|
])
|
2018-08-16 14:14:35 +00:00
|
|
|
|
|
|
|
if env['target'] == 'debug':
|
|
|
|
env.Append(CCFLAGS=['-Og'])
|
|
|
|
elif env['target'] == 'release':
|
|
|
|
env.Append(CCFLAGS=['-O3'])
|
|
|
|
|
|
|
|
elif env['platform'] == 'windows':
|
|
|
|
if host_platform == 'windows' and not env['use_mingw']:
|
|
|
|
# MSVC
|
|
|
|
env.Append(LINKFLAGS=['/WX'])
|
|
|
|
if env['target'] == 'debug':
|
2019-04-07 14:03:20 +00:00
|
|
|
env.Append(CCFLAGS=['/Z7', '/Od', '/EHsc', '/D_DEBUG', '/MDd'])
|
2018-08-16 14:14:35 +00:00
|
|
|
elif env['target'] == 'release':
|
|
|
|
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD'])
|
2019-03-26 23:51:51 +00:00
|
|
|
|
2019-05-25 12:23:36 +00:00
|
|
|
elif host_platform == 'linux' or host_platform == 'osx':
|
2019-03-26 23:51:51 +00:00
|
|
|
# Cross-compilation using MinGW
|
2018-08-16 14:14:35 +00:00
|
|
|
if env['bits'] == '64':
|
|
|
|
env['CXX'] = 'x86_64-w64-mingw32-g++'
|
2019-05-25 12:23:36 +00:00
|
|
|
env['AR'] = "x86_64-w64-mingw32-ar"
|
|
|
|
env['RANLIB'] = "x86_64-w64-mingw32-ranlib"
|
|
|
|
env['LINK'] = "x86_64-w64-mingw32-g++"
|
2018-08-16 14:14:35 +00:00
|
|
|
elif env['bits'] == '32':
|
|
|
|
env['CXX'] = 'i686-w64-mingw32-g++'
|
2019-05-25 12:23:36 +00:00
|
|
|
env['AR'] = "i686-w64-mingw32-ar"
|
|
|
|
env['RANLIB'] = "i686-w64-mingw32-ranlib"
|
|
|
|
env['LINK'] = "i686-w64-mingw32-g++"
|
2018-04-08 16:00:54 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
# Native or cross-compilation using MinGW
|
2019-05-25 12:23:36 +00:00
|
|
|
if host_platform == 'linux' or host_platform == 'osx' or env['use_mingw']:
|
2018-08-16 14:14:35 +00:00
|
|
|
env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings'])
|
2019-03-26 23:51:51 +00:00
|
|
|
env.Append(LINKFLAGS=[
|
|
|
|
'--static',
|
|
|
|
'-Wl,--no-undefined',
|
|
|
|
'-static-libgcc',
|
|
|
|
'-static-libstdc++',
|
|
|
|
])
|
|
|
|
|
|
|
|
env.Append(CPPPATH=[
|
|
|
|
'.',
|
|
|
|
env['headers_dir'],
|
|
|
|
'include',
|
|
|
|
'include/gen',
|
|
|
|
'include/core',
|
|
|
|
])
|
2018-02-11 14:50:01 +00:00
|
|
|
|
|
|
|
# Generate bindings?
|
|
|
|
json_api_file = ''
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
if 'custom_api_file' in env:
|
2018-11-25 21:13:15 +00:00
|
|
|
json_api_file = env['custom_api_file']
|
2018-05-16 00:05:41 +00:00
|
|
|
else:
|
2018-02-11 14:50:01 +00:00
|
|
|
json_api_file = os.path.join(os.getcwd(), 'godot_headers', 'api.json')
|
2017-03-06 07:49:24 +00:00
|
|
|
|
2018-11-25 21:13:15 +00:00
|
|
|
if env['generate_bindings']:
|
2018-08-16 14:14:35 +00:00
|
|
|
# Actually create the bindings here
|
2017-07-23 15:53:50 +00:00
|
|
|
import binding_generator
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2017-07-23 15:53:50 +00:00
|
|
|
binding_generator.generate_bindings(json_api_file)
|
2017-03-06 07:49:24 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
# Sources to compile
|
2018-02-22 22:16:25 +00:00
|
|
|
sources = []
|
|
|
|
add_sources(sources, 'src/core', 'cpp')
|
2018-02-11 14:50:01 +00:00
|
|
|
add_sources(sources, 'src/gen', 'cpp')
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
library = env.StaticLibrary(
|
2019-03-26 23:51:51 +00:00
|
|
|
target='bin/' + 'libgodot-cpp.{}.{}.{}'.format(
|
|
|
|
env['platform'],
|
|
|
|
env['target'],
|
|
|
|
env['bits'],
|
|
|
|
), source=sources
|
2018-08-16 14:14:35 +00:00
|
|
|
)
|
2018-02-22 22:16:25 +00:00
|
|
|
Default(library)
|