SCsub 4.3 KB

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