Fix and improve the build system
- Fix automatic architecture detection - Fix compiling with MinGW on Linux - MinGW on Windows is still not working though - Default to Clang on macOS - Remove redundant `use_custom_api_file` option - Format SConstruct using Flake8 This closes #245.pull/261/head
parent
df04c4097f
commit
976a188837
161
SConstruct
161
SConstruct
|
@ -1,14 +1,16 @@
|
||||||
#!python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os, subprocess, platform, sys
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def add_sources(sources, dir, extension):
|
def add_sources(sources, dir, extension):
|
||||||
for f in os.listdir(dir):
|
for f in os.listdir(dir):
|
||||||
if f.endswith('.' + extension):
|
if f.endswith('.' + extension):
|
||||||
sources.append(dir + '/' + f)
|
sources.append(dir + '/' + f)
|
||||||
|
|
||||||
# Try to detect the host platform automatically
|
|
||||||
|
# Try to detect the host platform automatically.
|
||||||
# This is used if no `platform` argument is passed
|
# This is used if no `platform` argument is passed
|
||||||
if sys.platform.startswith('linux'):
|
if sys.platform.startswith('linux'):
|
||||||
host_platform = 'linux'
|
host_platform = 'linux'
|
||||||
|
@ -17,50 +19,86 @@ elif sys.platform == 'darwin':
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
host_platform = 'windows'
|
host_platform = 'windows'
|
||||||
else:
|
else:
|
||||||
raise ValueError('Could not detect platform automatically, please specify with platform=<platform>')
|
raise ValueError(
|
||||||
|
'Could not detect platform automatically, please specify with '
|
||||||
|
'platform=<platform>'
|
||||||
|
)
|
||||||
|
|
||||||
opts = Variables([], ARGUMENTS)
|
opts = Variables([], ARGUMENTS)
|
||||||
|
opts.Add(EnumVariable(
|
||||||
opts.Add(EnumVariable('platform', 'Target platform', host_platform,
|
'platform',
|
||||||
allowed_values=('linux', 'osx', 'windows'),
|
'Target platform',
|
||||||
ignorecase=2))
|
host_platform,
|
||||||
opts.Add(EnumVariable('bits', 'Target platform bits', 'default', ('default', '32', '64')))
|
allowed_values=('linux', 'osx', 'windows'),
|
||||||
opts.Add(BoolVariable('use_llvm', 'Use the LLVM compiler - only effective when targeting Linux', False))
|
ignorecase=2
|
||||||
opts.Add(BoolVariable('use_mingw', 'Use the MinGW compiler - only effective on Windows', False))
|
))
|
||||||
|
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
|
||||||
|
))
|
||||||
# Must be the same setting as used for cpp_bindings
|
# Must be the same setting as used for cpp_bindings
|
||||||
opts.Add(EnumVariable('target', 'Compilation target', 'debug',
|
opts.Add(EnumVariable(
|
||||||
allowed_values=('debug', 'release'),
|
'target',
|
||||||
ignorecase=2))
|
'Compilation target',
|
||||||
opts.Add(PathVariable('headers_dir', 'Path to the directory containing Godot headers', 'godot_headers', PathVariable.PathIsDir))
|
'debug',
|
||||||
opts.Add(BoolVariable('use_custom_api_file', 'Use a custom JSON API file', False))
|
allowed_values=('debug', 'release'),
|
||||||
opts.Add(PathVariable('custom_api_file', 'Path to the custom JSON API file', None, PathVariable.PathIsFile))
|
ignorecase=2
|
||||||
opts.Add(BoolVariable('generate_bindings', 'Generate GDNative API bindings', False))
|
))
|
||||||
|
opts.Add(PathVariable(
|
||||||
unknown = opts.UnknownVariables()
|
'headers_dir',
|
||||||
if unknown:
|
'Path to the directory containing Godot headers',
|
||||||
print("Unknown variables:" + unknown.keys())
|
'godot_headers',
|
||||||
Exit(1)
|
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
|
||||||
|
))
|
||||||
|
|
||||||
env = Environment()
|
env = Environment()
|
||||||
opts.Update(env)
|
opts.Update(env)
|
||||||
Help(opts.GenerateHelpText(env))
|
Help(opts.GenerateHelpText(env))
|
||||||
|
|
||||||
# This makes sure to keep the session environment variables on Windows
|
is64 = sys.maxsize > 2**32
|
||||||
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find all the required tools
|
if (
|
||||||
if env['platform'] == 'windows':
|
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'
|
||||||
|
|
||||||
|
# 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':
|
||||||
if env['bits'] == '64':
|
if env['bits'] == '64':
|
||||||
env = Environment(TARGET_ARCH='amd64')
|
env = Environment(TARGET_ARCH='amd64')
|
||||||
elif env['bits'] == '32':
|
elif env['bits'] == '32':
|
||||||
env = Environment(TARGET_ARCH='x86')
|
env = Environment(TARGET_ARCH='x86')
|
||||||
else:
|
|
||||||
print("Warning: bits argument not specified, target arch is=" + env['TARGET_ARCH'])
|
|
||||||
opts.Update(env)
|
|
||||||
|
|
||||||
is64 = False
|
opts.Update(env)
|
||||||
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['platform'] == 'linux':
|
||||||
if env['use_llvm']:
|
if env['use_llvm']:
|
||||||
|
@ -82,11 +120,22 @@ if env['platform'] == 'linux':
|
||||||
env.Append(LINKFLAGS=['-m32'])
|
env.Append(LINKFLAGS=['-m32'])
|
||||||
|
|
||||||
elif env['platform'] == 'osx':
|
elif env['platform'] == 'osx':
|
||||||
|
# Use Clang on macOS by default
|
||||||
|
env['CXX'] = 'clang++'
|
||||||
|
|
||||||
if env['bits'] == '32':
|
if env['bits'] == '32':
|
||||||
raise ValueError('Only 64-bit builds are supported for the macOS target.')
|
raise ValueError(
|
||||||
|
'Only 64-bit builds are supported for the macOS target.'
|
||||||
|
)
|
||||||
|
|
||||||
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', 'x86_64'])
|
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', 'x86_64'])
|
||||||
env.Append(LINKFLAGS=['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
|
env.Append(LINKFLAGS=[
|
||||||
|
'-arch',
|
||||||
|
'x86_64',
|
||||||
|
'-framework',
|
||||||
|
'Cocoa',
|
||||||
|
'-Wl,-undefined,dynamic_lookup',
|
||||||
|
])
|
||||||
|
|
||||||
if env['target'] == 'debug':
|
if env['target'] == 'debug':
|
||||||
env.Append(CCFLAGS=['-Og'])
|
env.Append(CCFLAGS=['-Og'])
|
||||||
|
@ -101,40 +150,56 @@ elif env['platform'] == 'windows':
|
||||||
env.Append(CCFLAGS=['/EHsc', '/D_DEBUG', '/MDd'])
|
env.Append(CCFLAGS=['/EHsc', '/D_DEBUG', '/MDd'])
|
||||||
elif env['target'] == 'release':
|
elif env['target'] == 'release':
|
||||||
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD'])
|
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MD'])
|
||||||
else:
|
|
||||||
# MinGW
|
elif host_platform == 'linux':
|
||||||
|
# Cross-compilation using MinGW
|
||||||
if env['bits'] == '64':
|
if env['bits'] == '64':
|
||||||
env['CXX'] = 'x86_64-w64-mingw32-g++'
|
env['CXX'] = 'x86_64-w64-mingw32-g++'
|
||||||
elif env['bits'] == '32':
|
elif env['bits'] == '32':
|
||||||
env['CXX'] = 'i686-w64-mingw32-g++'
|
env['CXX'] = 'i686-w64-mingw32-g++'
|
||||||
|
|
||||||
|
# Native or cross-compilation using MinGW
|
||||||
|
if host_platform == 'linux' or env['use_mingw']:
|
||||||
env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings'])
|
env.Append(CCFLAGS=['-g', '-O3', '-std=c++14', '-Wwrite-strings'])
|
||||||
env.Append(LINKFLAGS=['--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++'])
|
env.Append(LINKFLAGS=[
|
||||||
|
'--static',
|
||||||
|
'-Wl,--no-undefined',
|
||||||
|
'-static-libgcc',
|
||||||
|
'-static-libstdc++',
|
||||||
|
])
|
||||||
|
|
||||||
|
env.Append(CPPPATH=[
|
||||||
env.Append(CPPPATH=['.', env['headers_dir'], 'include', 'include/gen', 'include/core'])
|
'.',
|
||||||
|
env['headers_dir'],
|
||||||
|
'include',
|
||||||
|
'include/gen',
|
||||||
|
'include/core',
|
||||||
|
])
|
||||||
|
|
||||||
# Generate bindings?
|
# Generate bindings?
|
||||||
json_api_file = ''
|
json_api_file = ''
|
||||||
|
|
||||||
if env['use_custom_api_file']:
|
if 'custom_api_file' in env:
|
||||||
json_api_file = env['custom_api_file']
|
json_api_file = env['custom_api_file']
|
||||||
else:
|
else:
|
||||||
json_api_file = os.path.join(os.getcwd(), 'godot_headers', 'api.json')
|
json_api_file = os.path.join(os.getcwd(), 'godot_headers', 'api.json')
|
||||||
|
|
||||||
if env['generate_bindings']:
|
if env['generate_bindings']:
|
||||||
# Actually create the bindings here
|
# Actually create the bindings here
|
||||||
|
|
||||||
import binding_generator
|
import binding_generator
|
||||||
|
|
||||||
binding_generator.generate_bindings(json_api_file)
|
binding_generator.generate_bindings(json_api_file)
|
||||||
|
|
||||||
# source to compile
|
# Sources to compile
|
||||||
sources = []
|
sources = []
|
||||||
add_sources(sources, 'src/core', 'cpp')
|
add_sources(sources, 'src/core', 'cpp')
|
||||||
add_sources(sources, 'src/gen', 'cpp')
|
add_sources(sources, 'src/gen', 'cpp')
|
||||||
|
|
||||||
library = env.StaticLibrary(
|
library = env.StaticLibrary(
|
||||||
target='bin/' + 'libgodot-cpp.{}.{}.{}'.format(env['platform'], env['target'], env['bits']), source=sources
|
target='bin/' + 'libgodot-cpp.{}.{}.{}'.format(
|
||||||
|
env['platform'],
|
||||||
|
env['target'],
|
||||||
|
env['bits'],
|
||||||
|
), source=sources
|
||||||
)
|
)
|
||||||
Default(library)
|
Default(library)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue