2
0

detect.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. ("builtin_pcre2_with_jit", False),
  25. ]
  26. def configure(env):
  27. env.msvc = True
  28. if env["bits"] != "default":
  29. print("Error: bits argument is disabled for MSVC")
  30. print(
  31. """
  32. Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console
  33. (or Visual Studio settings) that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits
  34. argument (example: scons p=uwp) and SCons will attempt to detect what MSVC compiler will be executed and inform you.
  35. """
  36. )
  37. sys.exit()
  38. ## Build type
  39. if env["target"] == "release":
  40. env.Append(CCFLAGS=["/MD"])
  41. env.Append(LINKFLAGS=["/SUBSYSTEM:WINDOWS"])
  42. if env["optimize"] != "none":
  43. env.Append(CCFLAGS=["/O2", "/GL"])
  44. env.Append(LINKFLAGS=["/LTCG"])
  45. elif env["target"] == "release_debug":
  46. env.Append(CCFLAGS=["/MD"])
  47. env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  48. env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
  49. env.Append(CPPDEFINES=["DEBUG_ENABLED"])
  50. if env["optimize"] != "none":
  51. env.Append(CCFLAGS=["/O2", "/Zi"])
  52. elif env["target"] == "debug":
  53. env.Append(CCFLAGS=["/Zi"])
  54. env.Append(CCFLAGS=["/MDd"])
  55. env.Append(CPPDEFINES=["DEBUG_ENABLED"])
  56. env.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  57. env.AppendUnique(CPPDEFINES=["WINDOWS_SUBSYSTEM_CONSOLE"])
  58. env.Append(LINKFLAGS=["/DEBUG"])
  59. ## Compiler configuration
  60. env["ENV"] = os.environ
  61. vc_base_path = os.environ["VCTOOLSINSTALLDIR"] if "VCTOOLSINSTALLDIR" in os.environ else os.environ["VCINSTALLDIR"]
  62. # Force to use Unicode encoding
  63. env.AppendUnique(CCFLAGS=["/utf-8"])
  64. # ANGLE
  65. angle_root = os.getenv("ANGLE_SRC_PATH")
  66. env.Prepend(CPPPATH=[angle_root + "/include"])
  67. jobs = str(env.GetOption("num_jobs"))
  68. angle_build_cmd = (
  69. "msbuild.exe "
  70. + angle_root
  71. + "/winrt/10/src/angle.sln /nologo /v:m /m:"
  72. + jobs
  73. + " /p:Configuration=Release /p:Platform="
  74. )
  75. if os.path.isfile(str(os.getenv("ANGLE_SRC_PATH")) + "/winrt/10/src/angle.sln"):
  76. env["build_angle"] = True
  77. ## Architecture
  78. arch = ""
  79. if str(os.getenv("Platform")).lower() == "arm":
  80. print("Compiled program architecture will be an ARM executable. (forcing bits=32).")
  81. arch = "arm"
  82. env["bits"] = "32"
  83. env.Append(LINKFLAGS=["/MACHINE:ARM"])
  84. env.Append(LIBPATH=[vc_base_path + "lib/store/arm"])
  85. angle_build_cmd += "ARM"
  86. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_ARM/lib"])
  87. else:
  88. compiler_version_str = methods.detect_visual_c_compiler_version(env["ENV"])
  89. if compiler_version_str == "amd64" or compiler_version_str == "x86_amd64":
  90. env["bits"] = "64"
  91. print("Compiled program architecture will be a x64 executable (forcing bits=64).")
  92. elif compiler_version_str == "x86" or compiler_version_str == "amd64_x86":
  93. env["bits"] = "32"
  94. print("Compiled program architecture will be a x86 executable. (forcing bits=32).")
  95. else:
  96. print(
  97. "Failed to detect MSVC compiler architecture version... Defaulting to 32-bit executable settings"
  98. " (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture"
  99. " this build is compiled for. You should check your settings/compilation setup."
  100. )
  101. env["bits"] = "32"
  102. if env["bits"] == "32":
  103. arch = "x86"
  104. angle_build_cmd += "Win32"
  105. env.Append(LINKFLAGS=["/MACHINE:X86"])
  106. env.Append(LIBPATH=[vc_base_path + "lib/store"])
  107. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_Win32/lib"])
  108. else:
  109. arch = "x64"
  110. angle_build_cmd += "x64"
  111. env.Append(LINKFLAGS=["/MACHINE:X64"])
  112. env.Append(LIBPATH=[os.environ["VCINSTALLDIR"] + "lib/store/amd64"])
  113. env.Append(LIBPATH=[angle_root + "/winrt/10/src/Release_x64/lib"])
  114. env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"]
  115. env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"]
  116. env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"]
  117. ## Compile flags
  118. env.Prepend(CPPPATH=["#platform/uwp", "#drivers/windows"])
  119. env.Append(CPPDEFINES=["UWP_ENABLED", "WINDOWS_ENABLED", "TYPED_METHOD_BIND"])
  120. env.Append(CPPDEFINES=["GLES_ENABLED", "GL_GLEXT_PROTOTYPES", "EGL_EGLEXT_PROTOTYPES", "ANGLE_ENABLED"])
  121. winver = "0x0602" # Windows 8 is the minimum target for UWP build
  122. env.Append(CPPDEFINES=[("WINVER", winver), ("_WIN32_WINNT", winver), "WIN32"])
  123. env.Append(CPPDEFINES=["__WRL_NO_DEFAULT_LIB__", ("PNG_ABORT", "abort")])
  124. env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/store/references"])
  125. env.Append(CPPFLAGS=["/AI", vc_base_path + "lib/x86/store/references"])
  126. env.Append(
  127. CCFLAGS=(
  128. '/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /errorReport:prompt /WX-'
  129. " /Zc:forScope /Gd /EHsc /nologo".split()
  130. )
  131. )
  132. env.Append(CPPDEFINES=["_UNICODE", "UNICODE", ("WINAPI_FAMILY", "WINAPI_FAMILY_APP")])
  133. env.Append(CXXFLAGS=["/ZW"])
  134. env.Append(
  135. CCFLAGS=[
  136. "/AI",
  137. vc_base_path + "\\vcpackages",
  138. "/AI",
  139. os.environ["WINDOWSSDKDIR"] + "\\References\\CommonConfiguration\\Neutral",
  140. ]
  141. )
  142. ## Link flags
  143. env.Append(
  144. LINKFLAGS=[
  145. "/MANIFEST:NO",
  146. "/NXCOMPAT",
  147. "/DYNAMICBASE",
  148. "/WINMD",
  149. "/APPCONTAINER",
  150. "/ERRORREPORT:PROMPT",
  151. "/NOLOGO",
  152. "/TLBID:1",
  153. '/NODEFAULTLIB:"kernel32.lib"',
  154. '/NODEFAULTLIB:"ole32.lib"',
  155. ]
  156. )
  157. LIBS = [
  158. "WindowsApp",
  159. "mincore",
  160. "ws2_32",
  161. "libANGLE",
  162. "libEGL",
  163. "libGLESv2",
  164. "bcrypt",
  165. ]
  166. env.Append(LINKFLAGS=[p + ".lib" for p in LIBS])
  167. # Incremental linking fix
  168. env["BUILDERS"]["ProgramOriginal"] = env["BUILDERS"]["Program"]
  169. env["BUILDERS"]["Program"] = methods.precious_program
  170. env.Append(BUILDERS={"ANGLE": env.Builder(action=angle_build_cmd)})