2
0

xmake.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package("cserialport")
  2. set_homepage("https://github.com/itas109/CSerialPort")
  3. set_description("CSerialPort is a lightweight cross-platform serial port library based on C++, which can easy to read and write serial port on multiple operating system.")
  4. set_license("LGPL-3.0")
  5. add_urls("https://github.com/itas109/CSerialPort/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/itas109/CSerialPort.git")
  7. add_versions("v4.3.3", "e500268b720aaa05fbf332bc2eea598c24b8a436dc52b16c008ec46d56ca0458")
  8. add_versions("v4.3.2", "0d10a0e978ab77b223dca8a37cfeb2b31676f2211d29a486f8e7173bb2e8c27d")
  9. add_versions("v4.3.1", "376f41866be65ddfed91f3d0fea91aaaf5ca7e645f9b9cfcdaa0a9182a0bb3ac")
  10. add_configs("c_api", {description = "Build C API", default = false, type = "boolean"})
  11. if is_plat("windows", "mingw") then
  12. add_syslinks("advapi32")
  13. elseif is_plat("linux", "bsd") then
  14. add_syslinks("pthread")
  15. elseif is_plat("macosx") then
  16. add_frameworks("Foundation", "IOKit")
  17. end
  18. add_deps("cmake")
  19. if on_check then
  20. on_check("windows", function (package)
  21. import("core.base.semver")
  22. if package:is_arch("arm.*") then
  23. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  24. assert(vs_toolset and semver.new(vs_toolset):minor() >= 30, "package(cserialport/arm): need vs_toolset >= v143")
  25. end
  26. end)
  27. end
  28. on_install("!cross and !iphoneos and !android", function (package)
  29. local configs = {"-DCSERIALPORT_BUILD_EXAMPLES=OFF"}
  30. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  31. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  32. import("package.tools.cmake").install(package, configs)
  33. if package:config("c_api") then
  34. io.replace("bindings/c/cserialport.h", "#define C_DLL_EXPORT __declspec(dllexport)", "#define C_DLL_EXPORT", {plain = true})
  35. io.writefile("xmake.lua", [[
  36. add_rules("mode.debug", "mode.release")
  37. target("cserialport-c")
  38. set_kind("static")
  39. add_files("bindings/c/cserialport.cpp")
  40. add_headerfiles("bindings/c/cserialport.h")
  41. add_includedirs("include")
  42. ]])
  43. import("package.tools.xmake").install(package)
  44. end
  45. end)
  46. on_test(function (package)
  47. assert(package:check_cxxsnippets({test = [[
  48. void test() {
  49. itas109::CSerialPort serialPort;
  50. }
  51. ]]}, {configs = {languages = "c++11"}, includes = "CSerialPort/SerialPort.h"}))
  52. if package:config("c_api") then
  53. assert(package:has_cfuncs("CSerialPortInit", {includes = "cserialport.h"}))
  54. end
  55. end)