plugin.lua 4.5 KB

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