Initial commit.

This commit is contained in:
Yohan Boujon 2025-03-10 12:12:52 +01:00
commit 4a913ea465
9 changed files with 244 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
# Generated code
build/**
# VSCode
.vscode/**

14
CMakeLists.txt Normal file
View file

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.18)
project(protocolstack_test_fetch)
# C/C++ Standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Dependencies
include(dependencies.cmake)
# Game source files
add_subdirectory(fetchtest)

62
dependencies.cmake Normal file
View file

@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.11)
# Poco
set(ENABLE_MONGODB OFF)
set(ENABLE_REDIS OFF)
set(ENABLE_DATA_SQLITE OFF)
set(ENABLE_DATA_MYSQL OFF)
set(ENABLE_DATA_ODBC OFF)
set(ENABLE_ZIP OFF)
set(ENABLE_PAGECOMPILER OFF) # Disable PageCompiler (unused binary)
set(ENABLE_PAGECOMPILER_FILE2PAGE OFF) # Disable File2Page (unused binary)
# Will maybe change later, for now we want the lib to be static.
set(POCO_STATIC ON)
find_package(Poco QUIET)
if (NOT Poco_FOUND)
include(FetchContent)
FetchContent_Declare(
Poco
DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/pocoproject/poco/archive/refs/tags/poco-1.9.4-release.tar.gz
)
FetchContent_GetProperties(Poco)
FetchContent_MakeAvailable(Poco)
set(Poco_INCLUDE_DIRS
"${poco_SOURCE_DIR}/Foundation/include"
"${poco_SOURCE_DIR}/Encodings/include"
"${poco_SOURCE_DIR}/XML/include"
"${poco_SOURCE_DIR}/JSON/include"
"${poco_SOURCE_DIR}/Util/include"
"${poco_SOURCE_DIR}/Net/include"
"${poco_SOURCE_DIR}/Data/include"
)
endif()
# LibXML2
set(LIBXML2_WITH_PROGRAMS OFF) # Disable programs
set(LIBXML2_WITH_TESTS OFF) # Disable tests
# Disabling every dependencies to build libxml2
set(LIBXML2_WITH_PYTHON OFF)
set(LIBXML2_WITH_ICONV OFF)
set(LIBXML2_WITH_LZMA OFF)
set(LIBXML2_WITH_ZLIB OFF)
# Will maybe change later, for now we want the lib to be static.
set(BUILD_SHARED_LIBS OFF)
find_package(libxml2 QUIET)
if (NOT (libxml2_FOUND OR LIBXML2_FOUND))
include(FetchContent)
FetchContent_Declare(
libxml2
GIT_REPOSITORY https://gitlab.gnome.org/GNOME/libxml2.git
GIT_TAG v2.12.6
)
FetchContent_GetProperties(libxml2)
FetchContent_MakeAvailable(libxml2)
set(LIBXML2_INCLUDE_DIR
"${libxml2_SOURCE_DIR}/include"
"${libxml2_BINARY_DIR}"
)
set(LIBXML2_LIBRARY "${libxml2_BINARY_DIR}/libxml2.a")
endif()

54
fetchtest/CMakeLists.txt Normal file
View file

@ -0,0 +1,54 @@
# Project
project(
fetchtest
VERSION 1.0.0
DESCRIPTION "fetchtest"
HOMEPAGE_URL "https://cmake.org/"
LANGUAGES CXX C
)
set(TARGET fetchtest)
# Source files
set(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src")
add_executable(${TARGET}
${SOURCES}/libxml.cpp
${SOURCES}/poco.cpp
${SOURCES}/main.cpp
)
# Include folders
target_include_directories(${TARGET} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(${TARGET} PRIVATE "${LIBXML2_INCLUDE_DIR}")
target_include_directories(${TARGET} PRIVATE "${Poco_INCLUDE_DIRS}")
# Libraries
target_link_libraries(
${TARGET} PRIVATE
${LIBXML2_LIBRARY}
PocoFoundation
PocoUtil
PocoNet
PocoXML
PocoJSON
)
# Compilation depending on the platform
if(MSVC)
# Build the program as a window-only (no cmd)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_link_options(${TARGET} PRIVATE "/SUBSYSTEM:WINDOWS")
target_compile_options(${TARGET} PRIVATE /W3 /WX )
else()
target_compile_options(${TARGET} PRIVATE /W3 /WX /DEBUG )
endif()
else()
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wpedantic -Werror)
endif()
# Output folder
set_target_properties(${TARGET}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

View file

@ -0,0 +1,7 @@
#ifndef _HEADER_FETCHTEST_LIBXML
#define _HEADER_FETCHTEST_LIBXML
void info_libxml(void);
void create_xml(void);
#endif // _HEADER_FETCHTEST_LIBXML

9
fetchtest/include/poco.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef _HEADER_FETCHTEST_POCO
#define _HEADER_FETCHTEST_POCO
#include <string>
std::string get_date_time();
std::string format_poco_version();
#endif // _HEADER_FETCHTEST__POCO

35
fetchtest/src/libxml.cpp Normal file
View 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]\t version: " << 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();
}

37
fetchtest/src/main.cpp Normal file
View file

@ -0,0 +1,37 @@
#include <Poco/Environment.h>
#include <iostream>
#include "poco.h"
#include "libxml.h"
void info_poco(void);
int main(void)
{
try
{
std::cout << "Poco Test..." << std::endl;
info_poco();
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;
}
void info_poco(void)
{
std::cout << "\n";
std::cout << "[TIME]:\t" << get_date_time() << "\n";
std::cout << "[ OS]:\t" << Poco::Environment::osDisplayName() << " v" << Poco::Environment::osVersion() << "\n";
std::cout << "[ARCH]:\t" << Poco::Environment::osArchitecture() << "\n";
std::cout << "[POCO]:\tPoco C++ Library v" << format_poco_version() << "\n";
std::cout << "\n"
<< std::flush;
}

21
fetchtest/src/poco.cpp Normal file
View file

@ -0,0 +1,21 @@
#include "poco.h"
#include <Poco/LocalDateTime.h>
#include <Poco/DateTimeFormatter.h>
#include <Poco/Environment.h>
#include <Poco/Format.h>
#include <cstdint>
std::string get_date_time()
{
Poco::LocalDateTime dateTime;
return Poco::DateTimeFormatter::format(
dateTime,
"%W %d %B %Y at %H:%M:%S");
}
std::string format_poco_version()
{
uint32_t full_version = Poco::Environment::libraryVersion();
return Poco::format("%u.%u.%u", (full_version >> 24), ((full_version >> 16) & 0xff), ((full_version >> 8) & 0xff));
}