2017-07-01 01:21:38 +08:00
import methods
2015-10-09 02:00:40 +08:00
import os
import string
2017-07-01 01:21:38 +08:00
import sys
2015-10-09 02:00:40 +08:00
def is_active ( ) :
2016-10-31 01:44:57 +08:00
return True
2016-04-03 02:26:12 +08:00
2016-10-31 02:05:14 +08:00
2015-10-09 02:00:40 +08:00
def get_name ( ) :
2016-11-03 05:22:49 +08:00
return " UWP "
2015-10-09 02:00:40 +08:00
2016-10-31 02:05:14 +08:00
2015-10-09 02:00:40 +08:00
def can_build ( ) :
2016-10-31 01:57:40 +08:00
if ( os . name == " nt " ) :
# building natively on windows!
2016-10-31 01:44:57 +08:00
if ( os . getenv ( " VSINSTALLDIR " ) ) :
2016-09-04 06:25:43 +08:00
2016-10-31 01:44:57 +08:00
if ( os . getenv ( " ANGLE_SRC_PATH " ) == None ) :
return False
2016-09-04 06:25:43 +08:00
2016-10-31 01:44:57 +08:00
return True
return False
2016-04-03 02:26:12 +08:00
2016-10-31 02:05:14 +08:00
2015-10-09 02:00:40 +08:00
def get_opts ( ) :
2018-03-15 19:24:49 +08:00
from SCons . Variables import BoolVariable
2017-07-01 01:21:38 +08:00
return [
2018-06-08 02:46:32 +08:00
( ' msvc_version ' , ' MSVC version to use (ignored if the VCINSTALLDIR environment variable is set) ' , None ) ,
BoolVariable ( ' use_mingw ' , ' Use the MinGW compiler even if MSVC is installed (only used on Windows) ' , False ) ,
2017-07-01 01:21:38 +08:00
]
2016-04-03 02:26:12 +08:00
2016-10-31 02:05:14 +08:00
2015-10-09 02:00:40 +08:00
def get_flags ( ) :
2016-10-31 01:44:57 +08:00
return [
2017-09-25 12:04:49 +08:00
( ' tools ' , False ) ,
( ' xaudio2 ' , True ) ,
2016-10-31 01:44:57 +08:00
]
2015-10-09 02:00:40 +08:00
def configure ( env ) :
2018-03-30 00:17:38 +08:00
env . msvc = True
2017-07-01 01:21:38 +08:00
if ( env [ " bits " ] != " default " ) :
print ( " Error: bits argument is disabled for MSVC " )
print ( """
Bits argument is not supported for MSVC compilation . Architecture depends on the Native / Cross Compile Tools Prompt / Developer Console
( or Visual Studio settings ) that is being used to run SCons . As a consequence , bits argument is disabled . Run scons again without bits
argument ( example : scons p = uwp ) and SCons will attempt to detect what MSVC compiler will be executed and inform you .
""" )
2016-10-31 01:44:57 +08:00
sys . exit ( )
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
## Build type
if ( env [ " target " ] == " release " ) :
env . Append ( CPPFLAGS = [ ' /O2 ' , ' /GL ' ] )
env . Append ( CPPFLAGS = [ ' /MD ' ] )
env . Append ( LINKFLAGS = [ ' /SUBSYSTEM:WINDOWS ' , ' /LTCG ' ] )
elif ( env [ " target " ] == " release_debug " ) :
env . Append ( CCFLAGS = [ ' /O2 ' , ' /Zi ' , ' /DDEBUG_ENABLED ' ] )
env . Append ( CPPFLAGS = [ ' /MD ' ] )
env . Append ( LINKFLAGS = [ ' /SUBSYSTEM:CONSOLE ' ] )
elif ( env [ " target " ] == " debug " ) :
env . Append ( CCFLAGS = [ ' /Zi ' , ' /DDEBUG_ENABLED ' , ' /DDEBUG_MEMORY_ENABLED ' ] )
env . Append ( CPPFLAGS = [ ' /MDd ' ] )
env . Append ( LINKFLAGS = [ ' /SUBSYSTEM:CONSOLE ' ] )
env . Append ( LINKFLAGS = [ ' /DEBUG ' ] )
## Compiler configuration
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
env [ ' ENV ' ] = os . environ
2017-05-24 00:50:21 +08:00
vc_base_path = os . environ [ ' VCTOOLSINSTALLDIR ' ] if " VCTOOLSINSTALLDIR " in os . environ else os . environ [ ' VCINSTALLDIR ' ]
2016-10-31 01:44:57 +08:00
# ANGLE
angle_root = os . getenv ( " ANGLE_SRC_PATH " )
env . Append ( CPPPATH = [ angle_root + ' /include ' ] )
jobs = str ( env . GetOption ( " num_jobs " ) )
angle_build_cmd = " msbuild.exe " + angle_root + " /winrt/10/src/angle.sln /nologo /v:m /m: " + jobs + " /p:Configuration=Release /p:Platform= "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
if os . path . isfile ( str ( os . getenv ( " ANGLE_SRC_PATH " ) ) + " /winrt/10/src/angle.sln " ) :
env [ " build_angle " ] = True
2016-09-21 07:02:58 +08:00
2017-07-01 01:21:38 +08:00
## Architecture
arch = " "
2017-11-10 02:06:44 +08:00
if str ( os . getenv ( ' Platform ' ) ) . lower ( ) == " arm " :
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
print ( " Compiled program architecture will be an ARM executable. (forcing bits=32). " )
2015-10-09 02:00:40 +08:00
2016-10-31 01:57:40 +08:00
arch = " arm "
env [ " bits " ] = " 32 "
2016-10-31 01:44:57 +08:00
env . Append ( LINKFLAGS = [ ' /MACHINE:ARM ' ] )
2017-05-24 00:50:21 +08:00
env . Append ( LIBPATH = [ vc_base_path + ' lib/store/arm ' ] )
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
angle_build_cmd + = " ARM "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
env . Append ( LIBPATH = [ angle_root + ' /winrt/10/src/Release_ARM/lib ' ] )
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
else :
compiler_version_str = methods . detect_visual_c_compiler_version ( env [ ' ENV ' ] )
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
if ( compiler_version_str == " amd64 " or compiler_version_str == " x86_amd64 " ) :
2016-10-31 01:57:40 +08:00
env [ " bits " ] = " 64 "
2017-07-01 01:21:38 +08:00
print ( " Compiled program architecture will be a x64 executable (forcing bits=64). " )
2016-10-31 01:57:40 +08:00
elif ( compiler_version_str == " x86 " or compiler_version_str == " amd64_x86 " ) :
env [ " bits " ] = " 32 "
2017-07-01 01:21:38 +08:00
print ( " Compiled program architecture will be a x86 executable. (forcing bits=32). " )
2016-10-31 01:44:57 +08:00
else :
2018-06-08 02:46:32 +08:00
print ( " Failed to detect MSVC compiler architecture version... Defaulting to 32-bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup. " )
2016-10-31 01:57:40 +08:00
env [ " bits " ] = " 32 "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
if ( env [ " bits " ] == " 32 " ) :
arch = " x86 "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
angle_build_cmd + = " Win32 "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
env . Append ( LINKFLAGS = [ ' /MACHINE:X86 ' ] )
2017-05-24 00:50:21 +08:00
env . Append ( LIBPATH = [ vc_base_path + ' lib/store ' ] )
2016-10-31 01:44:57 +08:00
env . Append ( LIBPATH = [ angle_root + ' /winrt/10/src/Release_Win32/lib ' ] )
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
else :
arch = " x64 "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
angle_build_cmd + = " x64 "
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08: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-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
env [ " PROGSUFFIX " ] = " . " + arch + env [ " PROGSUFFIX " ]
env [ " OBJSUFFIX " ] = " . " + arch + env [ " OBJSUFFIX " ]
env [ " LIBSUFFIX " ] = " . " + arch + env [ " LIBSUFFIX " ]
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
## Compile flags
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
env . Append ( CPPPATH = [ ' #platform/uwp ' , ' #drivers/windows ' ] )
env . Append ( CCFLAGS = [ ' /DUWP_ENABLED ' , ' /DWINDOWS_ENABLED ' , ' /DTYPED_METHOD_BIND ' ] )
2017-11-20 00:52:18 +08:00
env . Append ( CCFLAGS = [ ' /DGLES_ENABLED ' , ' /DGL_GLEXT_PROTOTYPES ' , ' /DEGL_EGLEXT_PROTOTYPES ' , ' /DANGLE_ENABLED ' ] )
2017-07-01 01:21:38 +08:00
winver = " 0x0602 " # Windows 8 is the minimum target for UWP build
env . Append ( CCFLAGS = [ ' /DWINVER= %s ' % winver , ' /D_WIN32_WINNT= %s ' % winver ] )
2015-10-09 02:00:40 +08:00
2017-07-12 12:23:44 +08:00
env . Append ( CPPFLAGS = [ ' /D ' , ' __WRL_NO_DEFAULT_LIB__ ' , ' /D ' , ' WIN32 ' , ' /DPNG_ABORT=abort ' ] )
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
env . Append ( CPPFLAGS = [ ' /AI ' , vc_base_path + ' lib/store/references ' ] )
env . Append ( CPPFLAGS = [ ' /AI ' , vc_base_path + ' lib/x86/store/references ' ] )
2015-10-09 02:00:40 +08:00
2017-08-27 00:53:49 +08:00
env . Append ( CCFLAGS = ' /FS /MP /GS /wd " 4453 " /wd " 28204 " /wd " 4291 " /Zc:wchar_t /Gm- /fp:precise /D " _UNICODE " /D " UNICODE " /D " WINAPI_FAMILY=WINAPI_FAMILY_APP " /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo ' . split ( ) )
env . Append ( CXXFLAGS = ' /ZW /FS ' . split ( ) )
2017-05-24 00:50:21 +08:00
env . Append ( CCFLAGS = [ ' /AI ' , vc_base_path + ' \\ vcpackages ' , ' /AI ' , os . environ [ ' WINDOWSSDKDIR ' ] + ' \\ References \\ CommonConfiguration \\ Neutral ' ] )
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
## Link flags
2015-10-09 02:00:40 +08:00
2017-07-01 01:21:38 +08:00
env . Append ( LINKFLAGS = [ ' /MANIFEST:NO ' , ' /NXCOMPAT ' , ' /DYNAMICBASE ' , ' /WINMD ' , ' /APPCONTAINER ' , ' /ERRORREPORT:PROMPT ' , ' /NOLOGO ' , ' /TLBID:1 ' , ' /NODEFAULTLIB: " kernel32.lib " ' , ' /NODEFAULTLIB: " ole32.lib " ' ] )
2016-11-03 12:20:26 +08:00
2016-10-31 01:44:57 +08:00
LIBS = [
' WindowsApp ' ,
' mincore ' ,
2016-11-03 12:20:26 +08:00
' ws2_32 ' ,
2016-10-31 01:44:57 +08:00
' libANGLE ' ,
' libEGL ' ,
' libGLESv2 ' ,
2018-02-20 17:08:17 +08:00
' bcrypt ' ,
2016-10-31 01:44:57 +08:00
]
2016-10-31 01:57:40 +08:00
env . Append ( LINKFLAGS = [ p + " .lib " for p in LIBS ] )
2015-10-09 02:00:40 +08:00
2016-10-31 01:44:57 +08:00
# Incremental linking fix
env [ ' BUILDERS ' ] [ ' ProgramOriginal ' ] = env [ ' BUILDERS ' ] [ ' Program ' ]
env [ ' BUILDERS ' ] [ ' Program ' ] = methods . precious_program
2016-09-04 06:25:43 +08:00
2016-10-31 01:57:40 +08:00
env . Append ( BUILDERS = { ' ANGLE ' : env . Builder ( action = angle_build_cmd ) } )