From e4242b048a38d5103aa72464208efc0c7f4cce40 Mon Sep 17 00:00:00 2001 From: star9029 Date: Wed, 29 May 2024 23:59:42 +0800 Subject: [PATCH] cpuinfo: add clog (#4191) * cpuinfo: add clog * improve on_check --- packages/c/cpuinfo/clog.lua | 10 ++++++++++ packages/c/cpuinfo/xmake.lua | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/c/cpuinfo/clog.lua diff --git a/packages/c/cpuinfo/clog.lua b/packages/c/cpuinfo/clog.lua new file mode 100644 index 000000000..846521ebf --- /dev/null +++ b/packages/c/cpuinfo/clog.lua @@ -0,0 +1,10 @@ +function main(package) + os.cd("deps/clog") + local configs = {"-DCLOG_BUILD_TESTS=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + table.insert(configs, "-DCLOG_RUNTIME_TYPE=" .. (package:config("shared") and "shared" or "static")) + if package:config("shared") and package:is_plat("windows") then + table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON") + end + import("package.tools.cmake").install(package, configs) +end diff --git a/packages/c/cpuinfo/xmake.lua b/packages/c/cpuinfo/xmake.lua index b97c1b53c..4d253fe11 100644 --- a/packages/c/cpuinfo/xmake.lua +++ b/packages/c/cpuinfo/xmake.lua @@ -10,6 +10,7 @@ package("cpuinfo") if is_plat("windows") then add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) end + add_configs("clog", {description = "Build clog library.", default = false, type = "boolean"}) add_deps("cmake") if is_plat("windows") then @@ -18,12 +19,12 @@ package("cpuinfo") add_syslinks("pthread") end - on_check("windows|arm.*", function (package) + on_check("windows", function (package) import("core.tool.toolchain") import("core.base.semver") local msvc = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}) - if msvc then + if msvc and package:is_arch("arm.*") then local vs_sdkver = msvc:config("vs_sdkver") assert(vs_sdkver and semver.match(vs_sdkver):gt("10.0.19041"), "package(cpuinfo): need vs_sdkver > 10.0.19041.0") end @@ -57,6 +58,10 @@ package("cpuinfo") end end import("package.tools.cmake").install(package, configs) + + if package:config("clog") then + import("clog")(package) + end end) on_test(function (package) @@ -67,4 +72,8 @@ package("cpuinfo") std::cout << "Running on CPU " << cpuinfo_get_package(0)->name; } ]]}, {configs = {languages = "c++11"}, includes = "cpuinfo.h"})) + + if package:config("clog") then + assert(package:has_cfuncs("clog_vlog_info", {includes = "clog.h"})) + end end)