2
0

xmake.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package("libmodbus")
  2. set_homepage("https://libmodbus.org")
  3. set_description("A Modbus library for Linux, Mac OS, FreeBSD and Windows")
  4. set_license("LGPL-2.1")
  5. add_urls("https://github.com/stephane/libmodbus/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/stephane/libmodbus.git")
  7. add_versions("v3.1.10", "e93503749cd89fda4c8cf1ee6371a3a9cc1f0a921c165afbbc4fd96d4813fa1a")
  8. if is_plat("mingw") and is_subhost("msys") then
  9. add_extsources("pacman::libmodbus")
  10. elseif is_plat("linux") then
  11. add_extsources("pacman::libmodbus", "apt::libmodbus")
  12. elseif is_plat("macosx") then
  13. add_extsources("brew::libmodbus")
  14. end
  15. if is_plat("windows", "mingw") then
  16. add_syslinks("ws2_32")
  17. end
  18. on_load(function (package)
  19. if (not is_host("windows")) and (not is_subhost("msys", "cygwin")) then
  20. package:add("deps", "autoconf", "automake", "libtool")
  21. end
  22. end)
  23. on_install("windows", "linux", "macosx", "mingw", "msys", "cross", function (package)
  24. if (not is_host("windows")) and (not is_subhost("msys", "cygwin")) then
  25. import("package.tools.autoconf").install(package, {"--disable-tests"})
  26. return
  27. end
  28. local configs = {}
  29. io.writefile("xmake.lua", [[
  30. add_rules("mode.debug", "mode.release")
  31. target("modbus")
  32. set_kind("$(kind)")
  33. add_files("src/*.c")
  34. add_headerfiles("src/*.h", {prefixdir = "modbus"})
  35. add_syslinks("ws2_32")
  36. add_includedirs("src/win32")
  37. if is_plat("windows") then
  38. add_files("src/win32/modbus.rc")
  39. add_defines("HAVE_CONFIG_H", "_CRT_SECURE_NO_DEPRECATE=1", "_CRT_NONSTDC_NO_DEPRECATE=1")
  40. if is_mode("debug") then
  41. add_defines("W32DEBUG")
  42. end
  43. if is_kind("shared") then
  44. add_defines("DLLBUILD")
  45. end
  46. end
  47. before_build(function (target)
  48. local old = os.cd("src/win32")
  49. os.exec("cscript /nologo configure.js")
  50. os.cd(old)
  51. end)
  52. ]])
  53. if package:config("shared") then
  54. configs.kind = "shared"
  55. else
  56. if package:is_plat("windows") then
  57. io.replace("src/modbus.h", "# define MODBUS_API __declspec(dllimport)", "# define MODBUS_API", {plain = true})
  58. end
  59. end
  60. import("package.tools.xmake").install(package, configs)
  61. end)
  62. on_test(function (package)
  63. assert(package:has_cfuncs("modbus_new_tcp", {includes = "modbus/modbus.h"}))
  64. end)