SCsub 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. 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. env["BUILDERS"]["RES"].emitter = redirect_emitter
  42. res_file = "godot_res.rc"
  43. res_target = "godot_res" + env["OBJSUFFIX"]
  44. res_obj = env.RES(res_target, res_file)
  45. env.Depends(res_obj, "#core/version_generated.gen.h")
  46. env.add_source_files(sources, common_win)
  47. sources += res_obj
  48. if env["accesskit"] and not env.msvc:
  49. env["BUILDERS"]["DEF"].emitter = redirect_emitter
  50. def_file = "uiautomationcore." + env["arch"] + ".def"
  51. def_target = "libuiautomationcore." + env["arch"] + ".a"
  52. def_obj = env.DEF(def_target, def_file)
  53. sources += def_obj
  54. prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  55. arrange_program_clean(prog)
  56. if env.msvc:
  57. env.Depends(prog, "godot.natvis")
  58. # Build console wrapper app.
  59. if env["windows_subsystem"] == "gui":
  60. env_wrap = env.Clone()
  61. res_wrap_file = "godot_res_wrap.rc"
  62. res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
  63. res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)
  64. env_wrap.Depends(res_wrap_obj, "#core/version_generated.gen.h")
  65. if env.msvc:
  66. env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  67. env_wrap.Append(LINKFLAGS=["version.lib"])
  68. else:
  69. env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"])
  70. env_wrap.Append(LIBS=["version"])
  71. prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"])
  72. arrange_program_clean(prog_wrap)
  73. env_wrap.Depends(prog_wrap, prog)
  74. sources += common_win_wrap + res_wrap_obj
  75. if env["d3d12"]:
  76. dxc_target_aliases = {
  77. "x86_32": "x86",
  78. "x86_64": "x64",
  79. "arm32": "arm",
  80. "arm64": "arm64",
  81. }
  82. dxc_arch_subdir = dxc_target_aliases[env["arch"]]
  83. agility_target_aliases = {
  84. "x86_32": "win32",
  85. "x86_64": "x64",
  86. "arm32": "arm",
  87. "arm64": "arm64",
  88. }
  89. agility_arch_subdir = agility_target_aliases[env["arch"]]
  90. # Used in cases where we can have multiple archs side-by-side.
  91. arch_bin_dir = "#bin/" + env["arch"]
  92. # Agility SDK
  93. if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
  94. agility_dlls = ["D3D12Core.dll", "d3d12SDKLayers.dll"]
  95. # Whether these are loaded from arch-specific directory or not has to be known at build time.
  96. target_dir = arch_bin_dir if env["agility_sdk_multiarch"] else "#bin"
  97. for dll in agility_dlls:
  98. env.CommandNoCache(
  99. target_dir + "/" + dll,
  100. env["agility_sdk_path"] + "/build/native/bin/" + agility_arch_subdir + "/" + dll,
  101. Copy("$TARGET", "$SOURCE"),
  102. )
  103. # PIX
  104. if env["use_pix"]:
  105. pix_dll = "WinPixEventRuntime.dll"
  106. env.CommandNoCache(
  107. "#bin/" + pix_dll,
  108. env["pix_path"] + "/bin/" + dxc_arch_subdir + "/" + pix_dll,
  109. Copy("$TARGET", "$SOURCE"),
  110. )
  111. if not env.msvc:
  112. if env["debug_symbols"]:
  113. env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
  114. if env["windows_subsystem"] == "gui":
  115. env.AddPostAction(prog_wrap, env.Run(platform_windows_builders.make_debug_mingw))
  116. env.platform_sources += sources