123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #!/usr/bin/env python
- import os
- import sys
- import subprocess
- from methods import print_error
- def normalize_path(val, env):
- return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
- def validate_parent_dir(key, val, env):
- if not os.path.isdir(normalize_path(os.path.dirname(val), env)):
- raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))
- libname = "spine_godot"
- projectdir = "example-v4-extension"
- localEnv = Environment(tools=["default"], PLATFORM="")
- customs = ["custom.py"]
- customs = [os.path.abspath(path) for path in customs]
- opts = Variables(customs, ARGUMENTS)
- opts.Add(
- BoolVariable(
- key="compiledb",
- help="Generate compilation DB (`compile_commands.json`) for external tools",
- default=localEnv.get("compiledb", False),
- )
- )
- opts.Add(
- PathVariable(
- key="compiledb_file",
- help="Path to a custom `compile_commands.json` file",
- default=localEnv.get("compiledb_file", "compile_commands.json"),
- validator=validate_parent_dir,
- )
- )
- opts.Update(localEnv)
- Help(opts.GenerateHelpText(localEnv))
- env = localEnv.Clone()
- env["compiledb"] = False
- env.Tool("compilation_db")
- compilation_db = env.CompilationDatabase(
- normalize_path(localEnv["compiledb_file"], localEnv)
- )
- env.Alias("compiledb", compilation_db)
- submodule_initialized = False
- dir_name = 'godot-cpp'
- if os.path.isdir(dir_name):
- if os.listdir(dir_name):
- submodule_initialized = True
- if not submodule_initialized:
- print_error("""godot-cpp is not available within this folder, as Git submodules haven't been initialized.
- Run the following command to download godot-cpp:
- git submodule update --init --recursive""")
- sys.exit(1)
- env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})
- env.Append(CPPDEFINES=["SPINE_GODOT_EXTENSION"])
- env.Append(CPPPATH=["spine_godot", "spine_godot/spine-cpp/include"])
- # Set iOS minimum deployment target
- if env["platform"] == "ios":
- env.Append(CCFLAGS=["-miphoneos-version-min=12.0"])
- env.Append(LINKFLAGS=["-miphoneos-version-min=12.0"])
- # sources = Glob("spine_godot/*.cpp") + Glob("spine_godot/spine-cpp/src/spine/*.cpp")
- sources = Glob("spine_godot/spine-cpp/src/spine/*.cpp")
- sources.append("spine_godot/GodotSpineExtension.cpp")
- sources.append("spine_godot/SpineAnimation.cpp")
- sources.append("spine_godot/SpineAnimationState.cpp")
- sources.append("spine_godot/SpineAnimationTrack.cpp")
- sources.append("spine_godot/SpineAtlasResource.cpp")
- sources.append("spine_godot/SpineAttachment.cpp")
- sources.append("spine_godot/SpineBone.cpp")
- sources.append("spine_godot/SpineBoneData.cpp")
- sources.append("spine_godot/SpineBoneNode.cpp")
- sources.append("spine_godot/SpineConstant.cpp")
- sources.append("spine_godot/SpineConstraintData.cpp")
- sources.append("spine_godot/SpineEditorPlugin.cpp")
- sources.append("spine_godot/SpineEvent.cpp")
- sources.append("spine_godot/SpineEventData.cpp")
- sources.append("spine_godot/SpineIkConstraint.cpp")
- sources.append("spine_godot/SpineIkConstraintData.cpp")
- sources.append("spine_godot/SpinePathConstraint.cpp")
- sources.append("spine_godot/SpinePathConstraintData.cpp")
- sources.append("spine_godot/SpinePhysicsConstraint.cpp")
- sources.append("spine_godot/SpinePhysicsConstraintData.cpp")
- sources.append("spine_godot/SpineSkeleton.cpp")
- sources.append("spine_godot/SpineSkeletonDataResource.cpp")
- sources.append("spine_godot/SpineSkeletonFileResource.cpp")
- sources.append("spine_godot/SpineSkin.cpp")
- sources.append("spine_godot/SpineSlot.cpp")
- sources.append("spine_godot/SpineSlotData.cpp")
- sources.append("spine_godot/SpineSlotNode.cpp")
- sources.append("spine_godot/SpineSprite.cpp")
- sources.append("spine_godot/SpineTimeline.cpp")
- sources.append("spine_godot/SpineTrackEntry.cpp")
- sources.append("spine_godot/SpineTransformConstraint.cpp")
- sources.append("spine_godot/SpineTransformConstraintData.cpp")
- sources.append("spine_godot/register_types.cpp")
- if env["target"] in ["editor", "template_debug"]:
- try:
- doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("spine_godot/docs/*.xml"))
- sources.append(doc_data)
- except AttributeError:
- print("Not including class reference as we're targeting a pre-4.3 baseline.")
- file = "lib{}{}{}".format(libname, env["suffix"], env["SHLIBSUFFIX"])
- filepath = ""
- if env["platform"] == "macos" or env["platform"] == "ios":
- filepath = "lib{}.{}.{}.framework/".format(libname, env["platform"], env["target"])
- file = "lib{}.{}.{}".format(libname, env["platform"], env["target"])
- env.Append(LINKFLAGS=["-Wl,-install_name,@rpath/{}{}".format(filepath, file)])
- libraryfile = "bin/{}/{}{}".format(env["platform"], filepath, file)
- library = env.SharedLibrary(
- libraryfile,
- source=sources,
- )
- if env["platform"] == "macos" or env["platform"] == "ios":
- plist_subst = {
- "${BUNDLE_LIBRARY}": file,
- "${BUNDLE_NAME}": "spine-godot",
- "${BUNDLE_IDENTIFIER}": "com.esotericsoftware.spine.spine-godot",
- "${BUNDLE_VERSION}": subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').strip().split('-')[0] + '.0',
- "${MIN_MACOS_VERSION}": "10.12",
- "${MIN_IOS_VERSION}": "12.0"
- }
- if env["platform"] == "macos":
- plist_file = "bin/macos/{}Resources/Info.plist".format(filepath)
- plist = env.Substfile(
- target=plist_file,
- source="Info.macos.plist",
- SUBST_DICT=plist_subst
- )
- elif env["platform"] == "ios":
- plist_file = "bin/ios/{}Info.plist".format(filepath)
- plist = env.Substfile(
- target=plist_file,
- source="Info.ios.plist",
- SUBST_DICT=plist_subst
- )
- env.Depends(library, plist)
- copy = env.InstallAs("{}/{}".format(projectdir, libraryfile), library)
- default_args = [library, copy]
- if env["platform"] == "macos" or env["platform"] == "ios":
- copy_plist = env.InstallAs("{}/{}".format(projectdir, plist_file), plist_file)
- default_args.append(copy_plist)
- if localEnv.get("compiledb", False):
- default_args += [compilation_db]
- Default(*default_args)
|