Skip to content
0.2.0-dev Download ZIP
63 lines ·1.9 KB Raw
1#!/usr/bin/env python
2from misc.utility.scons_hints import *
3
4import os
5
6import modules_builders
7
8Import("env")
9
10env_modules = env.Clone()
11
12# Allow modules to detect if they are being built as a module.
13env_modules.Append(CPPDEFINES=["GODOT_MODULE"])
14
15Export("env_modules")
16
17
18# Header with MODULE_*_ENABLED defines.
19modules_enabled = env.CommandNoCache(
20 "modules_enabled.gen.h", env.Value(env.module_list), env.Run(modules_builders.modules_enabled_builder)
21)
22
23
24register_module_types = env.CommandNoCache(
25 "register_module_types.gen.cpp",
26 [env.Value(env.modules_detected), modules_enabled],
27 env.Run(modules_builders.register_module_types_builder),
28)
29
30
31test_headers = []
32# libmodule_<name>.a for each active module.
33for name, path in env.module_list.items():
34 env.modules_sources = []
35
36 # Name for built-in modules, (absolute) path for custom ones.
37 base_path = path if os.path.isabs(path) else name
38 SConscript(base_path + "/SCsub")
39
40 if env.modules_sources:
41 lib = env_modules.add_library(f"module_{name}", env.modules_sources)
42 env.Prepend(LIBS=[lib])
43
44 if env["tests"]:
45 # Lookup potential headers in `tests` subfolder.
46 import glob
47
48 module_tests = sorted(glob.glob(os.path.join(base_path, "tests", "*.h")))
49 if module_tests != []:
50 test_headers += module_tests
51
52
53# Generate header to be included in `tests/test_main.cpp` to run module-specific tests.
54if env["tests"]:
55 env.CommandNoCache("modules_tests.gen.h", test_headers, env.Run(modules_builders.modules_tests_builder))
56
57# libmodules.a with only register_module_types.
58# Must be last so that all libmodule_<name>.a libraries are on the right side
59# in the linker command.
60env.modules_sources = []
61env_modules.add_source_files(env.modules_sources, register_module_types)
62lib = env_modules.add_library("modules", env.modules_sources)
63env.Prepend(LIBS=[lib])