SCsub 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. from misc.utility.scons_hints import *
  3. from glob import glob
  4. from pathlib import Path
  5. import methods
  6. Import("env")
  7. env.platform_sources = []
  8. # Generate export icons
  9. def export_icon_builder(target, source, env):
  10. src_path = Path(str(source[0]))
  11. src_name = src_path.stem
  12. platform = src_path.parent.parent.stem
  13. with open(str(source[0]), "r") as file:
  14. svg = file.read()
  15. with methods.generated_wrapper(target, prefix=platform) as file:
  16. file.write(
  17. f"""\
  18. static const char *_{platform}_{src_name}_svg = {methods.to_raw_cstring(svg)};
  19. """
  20. )
  21. for platform in env.platform_exporters:
  22. for path in glob(f"{platform}/export/*.svg"):
  23. env.CommandNoCache(path.replace(".svg", "_svg.gen.h"), path, env.Run(export_icon_builder))
  24. # Register platform-exclusive APIs
  25. def register_platform_apis_builder(target, source, env):
  26. platforms = source[0].read()
  27. api_inc = "\n".join([f'#include "{p}/api/api.h"' for p in platforms])
  28. api_reg = "\n".join([f"\tregister_{p}_api();" for p in platforms])
  29. api_unreg = "\n".join([f"\tunregister_{p}_api();" for p in platforms])
  30. with methods.generated_wrapper(target) as file:
  31. file.write(
  32. f"""\
  33. #include "register_platform_apis.h"
  34. {api_inc}
  35. void register_platform_apis() {{
  36. {api_reg}
  37. }}
  38. void unregister_platform_apis() {{
  39. {api_unreg}
  40. }}
  41. """
  42. )
  43. register_platform_apis = env.CommandNoCache(
  44. "register_platform_apis.gen.cpp", env.Value(env.platform_apis), env.Run(register_platform_apis_builder)
  45. )
  46. env.add_source_files(env.platform_sources, register_platform_apis)
  47. for platform in env.platform_apis:
  48. env.add_source_files(env.platform_sources, f"{platform}/api/*.cpp")
  49. lib = env.add_library("platform", env.platform_sources)
  50. env.Prepend(LIBS=[lib])