summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-02-06 17:28:32 +0100
committerRémi Verschelde <rverschelde@gmail.com>2020-02-07 11:31:37 +0100
commitb7297fb39ca7a55390f9390666bd29803adc827f (patch)
treed5e6f977177db1beab58745fbb53205e9c741e79 /modules
parent00f46452b0206afe6aca79b0c4cd4a205f99067b (diff)
SCons: Generate header with info on which modules are enabled
We already had `MODULE_*_ENABLED` defines but only in the modules environment, and a few custom `*_ENABLED` defines in the main env when we needed the information in core. Now this is defined in a single header which can be included in the files that need this information.
Diffstat (limited to 'modules')
-rw-r--r--modules/SCsub12
-rw-r--r--modules/modules_builders.py16
-rw-r--r--modules/register_module_types.h4
3 files changed, 23 insertions, 9 deletions
diff --git a/modules/SCsub b/modules/SCsub
index dc0420616c..75483fd637 100644
--- a/modules/SCsub
+++ b/modules/SCsub
@@ -2,19 +2,19 @@
Import('env')
+import modules_builders
+
env_modules = env.Clone()
Export('env_modules')
-env.modules_sources = []
+env.CommandNoCache("modules_enabled.gen.h", Value(env.module_list), modules_builders.generate_modules_enabled)
+env.modules_sources = []
env_modules.add_source_files(env.modules_sources, "register_module_types.gen.cpp")
-for x in env.module_list:
- if (x in env.disabled_modules):
- continue
- env_modules.Append(CPPDEFINES=["MODULE_" + x.upper() + "_ENABLED"])
- SConscript(x + "/SCsub")
+for module in env.module_list:
+ SConscript(module + "/SCsub")
if env['split_libmodules']:
env.split_lib("modules", env_lib = env_modules)
diff --git a/modules/modules_builders.py b/modules/modules_builders.py
new file mode 100644
index 0000000000..0e9cba2b0b
--- /dev/null
+++ b/modules/modules_builders.py
@@ -0,0 +1,16 @@
+"""Functions used to generate source files during build time
+
+All such functions are invoked in a subprocess on Windows to prevent build flakiness.
+"""
+
+from platform_methods import subprocess_main
+
+
+def generate_modules_enabled(target, source, env):
+ with open(target[0].path, 'w') as f:
+ for module in env.module_list:
+ f.write('#define %s\n' % ("MODULE_" + module.upper() + "_ENABLED"))
+
+
+if __name__ == '__main__':
+ subprocess_main(globals())
diff --git a/modules/register_module_types.h b/modules/register_module_types.h
index a8eb68b929..b410457201 100644
--- a/modules/register_module_types.h
+++ b/modules/register_module_types.h
@@ -31,9 +31,7 @@
#ifndef REGISTER_MODULE_TYPES_H
#define REGISTER_MODULE_TYPES_H
-//
-
void register_module_types();
void unregister_module_types();
-#endif
+#endif // REGISTER_MODULE_TYPES_H