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
|
2019-11-26 19:26:06 +00:00
|
|
|
import subprocess
|
2022-04-30 13:49:51 +00:00
|
|
|
from binding_generator import scons_generate_bindings, scons_emit_files
|
2019-11-26 19:26:06 +00:00
|
|
|
|
|
|
|
if sys.version_info < (3,):
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2019-11-26 19:26:06 +00:00
|
|
|
def decode_utf8(x):
|
|
|
|
return x
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2019-11-26 19:26:06 +00:00
|
|
|
else:
|
|
|
|
import codecs
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2019-11-26 19:26:06 +00:00
|
|
|
def decode_utf8(x):
|
|
|
|
return codecs.utf_8_decode(x)[0]
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
# Workaround for MinGW. See:
|
|
|
|
# http://www.scons.org/wiki/LongCmdLinesOnWin32
|
2021-04-25 19:24:38 +00:00
|
|
|
if os.name == "nt":
|
2019-08-21 08:03:49 +00:00
|
|
|
import subprocess
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
def mySubProcess(cmdline, env):
|
|
|
|
# print "SPAWNED : " + cmdline
|
2019-08-21 08:03:49 +00:00
|
|
|
startupinfo = subprocess.STARTUPINFO()
|
|
|
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
2021-08-18 14:03:52 +00:00
|
|
|
proc = subprocess.Popen(
|
|
|
|
cmdline,
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
startupinfo=startupinfo,
|
|
|
|
shell=False,
|
|
|
|
env=env,
|
|
|
|
)
|
2019-08-21 08:03:49 +00:00
|
|
|
data, err = proc.communicate()
|
|
|
|
rv = proc.wait()
|
|
|
|
if rv:
|
|
|
|
print("=====")
|
|
|
|
print(err.decode("utf-8"))
|
|
|
|
print("=====")
|
|
|
|
return rv
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
def mySpawn(sh, escape, cmd, args, env):
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
newargs = " ".join(args[1:])
|
2019-08-21 08:03:49 +00:00
|
|
|
cmdline = cmd + " " + newargs
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
rv = 0
|
|
|
|
if len(cmdline) > 32000 and cmd.endswith("ar"):
|
2019-08-21 08:03:49 +00:00
|
|
|
cmdline = cmd + " " + args[1] + " " + args[2] + " "
|
2021-08-18 14:03:52 +00:00
|
|
|
for i in range(3, len(args)):
|
|
|
|
rv = mySubProcess(cmdline + args[i], env)
|
|
|
|
if rv:
|
2019-12-15 22:13:19 +00:00
|
|
|
break
|
|
|
|
else:
|
2021-08-18 14:03:52 +00:00
|
|
|
rv = mySubProcess(cmdline, env)
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
return rv
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2021-08-18 14:03:52 +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):
|
2021-08-18 14:03:52 +00:00
|
|
|
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
|
2021-08-18 14:03:52 +00:00
|
|
|
if sys.platform.startswith("linux"):
|
|
|
|
host_platform = "linux"
|
|
|
|
elif sys.platform.startswith("freebsd"):
|
|
|
|
host_platform = "freebsd"
|
|
|
|
elif sys.platform == "darwin":
|
|
|
|
host_platform = "osx"
|
|
|
|
elif sys.platform == "win32" or sys.platform == "msys":
|
|
|
|
host_platform = "windows"
|
2018-08-16 14:14:35 +00:00
|
|
|
else:
|
2021-09-29 20:19:36 +00:00
|
|
|
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
env = Environment(ENV=os.environ)
|
2020-03-30 21:58:20 +00:00
|
|
|
|
2022-05-02 19:13:56 +00:00
|
|
|
is64 = sys.maxsize > 2**32
|
2020-03-30 21:58:20 +00:00
|
|
|
if (
|
2021-08-18 14:03:52 +00:00
|
|
|
env["TARGET_ARCH"] == "amd64"
|
|
|
|
or env["TARGET_ARCH"] == "emt64"
|
|
|
|
or env["TARGET_ARCH"] == "x86_64"
|
|
|
|
or env["TARGET_ARCH"] == "arm64-v8a"
|
2020-03-30 21:58:20 +00:00
|
|
|
):
|
|
|
|
is64 = True
|
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
opts = Variables([], ARGUMENTS)
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(
|
|
|
|
EnumVariable(
|
|
|
|
"platform",
|
|
|
|
"Target platform",
|
|
|
|
host_platform,
|
|
|
|
allowed_values=("linux", "freebsd", "osx", "windows", "android", "ios", "javascript"),
|
|
|
|
ignorecase=2,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
opts.Add(EnumVariable("bits", "Target platform bits", "64" if is64 else "32", ("32", "64")))
|
|
|
|
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux or FreeBSD", 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
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(EnumVariable("target", "Compilation target", "debug", allowed_values=("debug", "release"), ignorecase=2))
|
2020-12-03 20:30:59 +00:00
|
|
|
opts.Add(
|
2021-08-18 14:03:52 +00:00
|
|
|
PathVariable(
|
2021-09-27 11:04:56 +00:00
|
|
|
"headers_dir", "Path to the directory containing Godot headers", "godot-headers", PathVariable.PathIsDir
|
2021-08-18 14:03:52 +00:00
|
|
|
)
|
2020-12-03 20:30:59 +00:00
|
|
|
)
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(PathVariable("custom_api_file", "Path to a custom JSON API file", None, PathVariable.PathIsFile))
|
2021-07-05 14:07:55 +00:00
|
|
|
opts.Add(
|
2022-04-30 13:49:51 +00:00
|
|
|
BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False)
|
2021-07-05 14:07:55 +00:00
|
|
|
)
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(EnumVariable("android_arch", "Target Android architecture", "armv7", ["armv7", "arm64v8", "x86", "x86_64"]))
|
|
|
|
opts.Add("macos_deployment_target", "macOS deployment target", "default")
|
|
|
|
opts.Add("macos_sdk_path", "macOS SDK path", "")
|
2021-09-29 20:19:36 +00:00
|
|
|
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"]))
|
2022-02-10 14:18:22 +00:00
|
|
|
opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["universal", "arm64", "x86_64"]))
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
|
2019-11-26 19:26:06 +00:00
|
|
|
opts.Add(
|
2021-08-18 14:03:52 +00:00
|
|
|
"IPHONEPATH",
|
|
|
|
"Path to iPhone toolchain",
|
|
|
|
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain",
|
2019-11-26 19:26:06 +00:00
|
|
|
)
|
2019-08-21 08:03:49 +00:00
|
|
|
opts.Add(
|
2021-08-18 14:03:52 +00:00
|
|
|
"android_api_level",
|
|
|
|
"Target Android API level",
|
|
|
|
"18" if ARGUMENTS.get("android_arch", "armv7") in ["armv7", "x86"] else "21",
|
2019-08-21 08:03:49 +00:00
|
|
|
)
|
|
|
|
opts.Add(
|
2021-08-18 14:03:52 +00:00
|
|
|
"ANDROID_NDK_ROOT",
|
|
|
|
"Path to your Android NDK installation. By default, uses ANDROID_NDK_ROOT from your defined environment variables.",
|
|
|
|
os.environ.get("ANDROID_NDK_ROOT", None),
|
2019-08-21 08:03:49 +00:00
|
|
|
)
|
2021-08-18 14:03:52 +00:00
|
|
|
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2021-09-30 02:29:42 +00:00
|
|
|
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
|
2022-03-20 16:19:27 +00:00
|
|
|
opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64")))
|
2021-09-30 02:29:42 +00:00
|
|
|
|
2018-08-16 14:14:35 +00:00
|
|
|
opts.Update(env)
|
|
|
|
Help(opts.GenerateHelpText(env))
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2021-11-23 21:41:52 +00:00
|
|
|
# Detect and print a warning listing unknown SCons variables to ease troubleshooting.
|
|
|
|
unknown = opts.UnknownVariables()
|
|
|
|
if unknown:
|
|
|
|
print("WARNING: Unknown SCons variables were passed and will be ignored:")
|
|
|
|
for item in unknown.items():
|
|
|
|
print(" " + item[0] + "=" + item[1])
|
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
# 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
|
2021-08-18 14:03:52 +00:00
|
|
|
if host_platform == "windows" and env["platform"] != "android":
|
|
|
|
if env["bits"] == "64":
|
|
|
|
env = Environment(TARGET_ARCH="amd64")
|
|
|
|
elif env["bits"] == "32":
|
|
|
|
env = Environment(TARGET_ARCH="x86")
|
2018-10-25 16:35:33 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
opts.Update(env)
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2021-09-29 21:00:24 +00:00
|
|
|
# Require C++17
|
|
|
|
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
|
|
|
|
# MSVC
|
2022-02-16 11:12:10 +00:00
|
|
|
env.Append(CXXFLAGS=["/std:c++17"])
|
2021-09-29 21:00:24 +00:00
|
|
|
else:
|
2022-02-16 11:12:10 +00:00
|
|
|
env.Append(CXXFLAGS=["-std=c++17"])
|
2021-09-29 21:00:24 +00:00
|
|
|
|
2021-08-19 17:47:56 +00:00
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
|
|
|
|
|
2022-03-20 16:19:27 +00:00
|
|
|
if env["float"] == "64":
|
|
|
|
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["platform"] == "linux" or env["platform"] == "freebsd":
|
|
|
|
if env["use_llvm"]:
|
|
|
|
env["CXX"] = "clang++"
|
2018-02-25 16:03:55 +00:00
|
|
|
|
2021-09-29 21:00:24 +00:00
|
|
|
env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
|
2019-08-05 20:13:23 +00:00
|
|
|
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["-Og", "-g"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["-O3"])
|
2019-08-05 20:13:23 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["bits"] == "64":
|
|
|
|
env.Append(CCFLAGS=["-m64"])
|
|
|
|
env.Append(LINKFLAGS=["-m64"])
|
|
|
|
elif env["bits"] == "32":
|
|
|
|
env.Append(CCFLAGS=["-m32"])
|
|
|
|
env.Append(LINKFLAGS=["-m32"])
|
2019-08-05 20:13:23 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
elif env["platform"] == "osx":
|
2019-03-26 23:51:51 +00:00
|
|
|
# Use Clang on macOS by default
|
2021-08-18 14:03:52 +00:00
|
|
|
env["CXX"] = "clang++"
|
2019-03-26 23:51:51 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["bits"] == "32":
|
|
|
|
raise ValueError("Only 64-bit builds are supported for the macOS target.")
|
|
|
|
|
2021-09-29 20:19:36 +00:00
|
|
|
if env["macos_arch"] == "universal":
|
|
|
|
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
|
|
|
|
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["macos_deployment_target"] != "default":
|
|
|
|
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
|
|
|
|
env.Append(LINKFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
|
2018-08-16 14:14:35 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["macos_sdk_path"]:
|
|
|
|
env.Append(CCFLAGS=["-isysroot", env["macos_sdk_path"]])
|
|
|
|
env.Append(LINKFLAGS=["-isysroot", env["macos_sdk_path"]])
|
|
|
|
|
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-framework",
|
|
|
|
"Cocoa",
|
|
|
|
"-Wl,-undefined,dynamic_lookup",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["-Og", "-g"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["-O3"])
|
|
|
|
|
|
|
|
elif env["platform"] == "ios":
|
|
|
|
if env["ios_simulator"]:
|
|
|
|
sdk_name = "iphonesimulator"
|
|
|
|
env.Append(CCFLAGS=["-mios-simulator-version-min=10.0"])
|
2019-11-26 19:26:06 +00:00
|
|
|
else:
|
2021-08-18 14:03:52 +00:00
|
|
|
sdk_name = "iphoneos"
|
|
|
|
env.Append(CCFLAGS=["-miphoneos-version-min=10.0"])
|
2019-11-26 19:26:06 +00:00
|
|
|
|
|
|
|
try:
|
2021-08-18 14:03:52 +00:00
|
|
|
sdk_path = decode_utf8(subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-path"]).strip())
|
2019-11-26 19:26:06 +00:00
|
|
|
except (subprocess.CalledProcessError, OSError):
|
|
|
|
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
compiler_path = env["IPHONEPATH"] + "/usr/bin/"
|
|
|
|
env["ENV"]["PATH"] = env["IPHONEPATH"] + "/Developer/usr/bin/:" + env["ENV"]["PATH"]
|
|
|
|
|
|
|
|
env["CC"] = compiler_path + "clang"
|
|
|
|
env["CXX"] = compiler_path + "clang++"
|
|
|
|
env["AR"] = compiler_path + "ar"
|
|
|
|
env["RANLIB"] = compiler_path + "ranlib"
|
2021-09-30 02:29:42 +00:00
|
|
|
env["SHLIBSUFFIX"] = ".dylib"
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-02-10 14:18:22 +00:00
|
|
|
if env["ios_arch"] == "universal":
|
|
|
|
if env["ios_simulator"]:
|
|
|
|
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", "arm64"])
|
|
|
|
env.Append(CCFLAGS=["-arch", "arm64"])
|
|
|
|
else:
|
|
|
|
env.Append(LINKFLAGS=["-arch", env["ios_arch"]])
|
|
|
|
env.Append(CCFLAGS=["-arch", env["ios_arch"]])
|
|
|
|
|
|
|
|
env.Append(CCFLAGS=["-isysroot", sdk_path])
|
2022-02-26 20:45:00 +00:00
|
|
|
env.Append(LINKFLAGS=["-isysroot", sdk_path, "-F" + sdk_path])
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["-Og", "-g"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["-O3"])
|
|
|
|
|
|
|
|
elif env["platform"] == "windows":
|
|
|
|
if host_platform == "windows" and not env["use_mingw"]:
|
2018-08-16 14:14:35 +00:00
|
|
|
# MSVC
|
2021-08-21 11:50:22 +00:00
|
|
|
env.Append(CPPDEFINES=["TYPED_METHOD_BIND"])
|
2021-08-18 14:03:52 +00:00
|
|
|
env.Append(LINKFLAGS=["/WX"])
|
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["/Z7", "/Od", "/EHsc", "/D_DEBUG", "/MDd"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["/O2", "/EHsc", "/DNDEBUG", "/MD"])
|
2019-03-26 23:51:51 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
elif host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx":
|
2019-03-26 23:51:51 +00:00
|
|
|
# Cross-compilation using MinGW
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["bits"] == "64":
|
|
|
|
env["CXX"] = "x86_64-w64-mingw32-g++"
|
|
|
|
env["AR"] = "x86_64-w64-mingw32-ar"
|
|
|
|
env["RANLIB"] = "x86_64-w64-mingw32-ranlib"
|
|
|
|
env["LINK"] = "x86_64-w64-mingw32-g++"
|
|
|
|
elif env["bits"] == "32":
|
|
|
|
env["CXX"] = "i686-w64-mingw32-g++"
|
|
|
|
env["AR"] = "i686-w64-mingw32-ar"
|
|
|
|
env["RANLIB"] = "i686-w64-mingw32-ranlib"
|
|
|
|
env["LINK"] = "i686-w64-mingw32-g++"
|
|
|
|
|
|
|
|
elif host_platform == "windows" and env["use_mingw"]:
|
2021-01-31 22:59:11 +00:00
|
|
|
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
|
2021-08-18 14:03:52 +00:00
|
|
|
env = Environment(ENV=os.environ, tools=["mingw"])
|
2021-01-31 22:59:11 +00:00
|
|
|
opts.Update(env)
|
2021-09-29 21:00:24 +00:00
|
|
|
|
|
|
|
# Still need to use C++17.
|
|
|
|
env.Append(CCFLAGS=["-std=c++17"])
|
2021-09-30 02:29:42 +00:00
|
|
|
# Don't want lib prefixes
|
|
|
|
env["IMPLIBPREFIX"] = ""
|
|
|
|
env["SHLIBPREFIX"] = ""
|
2021-01-31 22:59:11 +00:00
|
|
|
|
2021-09-30 02:29:42 +00:00
|
|
|
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
|
2019-12-15 22:13:19 +00:00
|
|
|
env["SPAWN"] = mySpawn
|
2021-09-30 02:29:42 +00:00
|
|
|
env.Replace(ARFLAGS=["q"])
|
2018-04-08 16:00:54 +00:00
|
|
|
|
2019-03-26 23:51:51 +00:00
|
|
|
# Native or cross-compilation using MinGW
|
2021-08-18 14:03:52 +00:00
|
|
|
if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env["use_mingw"]:
|
2020-09-04 23:06:51 +00:00
|
|
|
# These options are for a release build even using target=debug
|
2021-09-29 21:00:24 +00:00
|
|
|
env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
|
2021-08-18 14:03:52 +00:00
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"--static",
|
|
|
|
"-Wl,--no-undefined",
|
|
|
|
"-static-libgcc",
|
|
|
|
"-static-libstdc++",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
elif env["platform"] == "android":
|
|
|
|
if host_platform == "windows":
|
2021-01-31 22:59:11 +00:00
|
|
|
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
|
2021-08-18 14:03:52 +00:00
|
|
|
env = Environment(ENV=os.environ, tools=["mingw"])
|
2021-01-31 22:59:11 +00:00
|
|
|
opts.Update(env)
|
|
|
|
|
2021-09-30 02:29:42 +00:00
|
|
|
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
|
2019-08-21 08:03:49 +00:00
|
|
|
env["SPAWN"] = mySpawn
|
2021-09-30 02:29:42 +00:00
|
|
|
env.Replace(ARFLAGS=["q"])
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
# Verify NDK root
|
2021-08-18 14:03:52 +00:00
|
|
|
if not "ANDROID_NDK_ROOT" in env:
|
|
|
|
raise ValueError(
|
|
|
|
"To build for Android, ANDROID_NDK_ROOT must be defined. Please set ANDROID_NDK_ROOT to the root folder of your Android NDK installation."
|
|
|
|
)
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
# Validate API level
|
2021-08-18 14:03:52 +00:00
|
|
|
api_level = int(env["android_api_level"])
|
|
|
|
if env["android_arch"] in ["x86_64", "arm64v8"] and api_level < 21:
|
2019-08-21 08:03:49 +00:00
|
|
|
print("WARN: 64-bit Android architectures require an API level of at least 21; setting android_api_level=21")
|
2021-08-18 14:03:52 +00:00
|
|
|
env["android_api_level"] = "21"
|
2019-08-21 08:03:49 +00:00
|
|
|
api_level = 21
|
2019-12-15 22:13:19 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
# Setup toolchain
|
2021-08-18 14:03:52 +00:00
|
|
|
toolchain = env["ANDROID_NDK_ROOT"] + "/toolchains/llvm/prebuilt/"
|
2019-08-21 08:03:49 +00:00
|
|
|
if host_platform == "windows":
|
|
|
|
toolchain += "windows"
|
|
|
|
import platform as pltfm
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2019-08-21 08:03:49 +00:00
|
|
|
if pltfm.machine().endswith("64"):
|
|
|
|
toolchain += "-x86_64"
|
|
|
|
elif host_platform == "linux":
|
|
|
|
toolchain += "linux-x86_64"
|
|
|
|
elif host_platform == "osx":
|
|
|
|
toolchain += "darwin-x86_64"
|
2021-08-18 14:03:52 +00:00
|
|
|
env.PrependENVPath("PATH", toolchain + "/bin") # This does nothing half of the time, but we'll put it here anyways
|
2019-08-21 08:03:49 +00:00
|
|
|
|
|
|
|
# Get architecture info
|
|
|
|
arch_info_table = {
|
2021-08-18 14:03:52 +00:00
|
|
|
"armv7": {
|
|
|
|
"march": "armv7-a",
|
|
|
|
"target": "armv7a-linux-androideabi",
|
|
|
|
"tool_path": "arm-linux-androideabi",
|
|
|
|
"compiler_path": "armv7a-linux-androideabi",
|
|
|
|
"ccflags": ["-mfpu=neon"],
|
|
|
|
},
|
|
|
|
"arm64v8": {
|
|
|
|
"march": "armv8-a",
|
|
|
|
"target": "aarch64-linux-android",
|
|
|
|
"tool_path": "aarch64-linux-android",
|
|
|
|
"compiler_path": "aarch64-linux-android",
|
|
|
|
"ccflags": [],
|
|
|
|
},
|
|
|
|
"x86": {
|
|
|
|
"march": "i686",
|
|
|
|
"target": "i686-linux-android",
|
|
|
|
"tool_path": "i686-linux-android",
|
|
|
|
"compiler_path": "i686-linux-android",
|
|
|
|
"ccflags": ["-mstackrealign"],
|
|
|
|
},
|
|
|
|
"x86_64": {
|
|
|
|
"march": "x86-64",
|
|
|
|
"target": "x86_64-linux-android",
|
|
|
|
"tool_path": "x86_64-linux-android",
|
|
|
|
"compiler_path": "x86_64-linux-android",
|
|
|
|
"ccflags": [],
|
|
|
|
},
|
2019-08-21 08:03:49 +00:00
|
|
|
}
|
2021-08-18 14:03:52 +00:00
|
|
|
arch_info = arch_info_table[env["android_arch"]]
|
2019-08-21 08:03:49 +00:00
|
|
|
|
|
|
|
# Setup tools
|
2021-08-18 14:03:52 +00:00
|
|
|
env["CC"] = toolchain + "/bin/clang"
|
|
|
|
env["CXX"] = toolchain + "/bin/clang++"
|
|
|
|
env["AR"] = toolchain + "/bin/" + arch_info["tool_path"] + "-ar"
|
2021-09-30 02:29:42 +00:00
|
|
|
env["SHLIBSUFFIX"] = ".so"
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
env.Append(
|
|
|
|
CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"]
|
|
|
|
) # , '-fPIE', '-fno-addrsig', '-Oz'])
|
|
|
|
env.Append(CCFLAGS=arch_info["ccflags"])
|
2021-09-30 02:29:42 +00:00
|
|
|
env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["-Og", "-g"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["-O3"])
|
2021-07-05 13:45:51 +00:00
|
|
|
|
2020-12-03 19:57:58 +00:00
|
|
|
elif env["platform"] == "javascript":
|
2022-04-30 21:35:42 +00:00
|
|
|
if host_platform == "windows":
|
|
|
|
env = Environment(ENV=os.environ, tools=["cc", "c++", "ar", "link", "textfile", "zip"])
|
|
|
|
opts.Update(env)
|
|
|
|
else:
|
|
|
|
env["ENV"] = os.environ
|
|
|
|
|
2020-12-03 19:57:58 +00:00
|
|
|
env["CC"] = "emcc"
|
|
|
|
env["CXX"] = "em++"
|
|
|
|
env["AR"] = "emar"
|
|
|
|
env["RANLIB"] = "emranlib"
|
|
|
|
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])
|
|
|
|
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])
|
|
|
|
env["SHOBJSUFFIX"] = ".bc"
|
|
|
|
env["SHLIBSUFFIX"] = ".wasm"
|
|
|
|
# Use TempFileMunge since some AR invocations are too long for cmd.exe.
|
|
|
|
# Use POSIX-style paths, required with TempFileMunge.
|
|
|
|
env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
|
|
|
|
env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"
|
|
|
|
|
|
|
|
# All intermediate files are just LLVM bitcode.
|
|
|
|
env["OBJPREFIX"] = ""
|
|
|
|
env["OBJSUFFIX"] = ".bc"
|
|
|
|
env["PROGPREFIX"] = ""
|
|
|
|
# Program() output consists of multiple files, so specify suffixes manually at builder.
|
|
|
|
env["PROGSUFFIX"] = ""
|
|
|
|
env["LIBPREFIX"] = "lib"
|
2021-07-05 13:03:47 +00:00
|
|
|
env["LIBSUFFIX"] = ".a"
|
2020-12-03 19:57:58 +00:00
|
|
|
env["LIBPREFIXES"] = ["$LIBPREFIX"]
|
|
|
|
env["LIBSUFFIXES"] = ["$LIBSUFFIX"]
|
2021-08-18 14:03:52 +00:00
|
|
|
env.Replace(SHLINKFLAGS="$LINKFLAGS")
|
|
|
|
env.Replace(SHLINKFLAGS="$LINKFLAGS")
|
|
|
|
|
|
|
|
if env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["-O0", "-g"])
|
|
|
|
elif env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["-O3"])
|
|
|
|
|
2022-04-30 13:49:51 +00:00
|
|
|
# Generate bindings
|
|
|
|
env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)})
|
2021-08-18 14:03:52 +00:00
|
|
|
json_api_file = ""
|
2018-02-22 22:16:25 +00:00
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
if "custom_api_file" in env:
|
|
|
|
json_api_file = env["custom_api_file"]
|
2018-05-16 00:05:41 +00:00
|
|
|
else:
|
2021-08-18 14:03:52 +00:00
|
|
|
json_api_file = os.path.join(os.getcwd(), env["headers_dir"], "extension_api.json")
|
2017-03-06 07:49:24 +00:00
|
|
|
|
2022-04-30 13:49:51 +00:00
|
|
|
bindings = env.GenerateBindings(
|
|
|
|
env.Dir("."), [json_api_file, os.path.join(env["headers_dir"], "godot", "gdnative_interface.h")]
|
|
|
|
)
|
2021-02-03 22:48:58 +00:00
|
|
|
|
2022-04-30 13:49:51 +00:00
|
|
|
# Forces bindings regeneration.
|
|
|
|
if env["generate_bindings"]:
|
|
|
|
AlwaysBuild(bindings)
|
2017-04-18 00:16:57 +00:00
|
|
|
|
2022-04-30 13:49:51 +00:00
|
|
|
# Includes
|
|
|
|
env.Append(CPPPATH=[[env.Dir(d) for d in [env["headers_dir"], "include", os.path.join("gen", "include")]]])
|
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 = []
|
2021-08-19 17:47:56 +00:00
|
|
|
add_sources(sources, "src", "cpp")
|
2021-11-30 13:00:13 +00:00
|
|
|
add_sources(sources, "src/classes", "cpp")
|
2021-08-18 14:03:52 +00:00
|
|
|
add_sources(sources, "src/core", "cpp")
|
|
|
|
add_sources(sources, "src/variant", "cpp")
|
2022-04-30 13:49:51 +00:00
|
|
|
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] = env["bits"]
|
2021-08-18 14:03:52 +00:00
|
|
|
if env["platform"] == "android":
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] = env["android_arch"]
|
2021-09-29 20:19:36 +00:00
|
|
|
elif env["platform"] == "ios":
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] = env["ios_arch"]
|
2022-02-10 04:38:54 +00:00
|
|
|
if env["ios_simulator"]:
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] += ".simulator"
|
2021-09-29 20:19:36 +00:00
|
|
|
elif env["platform"] == "javascript":
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] = "wasm"
|
2021-09-29 20:19:36 +00:00
|
|
|
elif env["platform"] == "osx":
|
2022-02-10 14:18:22 +00:00
|
|
|
env["arch_suffix"] = env["macos_arch"]
|
2019-11-26 19:26:06 +00:00
|
|
|
|
2021-09-30 02:29:42 +00:00
|
|
|
library = None
|
2022-02-10 14:18:22 +00:00
|
|
|
env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["OBJSUFFIX"])
|
|
|
|
library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["LIBSUFFIX"])
|
2021-09-30 02:29:42 +00:00
|
|
|
|
|
|
|
if env["build_library"]:
|
|
|
|
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
|
|
|
|
Default(library)
|
|
|
|
|
|
|
|
env.Append(LIBPATH=[env.Dir("bin")])
|
|
|
|
env.Append(LIBS=library_name)
|
|
|
|
Return("env")
|