leethomason / tinyxml2

TinyXML2 is a simple, small, efficient, C++ XML parser that can be easily integrated into other programs.
zlib License
5.11k stars 1.84k forks source link

Add xmake build system #974

Closed AstroAir closed 7 months ago

AstroAir commented 7 months ago

Sorry to bother you, I would like to add an xmake build system to this project, which is a more flexible and convenient build method. Here are possible build scripts:

-- xmake.lua

set_xmakever("2.7.2")

add_rules("mode.debug", "mode.release")

option("shared")
    set_default(false)
    set_showmenu(true)
    set_description("Build shared library")
option_end()

option("cxx_std")
    set_default("cxx11")
    set_showmenu(true)
    set_description("C++ standard")
    set_values("cxx98", "cxx11", "cxx14", "cxx17", "cxx20")
option_end()

target("tinyxml2")
    set_kind("$(kind)")
    set_languages(get_config("cxx_std"))
    add_files("tinyxml2.cpp")
    add_headerfiles("tinyxml2.h")
    add_includedirs("$(projectdir)", {public = true})

    if is_mode("debug") then
        add_defines("TINYXML2_DEBUG", {public = true})
    end

    if is_plat("windows") then
        add_defines("_CRT_SECURE_NO_WARNINGS", {private = true})
    end

    add_defines("_FILE_OFFSET_BITS=64", {public = true})

    set_configvar("TINYXML2_EXPORT", "tinyxml2_EXPORT")
    set_configdir("$(buildir)/config")

    set_version("9.0.0")
    set_symbols("none")

    on_install(function (target)
        local configs = {}
        configs.mode = is_mode("debug") and "debug" or "release"
        configs.kind = target:kind()
        if is_plat("windows") then
            configs.shared = target:kind() == "shared"
            configs.vs_runtime = target:config("vs_runtime")
        end
        import("package.tools.xmake").install(target, {configs = configs})
    end)
target_end()

if has_config("shared") then
    set_kind("shared")
else
    set_kind("static")
end

-- Installation
set_installdir("$(buildir)/install")

option("install_pkgconfigdir")
    set_default("$(installdir)/lib/pkgconfig")
    set_showmenu(true)
    set_description("Directory for pkgconfig files")
option_end()

option("install_cmakedir")
    set_default("$(installdir)/lib/cmake/tinyxml2")
    set_showmenu(true)
    set_description("Path to tinyxml2 CMake files")
option_end()

task("install")
    on_run(function ()
        import("core.project.config")
        import("package.tools.xmake")

        local configs = {}
        configs.mode = is_mode("debug") and "debug" or "release"
        configs.kind = is_mode("debug") and "debug" or "release"
        if is_plat("windows") then
            configs.shared = has_config("shared")
            configs.vs_runtime = get_config("vs_runtime")
        end

        local packagedirs = {}
        packagedirs.pkgconfig = get_config("install_pkgconfigdir")
        packagedirs.cmake = get_config("install_cmakedir")

        os.cp("tinyxml2.h", "$(installdir)/include")

        package.tools.xmake.install(target("tinyxml2"), {installdir = "$(installdir)", configs = configs, packagedirs = packagedirs})
    end)
task_end()
leethomason commented 7 months ago

I appreciate it, and I don't doubt that xmake could be better than cmake. But I have to stop adding build systems - too hard to maintain, not enough testing, and they go stale. CMake is the supported system for now.