diff --git a/CMakeLists.txt b/CMakeLists.txt index f2253ec..f120b6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,12 @@ project(docpp VERSION 0.0.1 LANGUAGES CXX ) +option(GENERATE_PKGBUILD "Generate PKGBUILD" OFF) +option(GENERATE_EBUILD "Generate ebuild" OFF) +option(BUILD_TARBALL "Build tarball" OFF) + +add_compile_definitions(DOCPP_VERSION="${PROJECT_VERSION}") + include(GNUInstallDirs) include(CMakePackageConfigHelpers) diff --git a/include/docpp.hpp b/include/docpp.hpp index 71a513d..be20f9c 100644 --- a/include/docpp.hpp +++ b/include/docpp.hpp @@ -13,6 +13,7 @@ #include #include #include +#include /** * @brief A namespace to represent HTML elements and documents @@ -1684,4 +1685,10 @@ namespace docpp { bool operator!=(const Stylesheet& stylesheet) const; }; } // namespace CSS + + /** + * @brief Get the version of the library + * @return std::tuple The version of the library + */ + std::tuple version(); } // namespace docpp diff --git a/src/docpp.cpp b/src/docpp.cpp index 1ed5c9c..0f980c8 100644 --- a/src/docpp.cpp +++ b/src/docpp.cpp @@ -1302,3 +1302,25 @@ std::string docpp::CSS::Stylesheet::get(const Formatting formatting, const int t return std::move(ret); } + +std::tuple docpp::version() { +#ifdef DOCPP_VERSION + std::string version{DOCPP_VERSION}; + + if (version.find('.') != std::string::npos) { + std::string major = version.substr(0, version.find('.')); + version = version.substr(version.find('.') + 1); + + if (version.find('.') != std::string::npos) { + std::string minor = version.substr(0, version.find('.')); + version = version.substr(version.find('.') + 1); + + if (version.find('.') != std::string::npos) { + std::string patch = version.substr(0, version.find('.')); + return {std::stoi(major), std::stoi(minor), std::stoi(patch)}; + } + } + } +#endif + return {}; +} diff --git a/tests/test.cpp b/tests/test.cpp index 5cf34bd..2223cd6 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -2015,6 +2015,14 @@ inline namespace General { REQUIRE(docpp::CSS::Element::npos == -1); REQUIRE(docpp::CSS::Stylesheet::npos == -1); } + + void test_version() { + std::tuple version = docpp::version(); + + REQUIRE(std::get<0>(version) >= 0); + REQUIRE(std::get<1>(version) >= 0); + REQUIRE(std::get<2>(version) >= 0); + } } /** @@ -2023,6 +2031,7 @@ inline namespace General { SCENARIO("Test general", "[GENERAL]") { General::test_exceptions(); General::test_npos_values(); + General::test_version(); } /**