SCsub 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. Import("env")
  4. import os
  5. from pathlib import Path
  6. import platform_windows_builders
  7. from methods import redirect_emitter
  8. sources = []
  9. common_win = [
  10. "godot_windows.cpp",
  11. "os_windows.cpp",
  12. "display_server_windows.cpp",
  13. "key_mapping_windows.cpp",
  14. "tts_windows.cpp",
  15. "windows_terminal_logger.cpp",
  16. "windows_utils.cpp",
  17. "native_menu_windows.cpp",
  18. "gl_manager_windows_native.cpp",
  19. "gl_manager_windows_angle.cpp",
  20. "wgl_detect_version.cpp",
  21. "rendering_context_driver_vulkan_windows.cpp",
  22. "drop_target_windows.cpp",
  23. ]
  24. if env.msvc:
  25. common_win += ["crash_handler_windows_seh.cpp"]
  26. else:
  27. common_win += ["crash_handler_windows_signal.cpp"]
  28. common_win_wrap = [
  29. "console_wrapper_windows.cpp",
  30. ]
  31. env_wrap = env.Clone()
  32. if env["arch"] == "x86_64":
  33. env_cpp_check = env.Clone()
  34. env_cpp_check.add_source_files(sources, ["cpu_feature_validation.c"])
  35. if env.msvc:
  36. if "/d2archSSE42" in env_cpp_check["CCFLAGS"]:
  37. env_cpp_check["CCFLAGS"].remove("/d2archSSE42")
  38. env.Append(LINKFLAGS=["/ENTRY:ShimMainCRTStartup"])
  39. else:
  40. if "-msse4.2" in env_cpp_check["CCFLAGS"]:
  41. env_cpp_check["CCFLAGS"].remove("-msse4.2")
  42. env.Append(LINKFLAGS=["-Wl,--entry=ShimMainCRTStartup"])
  43. def arrange_program_clean(prog):
  44. """
  45. Given an SCons program, arrange for output files SCons doesn't know about
  46. to be cleaned when SCons is called with --clean
  47. """
  48. extensions_to_clean = [".ilk", ".exp", ".pdb", ".lib"]
  49. for program in prog:
  50. executable_stem = Path(program.name).stem
  51. extra_files_to_clean = [f"#bin/{executable_stem}{extension}" for extension in extensions_to_clean]
  52. Clean(prog, extra_files_to_clean)
  53. env["BUILDERS"]["RES"].emitter = redirect_emitter
  54. res_file = "godot_res.rc"
  55. res_target = "godot_res" + env["OBJSUFFIX"]
  56. res_obj = env.RES(res_target, res_file)
  57. env.Depends(res_obj, "#core/version_generated.gen.h")
  58. env.add_source_files(sources, common_win)
  59. sources += res_obj
  60. if env["accesskit"] and not env.msvc:
  61. env["BUILDERS"]["DEF"].emitter = redirect_emitter
  62. def_file = "uiautomationcore." + env["arch"] + ".def"
  63. def_target = "libuiautomationcore." + env["arch"] + ".a"
  64. def_obj = env.DEF(def_target, def_file)
  65. sources += def_obj
  66. prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  67. arrange_program_clean(prog)
  68. if env.msvc:
  69. env.Depends(prog, "godot.natvis")
  70. # Build console wrapper app.
  71. if env["windows_subsystem"] == "gui":
  72. res_wrap_file = "godot_res_wrap.rc"
  73. res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
  74. res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)
  75. env_wrap.Depends(res_wrap_obj, "#core/version_generated.gen.h")
  76. if env.msvc:
  77. env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  78. env_wrap.Append(LINKFLAGS=["version.lib"])
  79. else:
  80. env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"])
  81. env_wrap.Append(LIBS=["version"])
  82. prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"])
  83. arrange_program_clean(prog_wrap)
  84. env_wrap.Depends(prog_wrap, prog)
  85. sources += common_win_wrap + res_wrap_obj
  86. if env["d3d12"]:
  87. dxc_target_aliases = {
  88. "x86_32": "x86",
  89. "x86_64": "x64",
  90. "arm32": "arm",
  91. "arm64": "arm64",
  92. }
  93. dxc_arch_subdir = dxc_target_aliases[env["arch"]]
  94. agility_target_aliases = {
  95. "x86_32": "win32",
  96. "x86_64": "x64",
  97. "arm32": "arm",
  98. "arm64": "arm64",
  99. }
  100. agility_arch_subdir = agility_target_aliases[env["arch"]]
  101. # Used in cases where we can have multiple archs side-by-side.
  102. arch_bin_dir = "#bin/" + env["arch"]
  103. # Agility SDK
  104. if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
  105. agility_dlls = ["D3D12Core.dll", "d3d12SDKLayers.dll"]
  106. # Whether these are loaded from arch-specific directory or not has to be known at build time.
  107. target_dir = arch_bin_dir if env["agility_sdk_multiarch"] else "#bin"
  108. for dll in agility_dlls:
  109. env.CommandNoCache(
  110. target_dir + "/" + dll,
  111. env["agility_sdk_path"] + "/build/native/bin/" + agility_arch_subdir + "/" + dll,
  112. Copy("$TARGET", "$SOURCE"),
  113. )
  114. # PIX
  115. if env["use_pix"]:
  116. pix_dll = "WinPixEventRuntime.dll"
  117. env.CommandNoCache(
  118. "#bin/" + pix_dll,
  119. env["pix_path"] + "/bin/" + dxc_arch_subdir + "/" + pix_dll,
  120. Copy("$TARGET", "$SOURCE"),
  121. )
  122. if not env.msvc:
  123. if env["debug_symbols"]:
  124. env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
  125. if env["windows_subsystem"] == "gui":
  126. env.AddPostAction(prog_wrap, env.Run(platform_windows_builders.make_debug_mingw))
  127. env.platform_sources += sources