Skip to content

Commit

Permalink
Add godot-cpp template build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhermeGSousa committed Nov 13, 2024
1 parent 30631e3 commit 5ae861d
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ bin

compile_commands.json

src/gen

# Ignored demos
demo_*/

Expand Down
151 changes: 111 additions & 40 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,28 +1,100 @@
# #!/usr/bin/env python
# import os
# import sys
# from glob import glob
# from pathlib import Path

# env = SConscript("godot-cpp/SConstruct")

# # For reference:
# # - CCFLAGS are compilation flags shared between C and C++
# # - CFLAGS are for C-specific compilation flags
# # - CXXFLAGS are for C++-specific compilation flags
# # - CPPFLAGS are for pre-processor flags
# # - CPPDEFINES are for pre-processor defines
# # - LINKFLAGS are for linking flags

# (extension_path,) = glob("addons/*/*.gdextension")

# addon_path = Path(extension_path).parent

# project_name = Path(extension_path).stem

# debug_or_release = "release" if env["target"] == "template_release" else "debug"

# # tweak this if you want to use different folders, or more folders, to store your source code in.
# env.Append(CPPPATH=["src/"])
# sources = Glob("src/*.cpp")
# sources += Glob("src/editor/*.cpp")
# sources += Glob("src/features/*.cpp")
# sources += Glob("src/math/*.cpp")
# sources += Glob("src/modifiers/*.cpp")
# sources += Glob("src/synchronizers/*.cpp")

# if env["platform"] == "macos":
# library = env.SharedLibrary(
# "{0}/bin/lib{1}.{2}.{3}.framework/{1}.{2}.{3}".format(
# addon_path,
# project_name,
# env["platform"],
# debug_or_release,
# ),
# source=sources,
# )
# else:
# library = env.SharedLibrary(
# "{}/bin/lib{}.{}.{}.{}{}".format(
# addon_path,
# project_name,
# env["platform"],
# debug_or_release,
# env["arch"],
# env["SHLIBSUFFIX"],
# ),
# source=sources,
# )


# Default(library)


#!/usr/bin/env python
import os
import sys
from glob import glob
from pathlib import Path

env = SConscript("godot-cpp/SConstruct")
from methods import print_error

# For reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags

(extension_path,) = glob("addons/*/*.gdextension")
libname = "godot-motion-matching"
projectdir = "addons"

addon_path = Path(extension_path).parent
localEnv = Environment(tools=["default"], PLATFORM="")

project_name = Path(extension_path).stem
customs = ["custom.py"]
customs = [os.path.abspath(path) for path in customs]

debug_or_release = "release" if env["target"] == "template_release" else "debug"
opts = Variables(customs, ARGUMENTS)
opts.Update(localEnv)

Help(opts.GenerateHelpText(localEnv))

env = localEnv.Clone()

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})

# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
sources += Glob("src/editor/*.cpp")
Expand All @@ -31,28 +103,27 @@ sources += Glob("src/math/*.cpp")
sources += Glob("src/modifiers/*.cpp")
sources += Glob("src/synchronizers/*.cpp")

if env["platform"] == "macos":
library = env.SharedLibrary(
"{0}/bin/lib{1}.{2}.{3}.framework/{1}.{2}.{3}".format(
addon_path,
project_name,
env["platform"],
debug_or_release,
),
source=sources,
)
else:
library = env.SharedLibrary(
"{}/bin/lib{}.{}.{}.{}{}".format(
addon_path,
project_name,
env["platform"],
debug_or_release,
env["arch"],
env["SHLIBSUFFIX"],
),
source=sources,
)


Default(library)
if env["target"] in ["editor", "template_debug"]:
try:
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
sources.append(doc_data)
except AttributeError:
print("Not including class reference as we're targeting a pre-4.3 baseline.")

file = "{}{}{}".format(libname, env["suffix"], env["SHLIBSUFFIX"])
filepath = ""

if env["platform"] == "macos" or env["platform"] == "ios":
filepath = "{}.framework/".format(env["platform"])
file = "{}.{}.{}".format(libname, env["platform"], env["target"])

libraryfile = "bin/{}/{}{}".format(env["platform"], filepath, file)
library = env.SharedLibrary(
libraryfile,
source=sources,
)

copy = env.InstallAs("{}/bin/{}/{}lib{}".format(projectdir, env["platform"], filepath, file), library)

default_args = [library, copy]
Default(*default_args)
52 changes: 52 additions & 0 deletions methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import sys
from enum import Enum

# Colors are disabled in non-TTY environments such as pipes. This means
# that if output is redirected to a file, it won't contain color codes.
# Colors are always enabled on continuous integration.
_colorize = bool(sys.stdout.isatty() or os.environ.get("CI"))


class ANSI(Enum):
"""
Enum class for adding ansi colorcodes directly into strings.
Automatically converts values to strings representing their
internal value, or an empty string in a non-colorized scope.
"""

RESET = "\x1b[0m"

BOLD = "\x1b[1m"
ITALIC = "\x1b[3m"
UNDERLINE = "\x1b[4m"
STRIKETHROUGH = "\x1b[9m"
REGULAR = "\x1b[22;23;24;29m"

BLACK = "\x1b[30m"
RED = "\x1b[31m"
GREEN = "\x1b[32m"
YELLOW = "\x1b[33m"
BLUE = "\x1b[34m"
MAGENTA = "\x1b[35m"
CYAN = "\x1b[36m"
WHITE = "\x1b[37m"

PURPLE = "\x1b[38;5;93m"
PINK = "\x1b[38;5;206m"
ORANGE = "\x1b[38;5;214m"
GRAY = "\x1b[38;5;244m"

def __str__(self) -> str:
global _colorize
return str(self.value) if _colorize else ""


def print_warning(*values: object) -> None:
"""Prints a warning message with formatting."""
print(f"{ANSI.YELLOW}{ANSI.BOLD}WARNING:{ANSI.REGULAR}", *values, ANSI.RESET, file=sys.stderr)


def print_error(*values: object) -> None:
"""Prints an error message with formatting."""
print(f"{ANSI.RED}{ANSI.BOLD}ERROR:{ANSI.REGULAR}", *values, ANSI.RESET, file=sys.stderr)

0 comments on commit 5ae861d

Please sign in to comment.