detect.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import methods
  2. import os
  3. import sys
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "UWP"
  8. def can_build():
  9. if (os.name == "nt"):
  10. # building natively on windows!
  11. if (os.getenv("VSINSTALLDIR")):
  12. if (os.getenv("ANGLE_SRC_PATH") is None):
  13. return False
  14. return True
  15. return False
  16. def get_opts():
  17. return [
  18. ('msvc_version', 'MSVC version to use (ignored if the VCINSTALLDIR environment variable is set)', None),
  19. ]
  20. def get_flags():
  21. return [
  22. ('tools', False),
  23. ('xaudio2', True),
  24. ]
  25. def configure(env):
  26. env.msvc = True
  27. if (env["bits"] != "default"):
  28. print("Error: bits argument is disabled for MSVC")
  29. print("""
  30. Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console
  31. (or Visual Studio settings) that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits
  32. argument (example: scons p=uwp) and SCons will attempt to detect what MSVC compiler will be executed and inform you.
  33. """)
  34. sys.exit()
  35. ## Build type
  36. if (env["target"] == "release"):
  37. env.Append(CPPFLAGS=['/O2', '/GL'])
  38. env.Append(CPPFLAGS=['/MD'])
  39. env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS', '/LTCG'])
  40. elif (env["target"] == "release_debug"):
  41. env.Append(CCFLAGS=['/O2', '/Zi', '/DDEBUG_ENABLED'])
  42. env.Append(CPPFLAGS=['/MD'])
  43. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  44. elif (env["target"] == "debug"):
  45. env.Append(CCFLAGS=['/Zi', '/DDEBUG_ENABLED', '/DDEBUG_MEMORY_ENABLED'])
  46. env.Append(CPPFLAGS=['/MDd'])
  47. env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
  48. env.Append(LINKFLAGS=['/DEBUG'])
  49. ## Compiler configuration
  50. env['ENV'] = os.environ
  51. vc_base_path = os.environ['VCTOOLSINSTALLDIR'] if "VCTOOLSINSTALLDIR" in os.environ else os.environ['VCINSTALLDIR']
  52. # ANGLE
  53. angle_root = os.getenv("ANGLE_SRC_PATH")
  54. env.Append(CPPPATH=[angle_root + '/include'])
  55. jobs = str(env.GetOption("num_jobs"))
  56. angle_build_cmd = "msbuild.exe " + angle_root + "/winrt/10/src/angle.sln /nologo /v:m /m:" + jobs + " /p:Configuration=Release /p:Platform="
  57. if os.path.isfile(str(os.getenv("ANGLE_SRC_PATH")) + "/winrt/10/src/angle.sln"):
  58. env["build_angle"] = True
  59. ## Architecture
  60. arch = ""
  61. if str(os.getenv('Platform')).lower() == "arm":
  62. print("Compiled program architecture will be an ARM executable. (forcing bits=32).")
  63. arch = "arm"
  64. env["bits"] = "32"
  65. env.Append(LINKFLAGS=['/MACHINE:ARM'])
  66. env.Append(LIBPATH=[vc_base_path + 'lib/store/arm'])
  67. angle_build_cmd += "ARM"
  68. env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_ARM/lib'])
  69. else:
  70. compiler_version_str = methods.detect_visual_c_compiler_version(env['ENV'])
  71. if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"):
  72. env["bits"] = "64"
  73. print("Compiled program architecture will be a x64 executable (forcing bits=64).")
  74. elif (compiler_version_str == "x86" or compiler_version_str == "amd64_x86"):
  75. env["bits"] = "32"
  76. print("Compiled program architecture will be a x86 executable. (forcing bits=32).")
  77. else:
  78. 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.")
  79. env["bits"] = "32"
  80. if (env["bits"] == "32"):
  81. arch = "x86"
  82. angle_build_cmd += "Win32"
  83. env.Append(LINKFLAGS=['/MACHINE:X86'])
  84. env.Append(LIBPATH=[vc_base_path + 'lib/store'])
  85. env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_Win32/lib'])
  86. else:
  87. arch = "x64"
  88. angle_build_cmd += "x64"
  89. env.Append(LINKFLAGS=['/MACHINE:X64'])
  90. env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/amd64'])
  91. env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_x64/lib'])
  92. env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"]
  93. env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"]
  94. env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"]
  95. ## Compile flags
  96. env.Append(CPPPATH=['#platform/uwp', '#drivers/windows'])
  97. env.Append(CCFLAGS=['/DUWP_ENABLED', '/DWINDOWS_ENABLED', '/DTYPED_METHOD_BIND'])
  98. env.Append(CCFLAGS=['/DGLES_ENABLED', '/DGL_GLEXT_PROTOTYPES', '/DEGL_EGLEXT_PROTOTYPES', '/DANGLE_ENABLED'])
  99. winver = "0x0602" # Windows 8 is the minimum target for UWP build
  100. env.Append(CCFLAGS=['/DWINVER=%s' % winver, '/D_WIN32_WINNT=%s' % winver])
  101. env.Append(CPPFLAGS=['/D', '__WRL_NO_DEFAULT_LIB__', '/D', 'WIN32', '/DPNG_ABORT=abort'])
  102. env.Append(CPPFLAGS=['/AI', vc_base_path + 'lib/store/references'])
  103. env.Append(CPPFLAGS=['/AI', vc_base_path + 'lib/x86/store/references'])
  104. 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())
  105. env.Append(CXXFLAGS='/ZW /FS'.split())
  106. env.Append(CCFLAGS=['/AI', vc_base_path + '\\vcpackages', '/AI', os.environ['WINDOWSSDKDIR'] + '\\References\\CommonConfiguration\\Neutral'])
  107. ## Link flags
  108. env.Append(LINKFLAGS=['/MANIFEST:NO', '/NXCOMPAT', '/DYNAMICBASE', '/WINMD', '/APPCONTAINER', '/ERRORREPORT:PROMPT', '/NOLOGO', '/TLBID:1', '/NODEFAULTLIB:"kernel32.lib"', '/NODEFAULTLIB:"ole32.lib"'])
  109. LIBS = [
  110. 'WindowsApp',
  111. 'mincore',
  112. 'ws2_32',
  113. 'libANGLE',
  114. 'libEGL',
  115. 'libGLESv2',
  116. 'bcrypt',
  117. ]
  118. env.Append(LINKFLAGS=[p + ".lib" for p in LIBS])
  119. # Incremental linking fix
  120. env['BUILDERS']['ProgramOriginal'] = env['BUILDERS']['Program']
  121. env['BUILDERS']['Program'] = methods.precious_program
  122. env.Append(BUILDERS={'ANGLE': env.Builder(action=angle_build_cmd)})