2017-06-30 19:21:38 +02:00
|
|
|
import methods
|
2015-10-08 20:00:40 +02:00
|
|
|
import os
|
2017-06-30 19:21:38 +02:00
|
|
|
import sys
|
2021-12-16 02:38:10 +01:00
|
|
|
from platform_methods import detect_arch
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-08-23 15:21:46 +02:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from SCons import Environment
|
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
def get_name():
|
2016-11-02 22:22:49 +01:00
|
|
|
return "UWP"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
def can_build():
|
2020-03-30 08:28:32 +02:00
|
|
|
if os.name == "nt":
|
2016-10-30 18:57:40 +01:00
|
|
|
# building natively on windows!
|
2020-03-30 08:28:32 +02:00
|
|
|
if os.getenv("VSINSTALLDIR"):
|
|
|
|
if os.getenv("ANGLE_SRC_PATH") is None:
|
2016-10-30 18:44:57 +01:00
|
|
|
return False
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
return True
|
|
|
|
return False
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
def get_opts():
|
2017-06-30 19:21:38 +02:00
|
|
|
return [
|
2020-03-30 08:28:32 +02:00
|
|
|
("msvc_version", "MSVC version to use (ignored if the VCINSTALLDIR environment variable is set)", None),
|
2017-06-30 19:21:38 +02:00
|
|
|
]
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2016-10-30 19:05:14 +01:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
def get_flags():
|
2016-10-30 18:44:57 +01:00
|
|
|
return [
|
2021-12-16 02:38:10 +01:00
|
|
|
("arch", detect_arch()),
|
2020-03-30 08:28:32 +02:00
|
|
|
("tools", False),
|
|
|
|
("xaudio2", True),
|
|
|
|
("builtin_pcre2_with_jit", False),
|
2016-10-30 18:44:57 +01:00
|
|
|
]
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
|
2022-08-23 15:21:46 +02:00
|
|
|
def configure(env: "Environment"):
|
2021-12-16 02:38:10 +01:00
|
|
|
# Validate arch.
|
|
|
|
supported_arches = ["x86_32", "x86_64", "arm32"]
|
|
|
|
if env["arch"] not in supported_arches:
|
2020-03-30 08:28:32 +02:00
|
|
|
print(
|
2021-12-16 02:38:10 +01:00
|
|
|
'Unsupported CPU architecture "%s" for UWP. Supported architectures are: %s.'
|
|
|
|
% (env["arch"], ", ".join(supported_arches))
|
2020-03-30 08:28:32 +02:00
|
|
|
)
|
2016-10-30 18:44:57 +01:00
|
|
|
sys.exit()
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2021-12-16 02:38:10 +01:00
|
|
|
env.msvc = True
|
|
|
|
|
2017-06-30 19:21:38 +02:00
|
|
|
## Build type
|
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
if env["target"] == "release":
|
|
|
|
env.Append(CCFLAGS=["/MD"])
|
2021-03-13 15:29:55 +01:00
|
|
|
env.Append(LINKFLAGS=["/SUBSYSTEM:WINDOWS"])
|
|
|
|
if env["optimize"] != "none":
|
|
|
|
env.Append(CCFLAGS=["/O2", "/GL"])
|
|
|
|
env.Append(LINKFLAGS=["/LTCG"])
|
2017-06-30 19:21:38 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
elif env["target"] == "release_debug":
|
|
|
|
env.Append(CCFLAGS=["/MD"])
|
|
|
|
env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
|
2020-09-14 19:56:41 +02:00
|
|
|
env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
|
2021-03-13 15:29:55 +01:00
|
|
|
if env["optimize"] != "none":
|
|
|
|
env.Append(CCFLAGS=["/O2", "/Zi"])
|
2017-06-30 19:21:38 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
elif env["target"] == "debug":
|
|
|
|
env.Append(CCFLAGS=["/Zi"])
|
|
|
|
env.Append(CCFLAGS=["/MDd"])
|
|
|
|
env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
|
2020-09-14 19:56:41 +02:00
|
|
|
env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(LINKFLAGS=["/DEBUG"])
|
2017-06-30 19:21:38 +02:00
|
|
|
|
|
|
|
## Compiler configuration
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env["ENV"] = os.environ
|
|
|
|
vc_base_path = os.environ["VCTOOLSINSTALLDIR"] if "VCTOOLSINSTALLDIR" in os.environ else os.environ["VCINSTALLDIR"]
|
2017-05-23 18:50:21 +02:00
|
|
|
|
2020-10-08 10:49:33 +02:00
|
|
|
# Force to use Unicode encoding
|
2020-10-09 12:56:20 +02:00
|
|
|
env.AppendUnique(CCFLAGS=["/utf-8"])
|
2020-10-08 10:49:33 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
# ANGLE
|
2022-08-23 15:21:46 +02:00
|
|
|
angle_root = os.environ["ANGLE_SRC_PATH"]
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Prepend(CPPPATH=[angle_root + "/include"])
|
2016-10-30 18:44:57 +01:00
|
|
|
jobs = str(env.GetOption("num_jobs"))
|
2020-03-30 08:28:32 +02:00
|
|
|
angle_build_cmd = (
|
|
|
|
"msbuild.exe "
|
|
|
|
+ angle_root
|
|
|
|
+ "/winrt/10/src/angle.sln /nologo /v:m /m:"
|
|
|
|
+ jobs
|
|
|
|
+ " /p:Configuration=Release /p:Platform="
|
|
|
|
)
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2022-08-23 15:21:46 +02:00
|
|
|
if os.path.isfile(f"{angle_root}/winrt/10/src/angle.sln"):
|
2016-10-30 18:44:57 +01:00
|
|
|
env["build_angle"] = True
|
2016-09-21 01:02:58 +02:00
|
|
|
|
2017-06-30 19:21:38 +02:00
|
|
|
## Architecture
|
|
|
|
|
|
|
|
arch = ""
|
2020-03-30 08:28:32 +02:00
|
|
|
if str(os.getenv("Platform")).lower() == "arm":
|
2021-12-16 02:38:10 +01:00
|
|
|
print("Compiled program architecture will be an ARM executable (forcing arch=arm32).")
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:57:40 +01:00
|
|
|
arch = "arm"
|
2021-12-16 02:38:10 +01:00
|
|
|
env["arch"] = "arm32"
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(LINKFLAGS=["/MACHINE:ARM"])
|
|
|
|
env.Append(LIBPATH=[vc_base_path + "lib/store/arm"])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
angle_build_cmd += "ARM"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_ARM/lib"])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
else:
|
2020-03-30 08:28:32 +02:00
|
|
|
compiler_version_str = methods.detect_visual_c_compiler_version(env["ENV"])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
if compiler_version_str == "amd64" or compiler_version_str == "x86_amd64":
|
2021-12-16 02:38:10 +01:00
|
|
|
env["arch"] = "x86_64"
|
|
|
|
print("Compiled program architecture will be a x64 executable (forcing arch=x86_64).")
|
2020-03-30 08:28:32 +02:00
|
|
|
elif compiler_version_str == "x86" or compiler_version_str == "amd64_x86":
|
2021-12-16 02:38:10 +01:00
|
|
|
env["arch"] = "x86_32"
|
|
|
|
print("Compiled program architecture will be a x86 executable (forcing arch=x86_32).")
|
2016-10-30 18:44:57 +01:00
|
|
|
else:
|
2020-03-30 08:28:32 +02:00
|
|
|
print(
|
2021-12-16 02:38:10 +01:00
|
|
|
"Failed to detect MSVC compiler architecture version... Defaulting to x86 32-bit executable settings"
|
|
|
|
" (forcing arch=x86_32). Compilation attempt will continue, but SCons can not detect for what architecture"
|
2020-07-26 19:38:10 +02:00
|
|
|
" this build is compiled for. You should check your settings/compilation setup."
|
2020-03-30 08:28:32 +02:00
|
|
|
)
|
2021-12-16 02:38:10 +01:00
|
|
|
env["arch"] = "x86_32"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2021-12-16 02:38:10 +01:00
|
|
|
if env["arch"] == "x86_32":
|
2016-10-30 18:44:57 +01:00
|
|
|
arch = "x86"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
angle_build_cmd += "Win32"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(LINKFLAGS=["/MACHINE:X86"])
|
|
|
|
env.Append(LIBPATH=[vc_base_path + "lib/store"])
|
|
|
|
env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_Win32/lib"])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
else:
|
|
|
|
arch = "x64"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
angle_build_cmd += "x64"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(LINKFLAGS=["/MACHINE:X64"])
|
|
|
|
env.Append(LIBPATH=[os.environ["VCINSTALLDIR"] + "lib/store/amd64"])
|
|
|
|
env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_x64/lib"])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-06-30 19:21:38 +02:00
|
|
|
env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"]
|
|
|
|
env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"]
|
|
|
|
env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"]
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-06-30 19:21:38 +02:00
|
|
|
## Compile flags
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Prepend(CPPPATH=["#platform/uwp", "#drivers/windows"])
|
|
|
|
env.Append(CPPDEFINES=["UWP_ENABLED", "WINDOWS_ENABLED", "TYPED_METHOD_BIND"])
|
|
|
|
env.Append(CPPDEFINES=["GLES_ENABLED", "GL_GLEXT_PROTOTYPES", "EGL_EGLEXT_PROTOTYPES", "ANGLE_ENABLED"])
|
|
|
|
winver = "0x0602" # Windows 8 is the minimum target for UWP build
|
|
|
|
env.Append(CPPDEFINES=[("WINVER", winver), ("_WIN32_WINNT", winver), "WIN32"])
|
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["__WRL_NO_DEFAULT_LIB__", ("PNG_ABORT", "abort")])
|
|
|
|
|
|
|
|
env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/store/references"])
|
|
|
|
env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/x86/store/references"])
|
|
|
|
|
|
|
|
env.Append(
|
2020-07-26 19:38:10 +02:00
|
|
|
CCFLAGS=(
|
|
|
|
'/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /errorReport:prompt /WX-'
|
|
|
|
" /Zc:forScope /Gd /EHsc /nologo".split()
|
|
|
|
)
|
2020-03-30 08:28:32 +02:00
|
|
|
)
|
|
|
|
env.Append(CPPDEFINES=["_UNICODE", "UNICODE", ("WINAPI_FAMILY", "WINAPI_FAMILY_APP")])
|
|
|
|
env.Append(CXXFLAGS=["/ZW"])
|
|
|
|
env.Append(
|
|
|
|
CCFLAGS=[
|
|
|
|
"/AI",
|
|
|
|
vc_base_path + "\\vcpackages",
|
|
|
|
"/AI",
|
|
|
|
os.environ["WINDOWSSDKDIR"] + "\\References\\CommonConfiguration\\Neutral",
|
|
|
|
]
|
|
|
|
)
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-06-30 19:21:38 +02:00
|
|
|
## Link flags
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"/MANIFEST:NO",
|
|
|
|
"/NXCOMPAT",
|
|
|
|
"/DYNAMICBASE",
|
|
|
|
"/WINMD",
|
|
|
|
"/APPCONTAINER",
|
|
|
|
"/ERRORREPORT:PROMPT",
|
|
|
|
"/NOLOGO",
|
|
|
|
"/TLBID:1",
|
|
|
|
'/NODEFAULTLIB:"kernel32.lib"',
|
|
|
|
'/NODEFAULTLIB:"ole32.lib"',
|
|
|
|
]
|
|
|
|
)
|
2016-11-03 05:20:26 +01:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
LIBS = [
|
2020-03-30 08:28:32 +02:00
|
|
|
"WindowsApp",
|
|
|
|
"mincore",
|
|
|
|
"ws2_32",
|
|
|
|
"libANGLE",
|
|
|
|
"libEGL",
|
|
|
|
"libGLESv2",
|
|
|
|
"bcrypt",
|
2016-10-30 18:44:57 +01:00
|
|
|
]
|
2016-10-30 18:57:40 +01:00
|
|
|
env.Append(LINKFLAGS=[p + ".lib" for p in LIBS])
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2016-10-30 18:44:57 +01:00
|
|
|
# Incremental linking fix
|
2020-03-30 08:28:32 +02:00
|
|
|
env["BUILDERS"]["ProgramOriginal"] = env["BUILDERS"]["Program"]
|
|
|
|
env["BUILDERS"]["Program"] = methods.precious_program
|
2016-09-04 00:25:43 +02:00
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
env.Append(BUILDERS={"ANGLE": env.Builder(action=angle_build_cmd)})
|