detect.py 6.0 KB

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