#!/usr/bin/env python import sys import importlib import os import platform import errno from SCons.Script import Configure godot_headers_files_subset = [ 'README.md', os.path.join('gdnative', 'aabb.h'), os.path.join('gdnative', 'color.h'), os.path.join('gdnative', 'node_path.h'), os.path.join('gdnative', 'quat.h'), os.path.join('gdnative', 'string.h'), os.path.join('gdnative', 'transform.h'), os.path.join('gdnative', 'vector3.h'), os.path.join('gdnative', 'array.h'), os.path.join('gdnative', 'dictionary.h'), os.path.join('gdnative', 'plane.h'), os.path.join('gdnative', 'rect2.h'), os.path.join('gdnative', 'string_name.h'), os.path.join('gdnative', 'variant.h'), os.path.join('gdnative', 'basis.h'), os.path.join('gdnative', 'gdnative.h'), os.path.join('gdnative', 'pool_arrays.h'), os.path.join('gdnative', 'rid.h'), os.path.join('gdnative', 'transform2d.h'), os.path.join('gdnative', 'vector2.h') ] # ----------------------------------------------------------------------------------------------- # def check_godot_headers_directory(environment, godot_cpp_directory): """Verifies that the godot_headers directory inside the Godot-CPP directory has been downloaded as a git submodule and is complete. @param godot_cpp_directory Directory into which Godot-CPP was checked out @returns True if the godot_headers subdirectory is complete, False otherwise""" configure_godot_headers = Configure(environment) godot_headers_directory = os.path.join(godot_cpp_directory, 'godot_headers') is_complete = True for file in godot_headers_files_subset: file_path = os.path.join(godot_headers_directory, file) if not os.path.isfile(file_path): is_complete = False #if not configure_godot_headers.CheckCXXHeader(file_path): # is_complete = False if is_complete: print("\033[92mGodot-CPP appears to be complete, with godot_headers submodule\033[0m") else: print("\033[95mERROR: The godot_headers directory seems to be incomplete.\033[0m") print("\033[95m This is a git submodule of Godot-CPP and needs to be\033[0m") print("\033[95m checked out together with Godot-CPP. Please repeat the\033[0m") print("\033[95m clone of the template with --recurse-submodules\033[0m") #Exit(1) raise FileNotFoundError( errno.ENOENT, 'Missing godot_headers directory. Incomplete git checkout?', os.path.join(godot_cpp_directory, 'godot_headers') ) # ----------------------------------------------------------------------------------------------- # def generate_gdnative_api_json(environment, godot_cpp_directory): """Exports the api.json file required by the Godot-CPP build script @param environment Environment used to call the Godot executable @param godot_cpp_directory Directory holding the Godot-CPP library @returns The api.json target generated by running the export""" api_json_path = os.path.join(godot_cpp_directory, 'godot_headers', 'api.json') return environment.call_godot( source = [], arguments = '--gdnative-generate-json-api $TARGET', target = api_json_path ) # ----------------------------------------------------------------------------------------------- # def compile(environment, godot_cpp_directory): """Compiles the Godot-CPP library @param environment Environment used for the build settings to Godot-CPP @param godot_cpp_directory Directory holding the Godot-CPP library @return A scons list of target created by the build""" if platform.system() == 'Windows': godot_cpp_platform = 'windows' else: godot_cpp_platform = 'linux' if environment.is_debug_build(): godot_cpp_build_type = 'debug' else: godot_cpp_build_type = 'release' additional_arguments = ( ' platform=' + godot_cpp_platform + ' target=' + godot_cpp_build_type + ' generate_bindings=yes' ) input_files_subset = [] godot_headers_directory = os.path.join(godot_cpp_directory, 'godot_headers') for file in godot_headers_files_subset: input_files_subset.append(os.path.join(godot_headers_directory, file)) input_files_subset.append(os.path.join(godot_cpp_directory, 'godot_headers', 'api.json')) sconstruct_file_path = os.path.join(godot_cpp_directory, 'SConstruct') input_files_subset.append(sconstruct_file_path) godot_cpp_library_path = os.path.join( godot_cpp_directory, 'bin', _get_godot_cpp_library_name(environment) ) return environment.build_scons( source = input_files_subset, arguments = '-j8 --directory=' + godot_cpp_directory + ' bits=64' + additional_arguments, target = godot_cpp_library_path ) # ----------------------------------------------------------------------------------------------- # def add_package(environment, godot_cpp_directory): """Adds the Godot-CPP package to the build (setting up all necessary include directories, library directories and linking the appropriate static library of godot-cpp. @param environment Environment to which the Godot-CPP package will be added.""" # ASSUMPTION: The passed environment is a Nuclex C++ environment created with # the nuclex.create_cplusplus_environment() helper method. # Include directories for Godot, its C++ headers and the Godot-CPP library environment.add_include_directory(os.path.join(godot_cpp_directory, 'godot_headers')) environment.add_include_directory(os.path.join(godot_cpp_directory, 'include')) environment.add_include_directory(os.path.join(godot_cpp_directory, 'include', 'core')) environment.add_include_directory(os.path.join(godot_cpp_directory, 'include', 'gen')) # Library directory environment.add_library_directory(os.path.join(godot_cpp_directory, 'bin')) environment.Append(LIBS=[_get_godot_cpp_library_name(environment)]) # ----------------------------------------------------------------------------------------------- # def _get_godot_cpp_library_name(environment): """Returns the name of the Godot-CPP static library that would get built for the current platform and build type (debug/release) @param environment Environment under which the Godot-CPP library name will be checked""" if platform.system() == 'Windows': if environment.is_debug_build(): return 'libgodot-cpp.windows.debug.64.lib' else: return 'libgodot-cpp.windows.release.64.lib' else: if environment.is_debug_build(): return 'godot-cpp.linux.debug.64' else: return 'godot-cpp.linux.release.64'