SCsub 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. Import("env")
  4. import os
  5. import shutil
  6. from platform_methods import detect_mvk, lipo
  7. def generate_bundle(target, source, env):
  8. bin_dir = Dir("#bin").abspath
  9. # Template bundle.
  10. app_prefix = "godot." + env["platform"]
  11. rel_prefix = "libgodot." + env["platform"] + "." + "template_release"
  12. dbg_prefix = "libgodot." + env["platform"] + "." + "template_debug"
  13. if env.dev_build:
  14. app_prefix += ".dev"
  15. rel_prefix += ".dev"
  16. dbg_prefix += ".dev"
  17. if env["precision"] == "double":
  18. app_prefix += ".double"
  19. rel_prefix += ".double"
  20. dbg_prefix += ".double"
  21. # Lipo template libraries.
  22. rel_target_bin = lipo(bin_dir + "/" + rel_prefix, env.extra_suffix + ".a")
  23. dbg_target_bin = lipo(bin_dir + "/" + dbg_prefix, env.extra_suffix + ".a")
  24. rel_target_bin_sim = lipo(bin_dir + "/" + rel_prefix, ".simulator" + env.extra_suffix + ".a")
  25. dbg_target_bin_sim = lipo(bin_dir + "/" + dbg_prefix, ".simulator" + env.extra_suffix + ".a")
  26. # Assemble Xcode project bundle.
  27. app_dir = Dir("#bin/ios_xcode").abspath
  28. templ = Dir("#misc/dist/ios_xcode").abspath
  29. if os.path.exists(app_dir):
  30. shutil.rmtree(app_dir)
  31. shutil.copytree(templ, app_dir)
  32. if rel_target_bin != "":
  33. shutil.copy(rel_target_bin, app_dir + "/libgodot.ios.release.xcframework/ios-arm64/libgodot.a")
  34. if dbg_target_bin != "":
  35. shutil.copy(dbg_target_bin, app_dir + "/libgodot.ios.debug.xcframework/ios-arm64/libgodot.a")
  36. if rel_target_bin_sim != "":
  37. shutil.copy(
  38. rel_target_bin_sim, app_dir + "/libgodot.ios.release.xcframework/ios-arm64_x86_64-simulator/libgodot.a"
  39. )
  40. if dbg_target_bin_sim != "":
  41. shutil.copy(
  42. dbg_target_bin_sim, app_dir + "/libgodot.ios.debug.xcframework/ios-arm64_x86_64-simulator/libgodot.a"
  43. )
  44. mvk_path = detect_mvk(env, "ios-arm64")
  45. if mvk_path != "":
  46. shutil.copytree(mvk_path, app_dir + "/MoltenVK.xcframework")
  47. # ZIP Xcode project bundle.
  48. zip_dir = Dir("#bin/" + (app_prefix + env.extra_suffix).replace(".", "_")).abspath
  49. shutil.make_archive(zip_dir, "zip", root_dir=app_dir)
  50. shutil.rmtree(app_dir)
  51. ios_lib = [
  52. "godot_ios.mm",
  53. "os_ios.mm",
  54. "main.m",
  55. "app_delegate.mm",
  56. "view_controller.mm",
  57. "ios.mm",
  58. "rendering_context_driver_vulkan_ios.mm",
  59. "display_server_ios.mm",
  60. "joypad_ios.mm",
  61. "godot_view.mm",
  62. "tts_ios.mm",
  63. "display_layer.mm",
  64. "godot_app_delegate.m",
  65. "godot_view_renderer.mm",
  66. "device_metrics.m",
  67. "keyboard_input_view.mm",
  68. "key_mapping_ios.mm",
  69. "ios_terminal_logger.mm",
  70. ]
  71. env_ios = env.Clone()
  72. ios_lib = env_ios.add_library("ios", ios_lib)
  73. # (iOS) Enable module support
  74. env_ios.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
  75. def combine_libs(target=None, source=None, env=None):
  76. lib_path = target[0].srcnode().abspath
  77. if "osxcross" in env:
  78. libtool = "$IOS_TOOLCHAIN_PATH/usr/bin/${ios_triple}libtool"
  79. else:
  80. libtool = "$IOS_TOOLCHAIN_PATH/usr/bin/libtool"
  81. env.Execute(
  82. libtool + ' -static -o "' + lib_path + '" ' + " ".join([('"' + lib.srcnode().abspath + '"') for lib in source])
  83. )
  84. combine_command = env_ios.Command("#bin/libgodot" + env_ios["LIBSUFFIX"], [ios_lib] + env_ios["LIBS"], combine_libs)
  85. if env["generate_bundle"]:
  86. generate_bundle_command = env.Command("generate_bundle", [], generate_bundle)
  87. command = env.AlwaysBuild(generate_bundle_command)
  88. env.Depends(command, [combine_command])