xmake.lua 2.7 KB

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