diff --git a/packages/l/libgpiod/port/xmake.lua b/packages/l/libgpiod/port/xmake.lua new file mode 100644 index 000000000..5977caea2 --- /dev/null +++ b/packages/l/libgpiod/port/xmake.lua @@ -0,0 +1,52 @@ +option("enable_bindings_cxx", {default = true, showmenu = true, description = "Enable C++ bindings"}) +option("enable_tools", {default = true, showmenu = true, description = "Enable tools"}) + +target("gpiod") + set_kind("$(kind)") + set_languages("cxx11") + + add_headerfiles("include/(gpiod.h)") + add_headerfiles("lib/uapi/*.h") + add_files("lib/*.c") + + add_includedirs("include", {public = true}) + + before_build(function (target) + local configure = io.readfile("configure.ac") + local version = configure:match("AC_INIT%(%[libgpiod%], %[?([0-9%.]+)%]?%)") + target:add("defines", "GPIOD_VERSION_STR=\"" .. version .. "\"") + end) + +if has_config("enable_bindings_cxx") then + target("gpiodcxx") + set_kind("$(kind)") + set_languages("cxx17") + + add_headerfiles("bindings/cxx/(gpiod.hpp)") + add_headerfiles("bindings/cxx/(gpiodcxx/**.hpp)") + add_files("bindings/cxx/*.cpp") + + add_includedirs("bindings/cxx", {public = true}) + + add_deps("gpiod") +end + +if has_config("enable_tools") then + for _, tool_file in ipairs(os.files("tools/*.c")) do + local name = path.basename(tool_file) + if name ~= "tools-common" then + target(name) + set_kind("binary") + set_languages("cxx11") + + add_files("tools/" .. name .. ".c") + add_headerfiles("tools/tools-common.h") + add_files("tools/tools-common.c") + + add_defines("program_invocation_short_name=\"" .. name .. "\"") + add_defines("program_invocation_name=\"" .. name .. "\"") + + add_deps("gpiod") + end + end +end \ No newline at end of file diff --git a/packages/l/libgpiod/xmake.lua b/packages/l/libgpiod/xmake.lua index d4f732800..8f0dc991b 100644 --- a/packages/l/libgpiod/xmake.lua +++ b/packages/l/libgpiod/xmake.lua @@ -7,18 +7,40 @@ package("libgpiod") add_versions("v2.0.1", "cf0d4db1d94cc99281de142063d0e28f42760c4d918d6b8854e1b27811517c34") add_versions("v2.0", "a0f835c4ca4a2a3ca021090b574235ba58bb9fd612d8a6051fb1350054e04fdd") add_versions("v1.6.4", "9f920260c46b155f65cba8796dcf159e4ba56950b85742af357d75a1af709e68") - - add_deps("autoconf-archive", "automake", "libtool", "pkg-config") + + add_configs("enable_bindings_cxx", {description = "Enable C++ bindings", default = true, type = "boolean"}) + add_configs("enable_tools", {description = "Enable tools", default = true, type = "boolean"}) on_install("linux", function (package) - local configs = {"--enable-tools=yes", "--enable-bindings-cxx"} - table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no")) - table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes")) - import("package.tools.autoconf").install(package, configs) + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + local configs = {} + if package:config("enable_bindings_cxx") then + configs.enable_bindings_cxx = true + end + if package:config("enable_tools") then + configs.enable_tools = true + end + import("package.tools.xmake").install(package) package:addenv("PATH", "bin") end) on_test(function (package) - os.runv("gpiodetect") - assert(package:has_cfuncs("gpiod_api_version", {includes = "gpiod.h"})) + assert(package:check_cxxsnippets({test = [[ + #include + void test() { + struct gpiod_chip *chip; + chip = gpiod_chip_open("/dev/null"); + } + ]]}, {configs = {languages = "c++11"}})) + if package:config("enable_bindings_cxx") then + assert(package:check_cxxsnippets({test = [[ + #include + void test() { + gpiod::chip chip("/dev/null"); + } + ]]}, {configs = {languages = "c++17"}})) + end + if package:config("enable_tools") then + os.runv("gpiodetect") + end end)