当前位置:网站首页>Xmake help 2

Xmake help 2

2022-06-11 19:34:00 fqbqrr

Example

target("demo")

    --  When building a library , prohibit 
    if has_config("onlylib") then
        set_default(false)
    end

    --  Plus dependence 
    add_deps("xmake")

    -- exe
    set_kind("binary")

    --  Add definition 
    add_defines("__tb_prefix__=\"xmake\"")

    --  Add include directory 
    add_includedirs("$(projectdir)", "$(projectdir)/src")

    --  Add source 
    add_files("**.c")

    --  Add resource file .
    if is_plat("windows") then
        add_files("*.rc")
    end

    --  Add links 
    if is_plat("windows") then
        add_links("ws2_32", "advapi32", "shell32")
        add_ldflags("/export:malloc", "/export:free")
    else
        add_links("pthread", "dl", "m", "c")
    end

    -- xp compatible .
    if is_plat("windows") then
        if is_arch("x86") then
            add_ldflags("/subsystem:console,5.01")
        else
            add_ldflags("/subsystem:console,5.02")
        end
    end

    --  Copy into build directory .
    after_build(function (target)
        os.cp(target:targetfile(), "$(buildir)/xmake" .. (is_plat("windows") and ".exe" or ""))
    end)


Plus mode

add_rules("mode.release", "mode.debug")
if is_mode("release") then
    set_optimize("smallest")
    if is_plat("windows") then
        add_ldflags("/LTCG")
    end
end

Mark and define

add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing", "-Wno-error=nullability-completeness", "-Wno-error=parentheses-equality")

--  Add definition 
add_defines("_GNU_SOURCE=1", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE")

--  Window platform 
if is_plat("windows") then
    add_cxflags("-MT")
    add_ldflags("-nodefaultlib:msvcrt.lib")
    add_links("kernel32", "user32", "gdi32")
--  Add links 
end
--  Plus engineering 
includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/lua", "src/tbox", "src/xmake", "src/demo")

Add configuration directory

    set_configdir("$(buildir)/config")
    add_configfiles("test.c.in", {
    filename = "mytest.c"})
    add_includedirs("$(buildir)/config/header")
// Add include directory 

Header file only

target("foo")
    set_kind("headeronly")
    add_headerfiles("src/foo.h")
    add_rules("utils.install.cmake_importfiles")
    add_rules("utils.install.pkgconfig_importfiles")
    add_files("src/*.manifest")
// Add list 
template("console")
    add_configfiles("xmake.lua")
// Templates , Add configuration file .

Tooling chain

toolchain("dlang")

    --  Home page , describe 
    set_homepage("https://dlang.org/")
    set_description("D Language ")

    --  Check 
    on_check("check")

    --  load 
    on_load(function (toolchain)

        --  Import 
        import("core.project.config")

        --  Prefix 
        local cross = toolchain:cross() or ""

        --  Toolset 
        toolchain:add("toolset", "dc",   "$(env DC)", "dmd", "ldc2", cross .. "gdc")
        toolchain:add("toolset", "dcld", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
        toolchain:add("toolset", "dcsh", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
        toolchain:add("toolset", "dcar", "$(env DC)", "dmd", "ldc2", cross .. "gcc-ar")

        --  Initial flag 
        local march
        if toolchain:is_arch("x86_64", "x64") then
            march = "-m64"
        elseif toolchain:is_arch("i386", "x86") then
            march = "-m32"
        end
        toolchain:add("dcflags",   march or "")
        toolchain:add("dcshflags", march or "")
        toolchain:add("dcldflags", march or "")
    end)

xmake Of xmake

target("xmake")

    --  Static library 
    set_kind("static")

    --  Plus dependence 
    if has_config("curses") or has_config("pdcurses") then
        add_deps("lcurses")
    end
    add_deps("sv", "lua-cjson", "tbox")
    add_deps(get_config("runtime"))

    --  Add definition 
    add_defines("__tb_prefix__=\"xmake\"")
    if is_mode("debug") then
        add_defines("__tb_debug__", {
    public = true})
    end

    --  Set to generate automatically ` To configure .h`
    set_configdir("$(buildir)/$(plat)/$(arch)/$(mode)")
    add_configfiles("xmake.config.h.in")

    --  Add include directory 
    add_includedirs("..", {
    interface = true})
    add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)", {
    public = true})

    --  Header file .
    add_headerfiles("../(xmake/*.h)")
    add_headerfiles("../(xmake/prefix/*.h)")
    add_headerfiles("$(buildir)/$(plat)/$(arch)/$(mode)/xmake.config.h", {
    prefixdir = "xmake"})

    --  Add source file 
    add_files("**.c|winos/*.c")
    if is_plat("windows", "msys", "cygwin") then
        add_files("winos/*.c")
    end

    --  Plus options 
    add_options("readline")
    if is_plat("windows") then
        add_defines("UNICODE", "_UNICODE")
    end

Define the rules

rule("markdown")
    set_extensions(".md", ".markdown")
    on_load(function (target)
        print("markdown: on_load")
    end)
    on_build_file(function (target, sourcefile)
        print("compile %s", sourcefile)
        os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
    end)

About the same , Yes , Look again .

原网站

版权声明
本文为[fqbqrr]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011816581247.html