Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cserialport lib #4662

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/c/cserialport/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package("cserialport")
set_homepage("https://github.com/itas109/CSerialPort")
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.")
set_license("LGPL-3.0")

add_urls("https://github.com/itas109/CSerialPort/archive/refs/tags/$(version).tar.gz",
"https://github.com/itas109/CSerialPort.git")

add_versions("v4.3.1", "376f41866be65ddfed91f3d0fea91aaaf5ca7e645f9b9cfcdaa0a9182a0bb3ac")

add_configs("c_api", {description = "Build C API", default = false, type = "boolean"})

if is_plat("windows", "mingw") then
add_syslinks("advapi32")
elseif is_plat("linux", "bsd") then
add_syslinks("pthread")
elseif is_plat("macosx") then
add_frameworks("Foundation", "IOKit")
end

add_deps("cmake")

if on_check then
on_check("windows", function (package)
import("core.base.semver")

if package:is_arch("arm.*") then
local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
assert(vs_toolset and semver.new(vs_toolset):minor() >= 30, "package(cserialport/arm): need vs_toolset >= v143")
end
end)
end

on_install("!cross and !iphoneos and !android", function (package)
local configs = {"-DCSERIALPORT_BUILD_EXAMPLES=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)

if package:config("c_api") then
io.replace("bindings/c/cserialport.h", "#define C_DLL_EXPORT __declspec(dllexport)", "#define C_DLL_EXPORT", {plain = true})
io.writefile("xmake.lua", [[
add_rules("mode.debug", "mode.release")
target("cserialport-c")
set_kind("static")
add_files("bindings/c/cserialport.cpp")
add_headerfiles("bindings/c/cserialport.h")
add_includedirs("include")
]])
import("package.tools.xmake").install(package)
end
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
void test() {
itas109::CSerialPort serialPort;
}
]]}, {configs = {languages = "c++11"}, includes = "CSerialPort/SerialPort.h"}))

if package:config("c_api") then
assert(package:has_cfuncs("CSerialPortInit", {includes = "cserialport.h"}))
end
end)
Loading