2017-04-03 14:11:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
Import('env')
|
|
|
|
|
2017-09-03 10:40:41 +00:00
|
|
|
gdn_env = env.Clone()
|
2017-10-03 03:23:05 +00:00
|
|
|
gdn_env.add_source_files(env.modules_sources, "gdnative.cpp")
|
|
|
|
gdn_env.add_source_files(env.modules_sources, "register_types.cpp")
|
2017-09-03 10:40:41 +00:00
|
|
|
gdn_env.add_source_files(env.modules_sources, "gdnative/*.cpp")
|
|
|
|
gdn_env.add_source_files(env.modules_sources, "nativescript/*.cpp")
|
2017-12-15 14:35:16 +00:00
|
|
|
gdn_env.add_source_files(env.modules_sources, "gdnative_library_singleton_editor.cpp")
|
|
|
|
gdn_env.add_source_files(env.modules_sources, "gdnative_library_editor_plugin.cpp")
|
2017-09-03 10:40:41 +00:00
|
|
|
|
|
|
|
gdn_env.Append(CPPPATH=['#modules/gdnative/include/'])
|
2017-04-03 14:11:38 +00:00
|
|
|
|
2017-11-10 11:36:50 +00:00
|
|
|
SConscript("arvr/SCsub")
|
2017-10-08 21:47:38 +00:00
|
|
|
SConscript("pluginscript/SCsub")
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-03 03:23:05 +00:00
|
|
|
def _spaced(e):
|
|
|
|
return e if e[-1] == '*' else e + ' '
|
|
|
|
|
|
|
|
def _build_gdnative_api_struct_header(api):
|
2017-11-21 19:09:08 +00:00
|
|
|
gdnative_api_init_macro = [
|
|
|
|
'\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;'
|
|
|
|
]
|
2017-11-16 21:05:47 +00:00
|
|
|
|
|
|
|
for name in api['extensions']:
|
2017-11-21 19:09:08 +00:00
|
|
|
gdnative_api_init_macro.append(
|
|
|
|
'\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name))
|
2017-11-16 21:05:47 +00:00
|
|
|
|
2017-11-21 19:09:08 +00:00
|
|
|
gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;')
|
|
|
|
gdnative_api_init_macro.append('\tfor (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ')
|
|
|
|
gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {')
|
2017-11-16 21:05:47 +00:00
|
|
|
|
|
|
|
for name in api['extensions']:
|
2017-11-21 19:09:08 +00:00
|
|
|
gdnative_api_init_macro.append(
|
|
|
|
'\t\t\tcase GDNATIVE_EXT_%s:' % api['extensions'][name]['type'])
|
|
|
|
gdnative_api_init_macro.append(
|
|
|
|
'\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)'
|
|
|
|
' _gdnative_wrapper_api_struct->extensions[i];'.format(name))
|
|
|
|
gdnative_api_init_macro.append('\t\t\t\tbreak;')
|
|
|
|
gdnative_api_init_macro.append('\t\t}')
|
|
|
|
gdnative_api_init_macro.append('\t}')
|
2017-11-16 21:05:47 +00:00
|
|
|
|
2017-10-03 03:23:05 +00:00
|
|
|
out = [
|
|
|
|
'/* THIS FILE IS GENERATED DO NOT EDIT */',
|
|
|
|
'#ifndef GODOT_GDNATIVE_API_STRUCT_H',
|
|
|
|
'#define GODOT_GDNATIVE_API_STRUCT_H',
|
|
|
|
'',
|
|
|
|
'#include <gdnative/gdnative.h>',
|
2017-11-10 11:36:50 +00:00
|
|
|
'#include <arvr/godot_arvr.h>',
|
2017-10-03 03:23:05 +00:00
|
|
|
'#include <nativescript/godot_nativescript.h>',
|
2017-10-08 21:47:38 +00:00
|
|
|
'#include <pluginscript/godot_pluginscript.h>',
|
2017-10-03 03:23:05 +00:00
|
|
|
'',
|
2017-11-21 19:09:08 +00:00
|
|
|
'#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)',
|
2017-10-03 21:07:29 +00:00
|
|
|
'',
|
2017-10-03 03:23:05 +00:00
|
|
|
'#ifdef __cplusplus',
|
|
|
|
'extern "C" {',
|
|
|
|
'#endif',
|
|
|
|
'',
|
2017-11-09 15:06:09 +00:00
|
|
|
'enum GDNATIVE_API_TYPES {',
|
|
|
|
'\tGDNATIVE_' + api['core']['type'] + ','
|
|
|
|
]
|
|
|
|
|
|
|
|
for name in api['extensions']:
|
2017-11-10 11:08:09 +00:00
|
|
|
out += ['\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',']
|
2017-11-09 15:06:09 +00:00
|
|
|
|
|
|
|
out += ['};', '']
|
|
|
|
|
|
|
|
for name in api['extensions']:
|
|
|
|
out += [
|
2017-11-10 11:08:09 +00:00
|
|
|
'typedef struct godot_gdnative_ext_' + name + '_api_struct {',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\tunsigned int type;',
|
2017-11-10 11:08:09 +00:00
|
|
|
'\tgodot_gdnative_api_version version;',
|
|
|
|
'\tconst godot_gdnative_api_struct *next;'
|
2017-11-09 15:06:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for funcdef in api['extensions'][name]['api']:
|
|
|
|
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
|
|
|
|
out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
|
|
|
|
|
2017-11-10 11:08:09 +00:00
|
|
|
out += ['} godot_gdnative_ext_' + name + '_api_struct;', '']
|
2017-11-09 15:06:09 +00:00
|
|
|
|
|
|
|
out += [
|
2017-11-10 11:08:09 +00:00
|
|
|
'typedef struct godot_gdnative_core_api_struct {',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\tunsigned int type;',
|
2017-11-10 11:08:09 +00:00
|
|
|
'\tgodot_gdnative_api_version version;',
|
|
|
|
'\tconst godot_gdnative_api_struct *next;',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\tunsigned int num_extensions;',
|
2017-11-10 11:08:09 +00:00
|
|
|
'\tconst godot_gdnative_api_struct **extensions;',
|
2017-10-03 03:23:05 +00:00
|
|
|
]
|
|
|
|
|
2017-11-09 15:06:09 +00:00
|
|
|
for funcdef in api['core']['api']:
|
2017-10-03 03:23:05 +00:00
|
|
|
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
|
2017-10-07 18:17:12 +00:00
|
|
|
out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
|
2017-10-03 03:23:05 +00:00
|
|
|
|
|
|
|
out += [
|
2017-11-10 11:08:09 +00:00
|
|
|
'} godot_gdnative_core_api_struct;',
|
2017-10-03 03:23:05 +00:00
|
|
|
'',
|
|
|
|
'#ifdef __cplusplus',
|
|
|
|
'}',
|
|
|
|
'#endif',
|
|
|
|
'',
|
|
|
|
'#endif // GODOT_GDNATIVE_API_STRUCT_H',
|
|
|
|
''
|
|
|
|
]
|
|
|
|
return '\n'.join(out)
|
|
|
|
|
|
|
|
def _build_gdnative_api_struct_source(api):
|
|
|
|
out = [
|
|
|
|
'/* THIS FILE IS GENERATED DO NOT EDIT */',
|
|
|
|
'',
|
|
|
|
'#include <gdnative_api_struct.gen.h>',
|
2017-11-09 15:06:09 +00:00
|
|
|
''
|
|
|
|
]
|
|
|
|
|
|
|
|
for name in api['extensions']:
|
|
|
|
out += [
|
2017-11-10 11:08:09 +00:00
|
|
|
'extern const godot_gdnative_ext_' + name + '_api_struct api_extension_' + name + '_struct = {',
|
|
|
|
'\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',',
|
|
|
|
'\t{' + str(api['extensions'][name]['version']['major']) + ', ' + str(api['extensions'][name]['version']['minor']) + '},',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\tNULL,'
|
|
|
|
]
|
|
|
|
|
|
|
|
for funcdef in api['extensions'][name]['api']:
|
|
|
|
out.append('\t%s,' % funcdef['name'])
|
|
|
|
|
|
|
|
out += ['};\n']
|
|
|
|
|
2017-11-10 11:08:09 +00:00
|
|
|
out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']
|
2017-11-09 15:06:09 +00:00
|
|
|
|
|
|
|
for name in api['extensions']:
|
2017-11-10 11:08:09 +00:00
|
|
|
out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
|
2017-11-09 15:06:09 +00:00
|
|
|
|
|
|
|
out += ['};\n']
|
|
|
|
|
|
|
|
out += [
|
2017-11-10 11:08:09 +00:00
|
|
|
'extern const godot_gdnative_core_api_struct api_struct = {',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\tGDNATIVE_' + api['core']['type'] + ',',
|
2017-11-10 11:08:09 +00:00
|
|
|
'\t{' + str(api['core']['version']['major']) + ', ' + str(api['core']['version']['minor']) + '},',
|
2017-10-04 01:11:41 +00:00
|
|
|
'\tNULL,',
|
2017-11-09 15:06:09 +00:00
|
|
|
'\t' + str(len(api['extensions'])) + ',',
|
|
|
|
'\tgdnative_extensions_pointers,',
|
2017-10-03 03:23:05 +00:00
|
|
|
]
|
|
|
|
|
2017-11-09 15:06:09 +00:00
|
|
|
for funcdef in api['core']['api']:
|
2017-10-07 18:17:12 +00:00
|
|
|
out.append('\t%s,' % funcdef['name'])
|
2017-10-03 03:23:05 +00:00
|
|
|
out.append('};\n')
|
|
|
|
|
|
|
|
return '\n'.join(out)
|
|
|
|
|
|
|
|
def build_gdnative_api_struct(target, source, env):
|
|
|
|
import json
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
with open(source[0].path, 'r') as fd:
|
2017-10-07 18:17:12 +00:00
|
|
|
api = json.load(fd)
|
2017-10-03 03:23:05 +00:00
|
|
|
|
|
|
|
header, source = target
|
|
|
|
with open(header.path, 'w') as fd:
|
|
|
|
fd.write(_build_gdnative_api_struct_header(api))
|
|
|
|
with open(source.path, 'w') as fd:
|
|
|
|
fd.write(_build_gdnative_api_struct_source(api))
|
|
|
|
|
|
|
|
_, gensource = gdn_env.Command(['include/gdnative_api_struct.gen.h', 'gdnative_api_struct.gen.cpp'],
|
|
|
|
'gdnative_api.json', build_gdnative_api_struct)
|
|
|
|
gdn_env.add_source_files(env.modules_sources, [gensource])
|
|
|
|
|
2017-08-02 12:21:12 +00:00
|
|
|
env.use_ptrcall = True
|
2017-10-03 21:07:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _build_gdnative_wrapper_code(api):
|
|
|
|
out = [
|
|
|
|
'/* THIS FILE IS GENERATED DO NOT EDIT */',
|
|
|
|
'',
|
|
|
|
'#include <gdnative/gdnative.h>',
|
|
|
|
'#include <nativescript/godot_nativescript.h>',
|
2017-10-08 21:47:38 +00:00
|
|
|
'#include <pluginscript/godot_pluginscript.h>',
|
2017-11-16 21:05:47 +00:00
|
|
|
'#include <arvr/godot_arvr.h>',
|
2017-10-03 21:07:29 +00:00
|
|
|
'',
|
|
|
|
'#include <gdnative_api_struct.gen.h>',
|
|
|
|
'',
|
|
|
|
'#ifdef __cplusplus',
|
|
|
|
'extern "C" {',
|
|
|
|
'#endif',
|
2017-11-16 21:05:47 +00:00
|
|
|
'',
|
|
|
|
'godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;',
|
2017-10-03 21:07:29 +00:00
|
|
|
]
|
|
|
|
|
2017-11-16 21:05:47 +00:00
|
|
|
for name in api['extensions']:
|
2017-11-21 19:09:08 +00:00
|
|
|
out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;')
|
2017-11-16 21:05:47 +00:00
|
|
|
|
|
|
|
out += ['']
|
|
|
|
|
|
|
|
for funcdef in api['core']['api']:
|
2017-10-03 21:07:29 +00:00
|
|
|
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
|
2017-10-08 18:51:18 +00:00
|
|
|
out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args))
|
2017-10-03 21:07:29 +00:00
|
|
|
|
|
|
|
args = ', '.join(['%s' % n for t, n in funcdef['arguments']])
|
|
|
|
|
|
|
|
return_line = '\treturn ' if funcdef['return_type'] != 'void' else '\t'
|
2017-10-07 18:17:12 +00:00
|
|
|
return_line += '_gdnative_wrapper_api_struct->' + funcdef['name'] + '(' + args + ');'
|
2017-10-03 21:07:29 +00:00
|
|
|
|
|
|
|
out.append(return_line)
|
|
|
|
out.append('}')
|
|
|
|
out.append('')
|
|
|
|
|
2017-11-16 21:05:47 +00:00
|
|
|
for name in api['extensions']:
|
|
|
|
for funcdef in api['extensions'][name]['api']:
|
|
|
|
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
|
|
|
|
out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args))
|
|
|
|
|
|
|
|
args = ', '.join(['%s' % n for t, n in funcdef['arguments']])
|
|
|
|
|
|
|
|
return_line = '\treturn ' if funcdef['return_type'] != 'void' else '\t'
|
|
|
|
return_line += '_gdnative_wrapper_' + name + '_api_struct->' + funcdef['name'] + '(' + args + ');'
|
|
|
|
|
|
|
|
out.append(return_line)
|
|
|
|
out.append('}')
|
|
|
|
out.append('')
|
|
|
|
|
2017-10-03 21:07:29 +00:00
|
|
|
out += [
|
|
|
|
'#ifdef __cplusplus',
|
|
|
|
'}',
|
|
|
|
'#endif'
|
|
|
|
]
|
|
|
|
|
|
|
|
return '\n'.join(out)
|
|
|
|
|
|
|
|
|
|
|
|
def build_gdnative_wrapper_code(target, source, env):
|
|
|
|
import json
|
|
|
|
with open(source[0].path, 'r') as fd:
|
|
|
|
api = json.load(fd)
|
|
|
|
|
|
|
|
wrapper_file = target[0]
|
|
|
|
with open(wrapper_file.path, 'w') as fd:
|
|
|
|
fd.write(_build_gdnative_wrapper_code(api))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ARGUMENTS.get('gdnative_wrapper', False):
|
|
|
|
#build wrapper code
|
2017-10-08 18:51:18 +00:00
|
|
|
gensource, = gdn_env.Command('gdnative_wrapper_code.gen.cpp', 'gdnative_api.json', build_gdnative_wrapper_code)
|
2017-10-03 21:07:29 +00:00
|
|
|
|
|
|
|
gd_wrapper_env = env.Clone()
|
|
|
|
gd_wrapper_env.Append(CPPPATH=['#modules/gdnative/include/'])
|
|
|
|
|
2018-01-04 18:42:02 +00:00
|
|
|
if gd_wrapper_env['use_lto']:
|
|
|
|
if not env.msvc:
|
2018-04-29 22:52:42 +00:00
|
|
|
gd_wrapper_env.Append(CCFLAGS=['-fno-lto'])
|
|
|
|
gd_wrapper_env.Append(LINKFLAGS=['-fno-lto'])
|
2018-01-04 18:42:02 +00:00
|
|
|
else:
|
|
|
|
gd_wrapper_env.Append(CCFLAGS=['/GL-'])
|
|
|
|
gd_wrapper_env.Append(LINKFLAGS=['/LTCG:OFF'])
|
|
|
|
|
2017-11-25 19:26:42 +00:00
|
|
|
if not env.msvc:
|
|
|
|
gd_wrapper_env.Append(CCFLAGS=['-fPIC'])
|
2017-10-03 21:07:29 +00:00
|
|
|
|
2017-11-28 20:27:57 +00:00
|
|
|
lib = gd_wrapper_env.add_library("#bin/gdnative_wrapper_code", [gensource])
|