SCsub 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. "os_windows.cpp",
  11. "display_server_windows.cpp",
  12. "key_mapping_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. "drop_target_windows.cpp",
  22. ]
  23. if env["library_type"] == "executable":
  24. common_win += ["godot_windows.cpp"]
  25. else:
  26. common_win += ["libgodot_windows.cpp"]
  27. if env.msvc:
  28. common_win += ["crash_handler_windows_seh.cpp"]
  29. else:
  30. common_win += ["crash_handler_windows_signal.cpp"]
  31. common_win_wrap = [
  32. "console_wrapper_windows.cpp",
  33. ]
  34. env_wrap = env.Clone()
  35. if env["arch"] == "x86_64" and env["library_type"] == "executable":
  36. env_cpp_check = env.Clone()
  37. env_cpp_check.add_source_files(sources, ["cpu_feature_validation.c"])
  38. if env.msvc:
  39. if "/d2archSSE42" in env_cpp_check["CCFLAGS"]:
  40. env_cpp_check["CCFLAGS"].remove("/d2archSSE42")
  41. env.Append(LINKFLAGS=["/ENTRY:ShimMainCRTStartup"])
  42. else:
  43. if "-msse4.2" in env_cpp_check["CCFLAGS"]:
  44. env_cpp_check["CCFLAGS"].remove("-msse4.2")
  45. env.Append(LINKFLAGS=["-Wl,--entry=ShimMainCRTStartup"])
  46. def arrange_program_clean(prog):
  47. """
  48. Given an SCons program, arrange for output files SCons doesn't know about
  49. to be cleaned when SCons is called with --clean
  50. """
  51. extensions_to_clean = [".ilk", ".exp", ".pdb", ".lib"]
  52. for program in prog:
  53. executable_stem = Path(program.name).stem
  54. extra_files_to_clean = [f"#bin/{executable_stem}{extension}" for extension in extensions_to_clean]
  55. Clean(prog, extra_files_to_clean)
  56. env["BUILDERS"]["RES"].emitter = redirect_emitter
  57. if env.editor_build:
  58. res_file = "godot_res.rc"
  59. res_target = "godot_res" + env["OBJSUFFIX"]
  60. else:
  61. res_file = "godot_res_template.rc"
  62. res_target = "godot_res_template" + env["OBJSUFFIX"]
  63. res_obj = env.RES(res_target, res_file)
  64. env.Depends(res_obj, "#core/version_generated.gen.h")
  65. env.add_source_files(sources, common_win)
  66. sources += res_obj
  67. if env["accesskit"] and not env.msvc:
  68. sources += env.DEFLIB("uiautomationcore")
  69. if env["library_type"] == "static_library":
  70. prog = env.add_library("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  71. elif env["library_type"] == "shared_library":
  72. prog = env.add_shared_library("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  73. else:
  74. prog = env.add_program("#bin/godot", sources, PROGSUFFIX=env["PROGSUFFIX"])
  75. arrange_program_clean(prog)
  76. env.Depends(prog, "godot.manifest")
  77. if env.msvc:
  78. env.Depends(prog, "godot.natvis")
  79. # Build console wrapper app.
  80. if env["windows_subsystem"] == "gui":
  81. if env.editor_build:
  82. res_wrap_file = "godot_res_wrap.rc"
  83. res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
  84. else:
  85. res_wrap_file = "godot_res_wrap_template.rc"
  86. res_wrap_target = "godot_res_wrap_template" + env["OBJSUFFIX"]
  87. res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)
  88. env_wrap.Depends(res_wrap_obj, "#core/version_generated.gen.h")
  89. if env.msvc:
  90. env_wrap.Append(LINKFLAGS=["/SUBSYSTEM:CONSOLE"])
  91. env_wrap.Append(LINKFLAGS=["version.lib"])
  92. else:
  93. env_wrap.Append(LINKFLAGS=["-Wl,--subsystem,console"])
  94. env_wrap.Append(LIBS=["version"])
  95. prog_wrap = env_wrap.add_program("#bin/godot", common_win_wrap + res_wrap_obj, PROGSUFFIX=env["PROGSUFFIX_WRAP"])
  96. arrange_program_clean(prog_wrap)
  97. env_wrap.Depends(prog_wrap, prog)
  98. sources += common_win_wrap + res_wrap_obj
  99. if env["d3d12"]:
  100. dxc_target_aliases = {
  101. "x86_32": "x86",
  102. "x86_64": "x64",
  103. "arm32": "arm",
  104. "arm64": "arm64",
  105. }
  106. dxc_arch_subdir = dxc_target_aliases[env["arch"]]
  107. agility_target_aliases = {
  108. "x86_32": "win32",
  109. "x86_64": "x64",
  110. "arm32": "arm",
  111. "arm64": "arm64",
  112. }
  113. agility_arch_subdir = agility_target_aliases[env["arch"]]
  114. # Used in cases where we can have multiple archs side-by-side.
  115. arch_bin_dir = "#bin/" + env["arch"]
  116. # Agility SDK
  117. if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
  118. agility_dlls = ["D3D12Core.dll", "d3d12SDKLayers.dll"]
  119. # Whether these are loaded from arch-specific directory or not has to be known at build time.
  120. target_dir = arch_bin_dir if env["agility_sdk_multiarch"] else "#bin"
  121. for dll in agility_dlls:
  122. env.CommandNoCache(
  123. target_dir + "/" + dll,
  124. env["agility_sdk_path"] + "/build/native/bin/" + agility_arch_subdir + "/" + dll,
  125. Copy("$TARGET", "$SOURCE"),
  126. )
  127. # PIX
  128. if env["use_pix"]:
  129. pix_dll = "WinPixEventRuntime.dll"
  130. env.CommandNoCache(
  131. "#bin/" + pix_dll,
  132. env["pix_path"] + "/bin/" + dxc_arch_subdir + "/" + pix_dll,
  133. Copy("$TARGET", "$SOURCE"),
  134. )
  135. if not env.msvc:
  136. if env["debug_symbols"]:
  137. env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
  138. if env["windows_subsystem"] == "gui":
  139. env.AddPostAction(prog_wrap, env.Run(platform_windows_builders.make_debug_mingw))
  140. env.platform_sources += sources