xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

Simplify package description #4507

Closed star-hengxing closed 10 months ago

star-hengxing commented 11 months ago

Is your feature request related to a problem? Please describe.

Add some helpful interface.

Describe the solution you'd like

Before:

on_install(function (package)
    local configs = {}
    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)
end)

on_test(function (package)
    local cxflags
    if package:is_plat("windows") then
        cxflags = {"/Zc:__cplusplus", "/permissive-"}
    else
        cxflags = "-fPIC"
    end
    assert(package:check_cxxsnippets({test = [[
        #include <QtAwesome/QtAwesome.h>
        void test() {
            fa::QtAwesome* awesome = new fa::QtAwesome(nullptr);
            awesome->initFontAwesome();
        }
    ]]}, {configs = {languages = "c++17", cxflags = cxflags}}))
end)

Now:

on_install(function (package)
    local configs = {
        "CMAKE_BUILD_TYPE" = (package:is_debug() and "Debug" or "Release"),
        "BUILD_SHARED_LIBS" = package:config("shared")
    }
    configs = import("package.tools.cmake").genconfig(configs)
    import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
    assert(package:check_qt_snippets({test = [[
        #include <QtAwesome/QtAwesome.h>
        void test() {
            fa::QtAwesome* awesome = new fa::QtAwesome(nullptr);
            awesome->initFontAwesome();
        }
    ]]}))
end)

Describe alternatives you've considered

No response

Additional context

No response

waruqi commented 11 months ago

on_install 没感觉简化了,反而更复杂了,之前4行,现在6行,还要 import 两次 cmake

on_test 部分不考虑。。package 这种不会去加 qt 特有的接口package:check_qt_snippets。。都是通用接口。