0.2.0-dev Download ZIP
63 lines ·1.9 KB Raw
| 1 | #!/usr/bin/env python |
| 2 | from misc.utility.scons_hints import * |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | import modules_builders |
| 7 | |
| 8 | Import("env") |
| 9 | |
| 10 | env_modules = env.Clone() |
| 11 | |
| 12 | # Allow modules to detect if they are being built as a module. |
| 13 | env_modules.Append(CPPDEFINES=["GODOT_MODULE"]) |
| 14 | |
| 15 | Export("env_modules") |
| 16 | |
| 17 | |
| 18 | # Header with MODULE_*_ENABLED defines. |
| 19 | modules_enabled = env.CommandNoCache( |
| 20 | "modules_enabled.gen.h", env.Value(env.module_list), env.Run(modules_builders.modules_enabled_builder) |
| 21 | ) |
| 22 | |
| 23 | |
| 24 | register_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 | |
| 31 | test_headers = [] |
| 32 | # libmodule_<name>.a for each active module. |
| 33 | for 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. |
| 54 | if 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. |
| 60 | env.modules_sources = [] |
| 61 | env_modules.add_source_files(env.modules_sources, register_module_types) |
| 62 | lib = env_modules.add_library("modules", env.modules_sources) |
| 63 | env.Prepend(LIBS=[lib]) |