SConstruct 6.0 KB

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