SConstruct 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. from methods import print_error
  5. def normalize_path(val, env):
  6. return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
  7. def validate_parent_dir(key, val, env):
  8. if not os.path.isdir(normalize_path(os.path.dirname(val), env)):
  9. raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))
  10. libname = "spine_godot"
  11. projectdir = "example-v4-extension"
  12. localEnv = Environment(tools=["default"], PLATFORM="")
  13. customs = ["custom.py"]
  14. customs = [os.path.abspath(path) for path in customs]
  15. opts = Variables(customs, ARGUMENTS)
  16. opts.Add(
  17. BoolVariable(
  18. key="compiledb",
  19. help="Generate compilation DB (`compile_commands.json`) for external tools",
  20. default=localEnv.get("compiledb", False),
  21. )
  22. )
  23. opts.Add(
  24. PathVariable(
  25. key="compiledb_file",
  26. help="Path to a custom `compile_commands.json` file",
  27. default=localEnv.get("compiledb_file", "compile_commands.json"),
  28. validator=validate_parent_dir,
  29. )
  30. )
  31. opts.Update(localEnv)
  32. Help(opts.GenerateHelpText(localEnv))
  33. env = localEnv.Clone()
  34. env["compiledb"] = False
  35. env.Tool("compilation_db")
  36. compilation_db = env.CompilationDatabase(
  37. normalize_path(localEnv["compiledb_file"], localEnv)
  38. )
  39. env.Alias("compiledb", compilation_db)
  40. submodule_initialized = False
  41. dir_name = 'godot-cpp'
  42. if os.path.isdir(dir_name):
  43. if os.listdir(dir_name):
  44. submodule_initialized = True
  45. if not submodule_initialized:
  46. print_error("""godot-cpp is not available within this folder, as Git submodules haven't been initialized.
  47. Run the following command to download godot-cpp:
  48. git submodule update --init --recursive""")
  49. sys.exit(1)
  50. env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
  51. env.Append(CPPDEFINES=["SPINE_GODOT_EXTENSION"])
  52. env.Append(CPPPATH=["spine_godot", "spine_godot/spine-cpp/include"])
  53. # sources = Glob("spine_godot/*.cpp") + Glob("spine_godot/spine-cpp/src/spine/*.cpp")
  54. sources = Glob("spine_godot/spine-cpp/src/spine/*.cpp")
  55. sources.append("spine_godot/GodotSpineExtension.cpp")
  56. sources.append("spine_godot/SpineAnimation.cpp")
  57. sources.append("spine_godot/SpineAnimationState.cpp")
  58. sources.append("spine_godot/SpineAnimationTrack.cpp")
  59. sources.append("spine_godot/SpineAtlasResource.cpp")
  60. sources.append("spine_godot/SpineAttachment.cpp")
  61. sources.append("spine_godot/SpineBone.cpp")
  62. sources.append("spine_godot/SpineBoneData.cpp")
  63. sources.append("spine_godot/SpineBoneNode.cpp")
  64. sources.append("spine_godot/SpineConstant.cpp")
  65. sources.append("spine_godot/SpineConstraintData.cpp")
  66. sources.append("spine_godot/SpineEditorPlugin.cpp")
  67. sources.append("spine_godot/SpineEvent.cpp")
  68. sources.append("spine_godot/SpineEventData.cpp")
  69. sources.append("spine_godot/SpineIkConstraint.cpp")
  70. sources.append("spine_godot/SpineIkConstraintData.cpp")
  71. sources.append("spine_godot/SpinePathConstraint.cpp")
  72. sources.append("spine_godot/SpinePathConstraintData.cpp")
  73. sources.append("spine_godot/SpinePhysicsConstraint.cpp")
  74. sources.append("spine_godot/SpinePhysicsConstraintData.cpp")
  75. sources.append("spine_godot/SpineSkeleton.cpp")
  76. sources.append("spine_godot/SpineSkeletonDataResource.cpp")
  77. sources.append("spine_godot/SpineSkeletonFileResource.cpp")
  78. sources.append("spine_godot/SpineSkin.cpp")
  79. sources.append("spine_godot/SpineSlot.cpp")
  80. sources.append("spine_godot/SpineSlotData.cpp")
  81. sources.append("spine_godot/SpineSlotNode.cpp")
  82. sources.append("spine_godot/SpineSprite.cpp")
  83. sources.append("spine_godot/SpineTimeline.cpp")
  84. sources.append("spine_godot/SpineTrackEntry.cpp")
  85. sources.append("spine_godot/SpineTransformConstraint.cpp")
  86. sources.append("spine_godot/SpineTransformConstraintData.cpp")
  87. sources.append("spine_godot/register_types.cpp")
  88. if env["target"] in ["editor", "template_debug"]:
  89. try:
  90. doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("spine_godot/docs/*.xml"))
  91. sources.append(doc_data)
  92. except AttributeError:
  93. print("Not including class reference as we're targeting a pre-4.3 baseline.")
  94. file = "lib{}{}{}".format(libname, env["suffix"], env["SHLIBSUFFIX"])
  95. filepath = ""
  96. if env["platform"] == "macos" or env["platform"] == "ios":
  97. filepath = "lib{}.{}.{}.framework/".format(libname, env["platform"], env["target"])
  98. file = "lib{}.{}.{}".format(libname, env["platform"], env["target"])
  99. env.Append(LINKFLAGS=["-Wl,-install_name,@rpath/{}{}".format(filepath, file)])
  100. libraryfile = "bin/{}/{}{}".format(env["platform"], filepath, file)
  101. library = env.SharedLibrary(
  102. libraryfile,
  103. source=sources,
  104. )
  105. if env["platform"] == "macos" or env["platform"] == "ios":
  106. plist_subst = {
  107. "${BUNDLE_LIBRARY}": file,
  108. "${BUNDLE_NAME}": "spine-godot",
  109. "${BUNDLE_IDENTIFIER}": "com.esotericsoftware.spine.spine-godot",
  110. "${BUNDLE_VERSION}": "4.2.0", # TODO: Get the proper version from somewhere. Note that this must be three integers.
  111. "${MIN_MACOS_VERSION}": "10.12",
  112. "${MIN_IOS_VERSION}": "12.0"
  113. }
  114. if env["platform"] == "macos":
  115. plist_file = "bin/macos/{}Resources/Info.plist".format(filepath)
  116. plist = env.Substfile(
  117. target=plist_file,
  118. source="Info.macos.plist",
  119. SUBST_DICT=plist_subst
  120. )
  121. elif env["platform"] == "ios":
  122. plist_file = "bin/ios/{}Info.plist".format(filepath)
  123. plist = env.Substfile(
  124. target=plist_file,
  125. source="Info.ios.plist",
  126. SUBST_DICT=plist_subst
  127. )
  128. env.Depends(library, plist)
  129. copy = env.InstallAs("{}/{}".format(projectdir, libraryfile), library)
  130. default_args = [library, copy]
  131. if env["platform"] == "macos" or env["platform"] == "ios":
  132. copy_plist = env.InstallAs("{}/{}".format(projectdir, plist_file), plist_file)
  133. default_args.append(copy_plist)
  134. if localEnv.get("compiledb", False):
  135. default_args += [compilation_db]
  136. Default(*default_args)