Skip to content

Commit

Permalink
Add a way to create compile_commands.json, lifted from godot-cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivorforce committed Oct 24, 2024
1 parent cb651ca commit c6b3889
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
gdextension_interface.h
extension_api.json

# Build tools
/docs/*build/


compile_commands.json
26 changes: 26 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ from SCons.Errors import UserError

from tools.build import build_utils

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

def normalize_path(val, env):
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)


EnsureSConsVersion(4, 0)

Expand Down Expand Up @@ -61,6 +68,23 @@ opts.Add(
)
)

opts.Add(
BoolVariable(
key="compiledb",
help="Generate compilation DB (`compile_commands.json`) for external tools",
default=env.get("compiledb", False),
)
)

opts.Add(
PathVariable(
key="compiledb_file",
help="Path to a custom `compile_commands.json` file",
default=env.get("compiledb_file", "compile_commands.json"),
validator=validate_parent_dir,
)
)


# Add platform options
tools = {}
Expand Down Expand Up @@ -383,6 +407,8 @@ env.AlwaysBuild(append_python_config)

env.Depends(sources, append_python_config)

env.Tool("compilation_db")
env.Alias("compiledb", env.CompilationDatabase(normalize_path(env["compiledb_file"], env)))

# library name
suffix = ".{}".format(env["platform"])
Expand Down

0 comments on commit c6b3889

Please sign in to comment.