test-client-godot/gdnative/SConstruct

154 lines
5.6 KiB
Text
Raw Permalink Normal View History

#!python
#
# On root project
# scons -C gdnative platform=linux bits=64
#
import os, subprocess, platform, sys
# Local dependency paths, adapt them to your setup
godot_headers_path = "../godot-cpp/godot_headers/"
cpp_bindings_path = "../godot-cpp/"
cpp_library = "godot-cpp"
if not os.path.exists( 'bin' ):
os.mkdir( 'bin' )
def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith('.' + extension):
sources.append(dir + '/' + f)
# Try to detect the host platform automatically
# This is used if no `platform` argument is passed
if sys.platform.startswith('linux'):
host_platform = 'linux'
elif sys.platform == 'darwin':
host_platform = 'osx'
elif sys.platform == 'win32':
host_platform = 'windows'
else:
raise ValueError('Could not detect platform automatically, please specify with platform=<platform>')
opts = Variables([], ARGUMENTS)
opts.Add(EnumVariable('platform', 'Target platform', host_platform,
allowed_values=('linux', 'osx', 'windows'),
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 - only effective on Windows', False))
# Must be the same setting as used for cpp_bindings
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_path, PathVariable.PathIsDir))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin'))
opts.Add(PathVariable('target_name', 'The library name.', 'libgdcrypt', PathVariable.PathAccept))
unknown = opts.UnknownVariables()
if unknown:
print("Unknown variables:" + unknown.keys())
Exit(1)
env = Environment()
opts.Update(env)
Help(opts.GenerateHelpText(env))
# sys.stderr.write("**** %s\n" % (cpp_library))
# 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 env['platform'] == 'windows':
if env['bits'] == '64':
env = Environment(TARGET_ARCH='amd64')
elif env['bits'] == '32':
env = Environment(TARGET_ARCH='x86')
else:
print("Warning: bits argument not specified, target arch is=" + env['TARGET_ARCH'])
opts.Update(env)
is64 = False
if (env['platform'] == 'osx' or env['TARGET_ARCH'] == 'amd64' or env['TARGET_ARCH'] == 'emt64' or env['TARGET_ARCH'] == 'x86_64'):
is64 = True
if env['bits'] == 'default':
env['bits'] = '64' if is64 else '32'
if env['platform'] == 'linux':
if env['use_llvm']:
env['CXX'] = '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':
if env['bits'] == '32':
raise ValueError('Only 64-bit builds are supported for the macOS target.')
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
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':
env.Append(CCFLAGS=['/EHsc', '/D_DEBUG', '/MDd'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD'])
else:
# MinGW
if env['bits'] == '64':
env['CXX'] = 'x86_64-w64-mingw32-g++'
elif env['bits'] == '32':
env['CXX'] = 'i686-w64-mingw32-g++'
env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings'])
env.Append(LINKFLAGS=['--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++'])
env.Append(CPPPATH=['.', env['headers_dir'], 'include', 'include/gen', 'include/core'])
# source to compile
sources = []
add_sources(sources, 'src', 'cpp')
#add_sources(sources, 'src/gen', 'cpp')
# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
libgodot = '{}.{}.{}.{}'.format(cpp_library, env['platform'], env['target'], env['bits'])
env.Append(LIBS=[libgodot])
# static = env.Command('libstdc++.a', None, Action('ln -s `g++ -print-file-name=libstdc++.a` $TARGET'));
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['src/'])
srcgdnative = Glob('src/*.cpp')
libgdnative = env.SharedLibrary(target=os.path.join(env['target_path'], 'libgdnative.{}.{}.{}'.format(env['platform'], env['target'], env['bits'])), source=srcgdnative)
Default(libgdnative)
# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))