From afae9338b3a97b450832f9278cf53f0f42b4f623 Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Thu, 29 Feb 2024 02:15:45 +0000 Subject: [PATCH] inih: add package (#3359) * inih: add package * inih: change test to only index test.ini * inih: use xmake instead of meson * inih: change main to test * inih: remove use prefix * inih: remove meson and ninja * inih: fix config for ini_parser test * inih: fix INIReader include * inih: Make tests smaller and remove 'r' from version * inih: use method to add 'r' to version --- packages/i/inih/port/xmake.lua | 45 ++++++++++++++++++++++++++++ packages/i/inih/xmake.lua | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 packages/i/inih/port/xmake.lua create mode 100644 packages/i/inih/xmake.lua diff --git a/packages/i/inih/port/xmake.lua b/packages/i/inih/port/xmake.lua new file mode 100644 index 000000000..c5ea6ebd5 --- /dev/null +++ b/packages/i/inih/port/xmake.lua @@ -0,0 +1,45 @@ +add_rules("mode.debug", "mode.release") + +option("ini_parser", {description = "compile and (if selected) install INIReader", default = true, type = "boolean"}) +option("heap", {description = "allocate memory on the heap using malloc instead using a fixed-sized line buffer on the stack", default = false, type = "boolean"}) +option("max_line_length", {description = "maximum line length in bytes", default = "200", type = "string"}) +option("allow_realloc", {description = "allow initial malloc size to grow to max line length (when using the heap)", default = false, type = "boolean"}) + +target("inih") + set_kind("$(kind)") + set_languages("c++11") + + add_files("ini.c") + add_headerfiles("(ini.h)") + + if has_config("ini_parser") then + add_files("cpp/INIReader.cpp") + add_headerfiles("cpp/(INIReader.h)") + end + + if has_config("heap") then + add_defines("INI_USE_STACK=0") + end + + if has_config("max_line_length") then + add_defines("INI_MAX_LINE=" .. get_config("max_line_length")) + end + + if has_config("allow_realloc") then + add_defines("INI_ALLOW_REALLOC=1") + end + + if is_plat("windows") then + add_defines("_WIN32") + end + + if is_kind("shared") then + add_defines("INI_SHARED_LIB") + add_defines("INI_SHARED_LIB_BUILDING") + end + + on_config(function (target) + if target:has_tool("gcc", "gxx") then + target:add("defines", "__GNUC__") + end + end) diff --git a/packages/i/inih/xmake.lua b/packages/i/inih/xmake.lua new file mode 100644 index 000000000..69b5016c3 --- /dev/null +++ b/packages/i/inih/xmake.lua @@ -0,0 +1,55 @@ +package("inih") + set_homepage("https://github.com/benhoyt/inih") + set_description("Simple .INI file parser in C, good for embedded systems") + + add_urls("https://github.com/benhoyt/inih/archive/refs/tags/$(version).tar.gz", {version = function (version) return "r" .. version end}) + add_urls("https://github.com/benhoyt/inih.git") + + add_versions("58", "e79216260d5dffe809bda840be48ab0eec7737b2bb9f02d2275c1b46344ea7b7") + + add_configs("ini_parser", {description = "compile and (if selected) install INIReader", default = true, type = "boolean"}) + add_configs("heap", {description = "allocate memory on the heap using malloc instead using a fixed-sized line buffer on the stack", default = false, type = "boolean"}) + add_configs("max_line_length", {description = "maximum line length in bytes", default = "200", type = "string"}) + add_configs("allow_realloc", {description = "allow initial malloc size to grow to max line length (when using the heap)", default = false, type = "boolean"}) + + on_install(function (package) + os.cp(path.join(os.scriptdir(), "port", "xmake.lua"), "xmake.lua") + local configs = {} + configs.ini_parser = package:config("ini_parser") + configs.heap = package:config("heap") + configs.max_line_length = package:config("max_line_length") + configs.allow_realloc = package:config("allow_realloc") + import("package.tools.xmake").install(package, configs) + end) + + on_test(function (package) + assert(package:check_cxxsnippets({test = [[ + #include "ini.h" + + typedef struct { } configuration; + + static int handler(void* user, const char* section, const char* name, const char* value) { return 1; } + + int test(int argc, char* argv[]) + { + configuration config; + if (ini_parse("test.ini", handler, &config) < 0) { + return 1; + } + return 0; + } + ]]}, {configs = {languages = "cxx11"}})) + + if package:config("ini_parser") then + assert(package:check_cxxsnippets({test = [[ + #include + #include "INIReader.h" + + int test() + { + INIReader reader("test.ini"); + return 0; + } + ]]}, {configs = {languages = "cxx11"}})) + end + end)