Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SCons variant_dir support #1439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import os
import platform
import sys
import subprocess

# binding_generator is located in the source tree along with this SConstruct file
sys.path.append(Dir(".").srcnode().abspath)
from binding_generator import scons_generate_bindings, scons_emit_files


Expand Down Expand Up @@ -32,7 +35,7 @@ if profile:
elif os.path.isfile(profile + ".py"):
customs.append(profile + ".py")
opts = Variables(customs, ARGUMENTS)
cpp_tool = Tool("godotcpp", toolpath=["tools"])
cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
cpp_tool.options(opts, env)
opts.Update(env)

Expand Down
42 changes: 26 additions & 16 deletions tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
from binding_generator import scons_generate_bindings, scons_emit_files


def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith("." + extension):
sources.append(dir + "/" + f)


def get_cmdline_bool(option, default):
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
Expand All @@ -30,6 +24,10 @@ def get_cmdline_bool(option, default):


def normalize_path(val, env):
"""Normalize a path that was provided by the user on the command line
and is thus either an absolute path or relative to the top level directory (#)
where the command was run
"""
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)


Expand All @@ -50,9 +48,10 @@ def validate_parent_dir(key, val, env):

def get_platform_tools_paths(env):
path = env.get("custom_tools", None)
tools_path = env.Dir("tools").srcnode().abspath
if path is None:
return ["tools"]
return [normalize_path(path, env), "tools"]
return [tools_path]
return [normalize_path(path, env), tools_path]


def get_custom_platforms(env):
Expand Down Expand Up @@ -511,8 +510,22 @@ def generate(env):


def _godot_cpp(env):
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
extension_dir = env.get("gdextension_dir", None)
# A user provided extension_dir is relative to where they are running from (#)
# But our gdextension directory is here in the source tree
if extension_dir is not None:
extension_dir = normalize_path(extension_dir, env)
else:
extension_dir = env.Dir("gdextension").srcnode().abspath

api_file = env.get("custom_api_file", None)
# A user provided api_file is relative to where they are running from (#)
# But a default api_file is relative to extension_dir
if api_file is not None:
api_file = normalize_path(api_file, env)
else:
api_file = os.path.join(extension_dir, "extension_api.json")

bindings = env.GodotCPPBindings(
env.Dir("."),
[
Expand All @@ -527,15 +540,12 @@ def _godot_cpp(env):
env.NoCache(bindings)

# Sources to compile
sources = []
add_sources(sources, "src", "cpp")
add_sources(sources, "src/classes", "cpp")
add_sources(sources, "src/core", "cpp")
add_sources(sources, "src/variant", "cpp")
sources = env.Glob("src/*.cpp")
sources += env.Glob("src/*/*.cpp")
sources.extend([f for f in bindings if str(f).endswith(".cpp")])

# Includes
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
env.AppendUnique(CPPPATH=[env.Dir(extension_dir), env.Dir("include").srcnode(), env.Dir("gen/include")])

library = None
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]
Expand Down