From 7491a33d85e2724f98cc30296aaf6cddd7be7680 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sat, 28 Sep 2024 20:43:05 +0800 Subject: [PATCH] xmake compilation is supported --- benchmark/xmake.lua | 26 ++++++++++++++++++ include/libimp/log.h | 8 ++++-- src/libimp/xmake.lua | 6 +++++ src/libipc/xmake.lua | 22 ++++++++++++++++ src/libpmr/xmake.lua | 7 +++++ src/xmake.lua | 1 + test/xmake.lua | 25 ++++++++++++++++++ xmake.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 benchmark/xmake.lua create mode 100644 src/libimp/xmake.lua create mode 100644 src/libipc/xmake.lua create mode 100644 src/libpmr/xmake.lua create mode 100644 src/xmake.lua create mode 100644 test/xmake.lua create mode 100644 xmake.lua diff --git a/benchmark/xmake.lua b/benchmark/xmake.lua new file mode 100644 index 0000000..d78539a --- /dev/null +++ b/benchmark/xmake.lua @@ -0,0 +1,26 @@ +add_requires("benchmark 1.9.*", "fmt 11.0.*") + +target("benchmark-ipc") + set_kind("binary") + add_deps("imp", "pmr", "ipc") + add_packages("benchmark", "fmt") + if is_os("windows") then + add_ldflags("/subsystem:console") + elseif is_os("linux") then + add_syslinks("rt") + end + on_config(config_target_compilation) + on_config(function (target) + if target:has_tool("cxx", "cl") then + target:add("defines", "_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING") + else + target:add("cxflags", "-Wno-missing-field-initializers" + , "-Wno-unused-variable" + , "-Wno-unused-function" + , "-Wno-unused-result") + end + end) + add_includedirs("$(projectdir)/include" + , "$(projectdir)/src" + , "$(projectdir)/test") + add_files("*.cpp") diff --git a/include/libimp/log.h b/include/libimp/log.h index b1650af..888a07c 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -187,7 +187,11 @@ inline auto make_logger(char const * /*ignore*/, char const *name, level level_l return make_logger(name, make_std_out(), level_limit); } +#define LIBIMP_LOG_(...) \ + auto log \ + = [](auto &&...args) noexcept { \ + return ::LIBIMP::log::make_logger(__func__, std::forward(args)...); \ + }(__VA_ARGS__) + } // namespace log LIBIMP_NAMESPACE_END_ - -#define LIBIMP_LOG_(...) auto log = ::LIBIMP::log::make_logger(__func__,##__VA_ARGS__) \ No newline at end of file diff --git a/src/libimp/xmake.lua b/src/libimp/xmake.lua new file mode 100644 index 0000000..cb464bd --- /dev/null +++ b/src/libimp/xmake.lua @@ -0,0 +1,6 @@ +target("imp") + set_kind("static") + on_config(config_target_compilation) + add_includedirs("$(projectdir)/include", {public = true}) + add_includedirs("$(projectdir)/src") + add_files("$(projectdir)/src/libimp/**.cpp") diff --git a/src/libipc/xmake.lua b/src/libipc/xmake.lua new file mode 100644 index 0000000..a15966f --- /dev/null +++ b/src/libipc/xmake.lua @@ -0,0 +1,22 @@ +target("ipc") + if has_config("build_shared_lib") then + set_kind("shared") + add_defines("LIBIMP_LIBRARY_SHARED_BUILDING__") + else + set_kind("static") + end + add_deps("imp", "pmr") + if is_os("linux") then + add_syslinks("pthread", "rt") + elseif is_os("windows") then + add_syslinks("Advapi32") + end + on_config(config_target_compilation) + on_config(function (target) + if (not target:has_tool("cxx", "cl")) and has_config("build_shared_lib") then + target:add("linkgroups", "imp", "pmr", {whole = true}) + end + end) + add_includedirs("$(projectdir)/include", {public = true}) + add_includedirs("$(projectdir)/src") + add_files("$(projectdir)/src/libipc/**.cpp") diff --git a/src/libpmr/xmake.lua b/src/libpmr/xmake.lua new file mode 100644 index 0000000..02ccfe2 --- /dev/null +++ b/src/libpmr/xmake.lua @@ -0,0 +1,7 @@ +target("pmr") + set_kind("static") + add_deps("imp") + on_config(config_target_compilation) + add_includedirs("$(projectdir)/include", {public = true}) + add_includedirs("$(projectdir)/src") + add_files("$(projectdir)/src/libpmr/**.cpp") diff --git a/src/xmake.lua b/src/xmake.lua new file mode 100644 index 0000000..6182196 --- /dev/null +++ b/src/xmake.lua @@ -0,0 +1 @@ +includes("libimp", "libpmr", "libipc") diff --git a/test/xmake.lua b/test/xmake.lua new file mode 100644 index 0000000..4426414 --- /dev/null +++ b/test/xmake.lua @@ -0,0 +1,25 @@ +add_requires("gtest 1.15.*", {configs = {main = true}}) + +target("test-ipc") + set_kind("binary") + add_deps("ipc") + add_packages("gtest") + add_links("gtest_main") + if is_os("windows") then + add_ldflags("/subsystem:console") + end + on_config(config_target_compilation) + on_config(function (target) + if target:has_tool("cxx", "cl") then + target:add("cxflags", "/wd4723") + else + target:add("links", "gtest_main") + target:add("cxflags", "-Wno-missing-field-initializers" + , "-Wno-unused-variable" + , "-Wno-unused-function") + end + end) + add_includedirs("$(projectdir)/include" + , "$(projectdir)/src" + , "$(projectdir)/test") + add_files("$(projectdir)/test/**.cpp") diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..18f522a --- /dev/null +++ b/xmake.lua @@ -0,0 +1,63 @@ +set_project("cpp-ipc") +set_version("2.0.0", {build = "%Y%m%d%H%M"}) + +-- Build all of libipc's own tests. +option("build_tests") set_default(false) +-- Build all of libipc's own demos. +option("build_demos") set_default(false) +-- Build all of libipc's own benchmark tests. +option("build_benchmarks") set_default(false) +-- Build shared libraries (DLLs). +option("build_shared_lib") set_default(false) +-- Set to ON to build with static CRT on Windows (/MT). +option("use_static_crt") set_default(false) +-- Build with unit test coverage. +option("use_codecov") set_default(false) +option_end() + +add_rules("mode.debug", "mode.release") +set_languages("cxx17") +if is_mode("debug") then + if has_config("use_static_crt") then + set_runtimes("MTd") + else + set_runtimes("MDd") + end +else + if has_config("use_static_crt") then + set_runtimes("MT") + else + set_runtimes("MD") + end +end + +function config_target_compilation(target) + if target:has_tool("cxx", "cl") then + target:add("defines", "UNICODE", "_UNICODE") + if is_mode("debug") then + target:add("cxflags", "/Zi") + end + else + target:add("cxflags", "-fPIC", "-Wno-attributes") + if has_config("use_codecov") then + target:add("cxflags", "--coverage") + target:add("ldflags", "--coverage") + target:add("syslinks", "gcov") + end + if is_mode("debug") then + target:add("cxflags", "-rdynamic -fsanitize=address") + target:add("ldflags", "-fsanitize=address") + end + end +end + +includes("src") +if has_config("build_tests") then + includes("test") +end +if has_config("build_demos") then + includes("demo") +end +if has_config("build_benchmarks") then + includes("benchmark") +end