commit e9607e14118aa270ac54e28d50bcb34e73b01677 Author: Yohan Boujon Date: Wed Mar 12 10:29:39 2025 +0100 Added libxml2 depdency. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5d201a --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Meson +/subprojects/* +!/subprojects/*.wrap +build/** + +# VSCode +.vscode \ No newline at end of file diff --git a/include/libxml.h b/include/libxml.h new file mode 100644 index 0000000..8e4d1ab --- /dev/null +++ b/include/libxml.h @@ -0,0 +1,7 @@ +#ifndef _HEADER_MESONTEST_LIBXML +#define _HEADER_MESONTEST_LIBXML + +void info_libxml(void); +void create_xml(void); + +#endif // _HEADER_MESONTEST_LIBXML diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f858504 --- /dev/null +++ b/meson.build @@ -0,0 +1,19 @@ +project('meson-test', 'cpp', + version : '0.1', + default_options : ['warning_level=3', 'cpp_std=c++11'] +) + +# Libraries +libxml2_proj = subproject('libxml2', default_options: ['python=false', 'default_library=static']) +libxml2_dep = libxml2_proj.get_variable('xml_dep') + +# Include directories +incdir = include_directories('include') + +# Executable +executable('mesontest', + 'src/libxml.cpp', + 'src/main.cpp', + dependencies: libxml2_dep, + include_directories : incdir +) \ No newline at end of file diff --git a/src/libxml.cpp b/src/libxml.cpp new file mode 100644 index 0000000..3ad31e8 --- /dev/null +++ b/src/libxml.cpp @@ -0,0 +1,35 @@ +#include "libxml.h" + +#include +#include +#include +#include + +void info_libxml(void) +{ + std::cout << "[LIBXML2]\tversion: " << LIBXML_DOTTED_VERSION << std::endl; +} + +void create_xml(void) +{ + std::cout << "[LIBXML2]\tWriting basic .xml file..." << std::endl; + // Create new doc + xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); + xmlNodePtr root_node = xmlNewNode(nullptr, BAD_CAST "root"); + xmlDocSetRootElement(doc, root_node); + + xmlNodePtr child1 = xmlNewChild(root_node, nullptr, BAD_CAST "child1", BAD_CAST "This is child 1"); + xmlNewProp(child1, BAD_CAST "attribute", BAD_CAST "value"); + + // Save the document + const char* filename = "example.xml"; + if (xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1) != -1) { + std::cout << "[LIBXML2]\tXML file created successfully: " << filename << std::endl; + } else { + std::cerr << "LIBXML2]\tError saving XML file!" << std::endl; + } + + // Clean up + xmlFreeDoc(doc); + xmlCleanupParser(); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..88d1292 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,20 @@ +#include + +#include "libxml.h" + +int main(void) +{ + try + { + std::cout << "Libxml2 Test..." << std::endl; + info_libxml(); + create_xml(); + std::cout << "Enter any key to quit the program\n> "; + std::cin.ignore(); + } + catch (const std::exception &ex) + { + std::cerr << "\033[0;31m[ ERR]:\t" << ex.what() << "\033[0m" << std::flush; + } + return 0; +} diff --git a/subprojects/libxml2.wrap b/subprojects/libxml2.wrap new file mode 100644 index 0000000..574b6d9 --- /dev/null +++ b/subprojects/libxml2.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = libxml2-2.13.6 +source_url = https://download.gnome.org/sources/libxml2/2.13/libxml2-2.13.6.tar.xz +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libxml2_2.13.6-1/libxml2-2.13.6.tar.xz +source_filename = libxml2-2.13.6.tar.xz +source_hash = f453480307524968f7a04ec65e64f2a83a825973bcd260a2e7691be82ae70c96 +wrapdb_version = 2.13.6-1 + +[provide] +libxml-2.0 = xml_dep