From 9a75e083eedde92a300012a202388724f8ad9e1a Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Thu, 13 Mar 2025 11:09:39 +0100 Subject: [PATCH] Added template file generated by meson. --- gen/host.cpp.template | 10 ++++++++++ include/host.h | 8 ++++++++ meson.build | 16 ++++++++++++++++ src/main.cpp | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 gen/host.cpp.template create mode 100644 include/host.h diff --git a/gen/host.cpp.template b/gen/host.cpp.template new file mode 100644 index 0000000..026bf54 --- /dev/null +++ b/gen/host.cpp.template @@ -0,0 +1,10 @@ +#include "host.h" + +const std::string _uname = "@UNAME@"; +const std::string _gcc = "@GCC_VERSION@"; +const std::string _ninja = "@NINJA_VERSION@"; + +std::string get_host_info() +{ + return "[ OS]: "+_uname+"\n[ GCC]: "+_gcc+"\n[NINJ]: Ninja v"+_ninja; +} diff --git a/include/host.h b/include/host.h new file mode 100644 index 0000000..c5a48ee --- /dev/null +++ b/include/host.h @@ -0,0 +1,8 @@ +#ifndef _HEADER_MESONTEST_HOST +#define _HEADER_MESONTEST_HOST + +#include + +std::string get_host_info(); + +#endif // _HEADER_MESONTEST_HOST diff --git a/meson.build b/meson.build index 2bc8d74..c98146c 100644 --- a/meson.build +++ b/meson.build @@ -26,8 +26,24 @@ poco_dep_util = poco_proj.dependency(['Util']) # Include directories incdir = include_directories('include') +# Meson template +uname = run_command('sh', '-c', 'echo "$(uname -o) $(uname -r)"').stdout().strip() +gcc_version = meson.get_compiler('c').version() +ninja_version = run_command('ninja', '--version').stdout().strip() + +host_template = configure_file( + input: 'gen/host.cpp.template', + output: 'host.cpp', + configuration: { + 'UNAME': '@0@'.format(uname), + 'GCC_VERSION': '@0@'.format(gcc_version), + 'NINJA_VERSION': '@0@'.format(ninja_version) + } +) + # Executable executable('mesontest', + host_template, 'src/libxml_meson.cpp', 'src/poco.cpp', 'src/main.cpp', diff --git a/src/main.cpp b/src/main.cpp index 25b498a..5e1b9e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "poco.h" #include "libxml_meson.h" +#include "host.h" void info_poco(void); @@ -10,6 +11,7 @@ int main(void) { try { + std::cout << "Compiled under:\n" << get_host_info() << "\n" << std::endl; std::cout << "Poco Test..." << std::endl; info_poco(); std::cout << "Libxml2 Test..." << std::endl;