xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.2", "0d10a0e978ab77b223dca8a37cfeb2b31676f2211d29a486f8e7173bb2e8c27d")
  8. add_versions("v4.3.1", "376f41866be65ddfed91f3d0fea91aaaf5ca7e645f9b9cfcdaa0a9182a0bb3ac")
  9. add_configs("c_api", {description = "Build C API", default = false, type = "boolean"})
  10. if is_plat("windows", "mingw") then
  11. add_syslinks("advapi32")
  12. elseif is_plat("linux", "bsd") then
  13. add_syslinks("pthread")
  14. elseif is_plat("macosx") then
  15. add_frameworks("Foundation", "IOKit")
  16. end
  17. add_deps("cmake")
  18. if on_check then
  19. on_check("windows", function (package)
  20. import("core.base.semver")
  21. if package:is_arch("arm.*") then
  22. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  23. assert(vs_toolset and semver.new(vs_toolset):minor() >= 30, "package(cserialport/arm): need vs_toolset >= v143")
  24. end
  25. end)
  26. end
  27. on_install("!cross and !iphoneos and !android", function (package)
  28. local configs = {"-DCSERIALPORT_BUILD_EXAMPLES=OFF"}
  29. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  30. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  31. import("package.tools.cmake").install(package, configs)
  32. if package:config("c_api") then
  33. io.replace("bindings/c/cserialport.h", "#define C_DLL_EXPORT __declspec(dllexport)", "#define C_DLL_EXPORT", {plain = true})
  34. io.writefile("xmake.lua", [[
  35. add_rules("mode.debug", "mode.release")
  36. target("cserialport-c")
  37. set_kind("static")
  38. add_files("bindings/c/cserialport.cpp")
  39. add_headerfiles("bindings/c/cserialport.h")
  40. add_includedirs("include")
  41. ]])
  42. import("package.tools.xmake").install(package)
  43. end
  44. end)
  45. on_test(function (package)
  46. assert(package:check_cxxsnippets({test = [[
  47. void test() {
  48. itas109::CSerialPort serialPort;
  49. }
  50. ]]}, {configs = {languages = "c++11"}, includes = "CSerialPort/SerialPort.h"}))
  51. if package:config("c_api") then
  52. assert(package:has_cfuncs("CSerialPortInit", {includes = "cserialport.h"}))
  53. end
  54. end)