set_project("bitserial") set_version("1.0.0") add_rules("mode.debug", "mode.release", "mode.releasedbg", "mode.minsizerel") set_languages("c++20") add_cxxflags("/Zc:preprocessor", "/utf-8", {tools = "cl"}) if is_plat("mingw") then add_ldflags("-static", "-static-libgcc", "-static-libstdc++") end task("export_all") set_menu { usage = "xmake export_all", description = "Generate the single-header bitserial_all.hpp" } on_run(function () local rootdir = os.projectdir() local output = path.join(rootdir, "bitserial_all.hpp") local headers = { "include/bitserial/detail/config.hpp", "include/bitserial/bit_io.hpp", "include/bitserial/bulk.hpp", "include/bitserial/bitserial.hpp" } local out = { "// This file is generated by `xmake export_all`.", "// Do not edit it directly; edit headers under include/bitserial instead.", "#pragma once" } local function append_header(header) table.insert(out, "") table.insert(out, "// =============================================================================") table.insert(out, "// " .. header) table.insert(out, "// =============================================================================") local content = io.readfile(path.join(rootdir, header)) content = content:gsub("\r\n", "\n") for line in (content .. "\n"):gmatch("(.-)\n") do if not line:match("^%s*#pragma%s+once%s*$") and not line:match("^%s*#%s*include%s*[<\"]bitserial/") then table.insert(out, line) end end end for _, header in ipairs(headers) do append_header(header) end io.writefile(output, table.concat(out, "\n") .. "\n") cprint("${bright green}generated ${clear}%s", output) end) target("bitserial") set_kind("headeronly") add_headerfiles("bitserial.hpp", "include/(bitserial/**.hpp)") add_includedirs(".", "include", {public = true}) target("bitserial_catch2") set_kind("static") add_files("third_party/catch2/catch_amalgamated.cpp") add_includedirs("third_party/catch2", {public = true}) target("bitserial_tests") set_kind("binary") add_files("tests/bitserial_tests.cpp") add_deps("bitserial", "bitserial_catch2") target("bitserial_benchmarks") set_kind("binary") add_files("benchmarks/baq_bulk_benchmarks.cpp") add_deps("bitserial", "bitserial_catch2") if is_arch("x64", "x86") then add_cxxflags("/arch:AVX2", {tools = "cl"}) add_cxxflags("-O3", "-mavx2", "-mbmi2", {tools = {"gcc", "clang"}}) end add_ldflags("/STACK:33554432", {tools = "link"})