SCsub 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. sources = []
  8. common_win = [
  9. "godot_windows.cpp",
  10. "os_windows.cpp",
  11. "display_server_windows.cpp",
  12. "key_mapping_windows.cpp",
  13. "joypad_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. def arrange_program_clean(prog):
  32. """
  33. Given an SCons program, arrange for output files SCons doesn't know about
  34. to be cleaned when SCons is called with --clean
  35. """
  36. extensions_to_clean = [".ilk", ".exp", ".pdb", ".lib"]
  37. for program in prog:
  38. executable_stem = Path(program.name).stem
  39. extra_files_to_clean = [f"#bin/{executable_stem}{extension}" for extension in extensions_to_clean]
  40. Clean(prog, extra_files_to_clean)
  41. res_file = "godot_res.rc"
  42. res_target = "godot_res" + env["OBJSUFFIX"]
  43. res_obj = env.RES(res_target, res_file)
  44. env.Depends(res_obj, "#core/version_generated.gen.h")
  45. env.add_source_files(sources, common_win)
  46. sources += res_obj
  47. prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  48. arrange_program_clean(prog)
  49. if env.msvc:
  50. env.Depends(prog, "godot.natvis")
  51. # Build console wrapper app.
  52. if env["windows_subsystem"] == "gui":
  53. env_wrap = env.Clone()
  54. res_wrap_file = "godot_res_wrap.rc"
  55. res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
  56. res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)
  57. env_wrap.Depends(res_wrap_obj, "#core/version_generated.gen.h")
  58. if env.msvc:
  59. env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  60. env_wrap.Append(LINKFLAGS=["version.lib"])
  61. else:
  62. env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"])
  63. env_wrap.Append(LIBS=["version"])
  64. prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"])
  65. arrange_program_clean(prog_wrap)
  66. env_wrap.Depends(prog_wrap, prog)
  67. sources += common_win_wrap + res_wrap_obj
  68. if env["d3d12"]:
  69. dxc_target_aliases = {
  70. "x86_32": "x86",
  71. "x86_64": "x64",
  72. "arm32": "arm",
  73. "arm64": "arm64",
  74. }
  75. dxc_arch_subdir = dxc_target_aliases[env["arch"]]
  76. agility_target_aliases = {
  77. "x86_32": "win32",
  78. "x86_64": "x64",
  79. "arm32": "arm",
  80. "arm64": "arm64",
  81. }
  82. agility_arch_subdir = agility_target_aliases[env["arch"]]
  83. # Used in cases where we can have multiple archs side-by-side.
  84. arch_bin_dir = "#bin/" + env["arch"]
  85. # Agility SDK
  86. if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
  87. agility_dlls = ["D3D12Core.dll", "d3d12SDKLayers.dll"]
  88. # Whether these are loaded from arch-specific directory or not has to be known at build time.
  89. target_dir = arch_bin_dir if env["agility_sdk_multiarch"] else "#bin"
  90. for dll in agility_dlls:
  91. env.Command(
  92. target_dir + "/" + dll,
  93. env["agility_sdk_path"] + "/build/native/bin/" + agility_arch_subdir + "/" + dll,
  94. Copy("$TARGET", "$SOURCE"),
  95. )
  96. # PIX
  97. if env["use_pix"]:
  98. pix_dll = "WinPixEventRuntime.dll"
  99. env.Command(
  100. "#bin/" + pix_dll,
  101. env["pix_path"] + "/bin/" + dxc_arch_subdir + "/" + pix_dll,
  102. Copy("$TARGET", "$SOURCE"),
  103. )
  104. if not os.getenv("VCINSTALLDIR"):
  105. if env["debug_symbols"]:
  106. env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
  107. if env["windows_subsystem"] == "gui":
  108. env.AddPostAction(prog_wrap, env.Run(platform_windows_builders.make_debug_mingw))
  109. env.platform_sources += sources