2
0

resource.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -- Compile corrade resource files. Substitution for cmake corrade_add_resource.
  2. --
  3. -- Usage:
  4. --
  5. -- add_rules("@corrade/resource")
  6. -- add_files("resources.conf", {rule = "@corrade/resource", single = false})
  7. rule("resource")
  8. set_extensions(".conf")
  9. on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
  10. import("core.base.option")
  11. import("lib.detect.find_program")
  12. batchcmds:show_progress(opt.progress, "${color.build.object}compiling.corrade %s", sourcefile)
  13. -- get corrade-rc program
  14. local corrade = find_program("corrade-rc", {check = "-h"})
  15. assert(corrade, "corrade-rc not found! please check your corrade installation.")
  16. -- generate source file
  17. local basename = path.basename(sourcefile)
  18. local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", basename .. ".cpp")
  19. local objectfile = target:objectfile(sourcefile_cx)
  20. table.insert(target:objectfiles(), objectfile)
  21. -- compile
  22. batchcmds:mkdir(path.directory(sourcefile_cx))
  23. local args = {}
  24. local fileconf = target:fileconfig(sourcefile)
  25. if fileconf and fileconf.single then
  26. table.insert(args, "--single")
  27. end
  28. if fileconf and fileconf.name then
  29. table.insert(args, fileconf.name)
  30. else
  31. table.insert(args, basename)
  32. end
  33. local workdir = path.directory(sourcefile)
  34. table.insert(args, path.filename(sourcefile))
  35. table.insert(args, path.relative(sourcefile_cx, workdir))
  36. if option.get("verbose") then
  37. batchcmds:show(corrade .. " " .. os.args(args))
  38. end
  39. local currentdir = os.curdir()
  40. batchcmds:cd(workdir)
  41. batchcmds:vrunv(corrade, args)
  42. batchcmds:cd(currentdir)
  43. batchcmds:compile(sourcefile_cx, objectfile)
  44. -- add dependency
  45. batchcmds:add_depfiles(sourcefile)
  46. batchcmds:set_depmtime(os.mtime(objectfile))
  47. batchcmds:set_depcache(target:dependfile(objectfile))
  48. end)