Added libxml2 depdency.
This commit is contained in:
commit
e9607e1411
6 changed files with 98 additions and 0 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Meson
|
||||||
|
/subprojects/*
|
||||||
|
!/subprojects/*.wrap
|
||||||
|
build/**
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode
|
7
include/libxml.h
Normal file
7
include/libxml.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _HEADER_MESONTEST_LIBXML
|
||||||
|
#define _HEADER_MESONTEST_LIBXML
|
||||||
|
|
||||||
|
void info_libxml(void);
|
||||||
|
void create_xml(void);
|
||||||
|
|
||||||
|
#endif // _HEADER_MESONTEST_LIBXML
|
19
meson.build
Normal file
19
meson.build
Normal file
|
@ -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
|
||||||
|
)
|
35
src/libxml.cpp
Normal file
35
src/libxml.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include "libxml.h"
|
||||||
|
|
||||||
|
#include <libxml/xmlversion.h>
|
||||||
|
#include <libxml/parser.h>
|
||||||
|
#include <libxml/tree.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
20
src/main.cpp
Normal file
20
src/main.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
10
subprojects/libxml2.wrap
Normal file
10
subprojects/libxml2.wrap
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue