2
0

plugin.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. -- Usage:
  2. --
  3. -- add_rules("@commonlibsse-ng/plugin", {
  4. -- name = "Plugin name",
  5. -- author = "Author name",
  6. -- description = "Plugin description",
  7. -- email = "[email protected]",
  8. -- options = {
  9. -- address_library = true,
  10. -- signature_scanning = false
  11. -- }
  12. -- })
  13. rule("plugin")
  14. add_deps("win.sdk.resource")
  15. on_config(function(target)
  16. import("core.base.semver")
  17. import("core.project.depend")
  18. import("core.project.project")
  19. target:set("kind", "shared")
  20. target:set("arch", "x64")
  21. local version = semver.new(target:version() or "0.0.0")
  22. local configs = target:extraconf("rules", "@commonlibsse-ng/plugin")
  23. local config_dir = path.join(target:autogendir(), "rules", "commonlibsse", "plugin")
  24. local version_file = path.join(config_dir, "version.rc")
  25. depend.on_changed(function()
  26. local file = io.open(version_file, "w")
  27. if file then
  28. file:print("#include <winres.h>\n")
  29. file:print("1 VERSIONINFO")
  30. file:print("FILEVERSION %s, %s, %s, 0", version:major(), version:minor(), version:patch())
  31. file:print("PRODUCTVERSION %s, %s, %s, 0", version:major(), version:minor(), version:patch())
  32. file:print("FILEFLAGSMASK 0x17L")
  33. file:print("#ifdef _DEBUG")
  34. file:print(" FILEFLAGS 0x1L")
  35. file:print("#else")
  36. file:print(" FILEFLAGS 0x0L")
  37. file:print("#endif")
  38. file:print("FILEOS 0x4L")
  39. file:print("FILETYPE 0x1L")
  40. file:print("FILESUBTYPE 0x0L")
  41. file:print("BEGIN")
  42. file:print(" BLOCK \"StringFileInfo\"")
  43. file:print(" BEGIN")
  44. file:print(" BLOCK \"040904b0\"")
  45. file:print(" BEGIN")
  46. file:print(" VALUE \"FileDescription\", \"%s\"", configs.description or "")
  47. file:print(" VALUE \"FileVersion\", \"%s.0\"", target:version() or "0.0.0")
  48. file:print(" VALUE \"InternalName\", \"%s\"", configs.name or target:name())
  49. file:print(" VALUE \"LegalCopyright\", \"%s, %s\"", configs.author or "", target:license() or "Unknown License")
  50. file:print(" VALUE \"ProductName\", \"%s\"", project.name() or "")
  51. file:print(" VALUE \"ProductVersion\", \"%s.0\"", project.version() or "0.0.0")
  52. file:print(" END")
  53. file:print(" END")
  54. file:print(" BLOCK \"VarFileInfo\"")
  55. file:print(" BEGIN")
  56. file:print(" VALUE \"Translation\", 0x409, 1200")
  57. file:print(" END")
  58. file:print("END")
  59. file:close()
  60. end
  61. end, { dependfile = target:dependfile(version_file), files = project.allfiles()})
  62. local plugin_file = path.join(config_dir, "plugin.cpp")
  63. depend.on_changed(function()
  64. local file = io.open(plugin_file, "w")
  65. if file then
  66. local struct_compat = "Independent"
  67. local runtime_compat = "AddressLibrary"
  68. if configs.options then
  69. local address_library = configs.options.address_library or true
  70. local signature_scanning = configs.options.signature_scanning or false
  71. if not address_library and signature_scanning then
  72. runtime_compat = "SignatureScanning"
  73. end
  74. end
  75. file:print("#include <SKSE/SKSE.h>")
  76. file:print("#include <REL/Relocation.h>\n")
  77. file:print("using namespace std::literals;\n")
  78. file:print("SKSEPluginInfo(")
  79. file:print(" .Version = { %s, %s, %s, 0 },", version:major(), version:minor(), version:patch())
  80. file:print(" .Name = \"%s\"sv,", configs.name or target:name())
  81. file:print(" .Author = \"%s\"sv,", configs.author or "")
  82. file:print(" .SupportEmail = \"%s\"sv,", configs.email or "")
  83. file:print(" .StructCompatibility = SKSE::StructCompatibility::%s,", struct_compat)
  84. file:print(" .RuntimeCompatibility = SKSE::VersionIndependence::%s", runtime_compat)
  85. file:print(")")
  86. file:close()
  87. end
  88. end, { dependfile = target:dependfile(plugin_file), files = project.allfiles()})
  89. target:add("files", version_file)
  90. target:add("files", plugin_file)
  91. target:add("defines", "UNICODE", "_UNICODE")
  92. target:add("cxxflags", "/permissive-", "/Zc:alignedNew", "/Zc:__cplusplus", "/Zc:forScope", "/Zc:ternary")
  93. target:add("cxxflags", "cl::/Zc:externConstexpr", "cl::/Zc:hiddenFriend", "cl::/Zc:preprocessor", "cl::/Zc:referenceBinding")
  94. end)