From e354e1ab2b7d43b9b550ad92e02afb5d8c484ae3 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 31 Oct 2024 14:25:12 +0100 Subject: [PATCH] add support for C++20 module (and C++23 std module) --- src/pugixml.cpp | 4 +++ src/pugixml.cppm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ src/pugixml.hpp | 24 ++++++++++------ 3 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 src/pugixml.cppm diff --git a/src/pugixml.cpp b/src/pugixml.cpp index b84658d2..8b6c0fb2 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -16,6 +16,7 @@ #include "pugixml.hpp" +#ifndef PUGIXML_EXPORT_MODULE #include #include #include @@ -44,6 +45,7 @@ #if defined(__linux__) || defined(__APPLE__) #include #endif +#endif #ifdef _MSC_VER # pragma warning(push) @@ -196,8 +198,10 @@ namespace pugi typedef unsigned __int32 uint32_t; } #else +#ifndef PUGIXML_EXPORT_MODULE # include #endif +#endif // Memory allocation PUGI_IMPL_NS_BEGIN diff --git a/src/pugixml.cppm b/src/pugixml.cppm new file mode 100644 index 00000000..c314f2b2 --- /dev/null +++ b/src/pugixml.cppm @@ -0,0 +1,71 @@ +/** + * pugixml parser - version 1.14 + * -------------------------------------------------------- + * Copyright (C) 2006-2024, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) + * Report bugs and download new versions at https://pugixml.org/ + * + * This library is distributed under the MIT License. See notice at the end + * of this file. + * + * This work is based on the pugxml parser, which is: + * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) + */ + +module; + +#define PUGIXML_EXPORT_MODULE + +#include + +#ifndef PUGIXML_USE_STD_MODULE +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef PUGIXML_WCHAR_MODE +# include +#endif + +#ifndef PUGIXML_NO_XPATH +# include +# include +#endif + +#if defined(__linux__) || defined(__APPLE__) +# include +#endif + +export module pugixml; + +#ifdef PUGIXML_USE_STD_MODULE +import std.compat; +#endif + +#define PUGIXML_MODULE_EXPORT export +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" +#endif +#include +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + +module :private; + +#define PUGIXML_SOURCE "pugixml.cpp" +#include PUGIXML_SOURCE diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 1712623f..032c6d56 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -23,6 +23,7 @@ #ifndef HEADER_PUGIXML_HPP #define HEADER_PUGIXML_HPP +#ifndef PUGIXML_EXPORT_MODULE // Include stddef.h for size_t and ptrdiff_t #include @@ -37,6 +38,7 @@ # include # include #endif +#endif // Check if std::string_view is both requested and available #if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL) @@ -48,8 +50,10 @@ #endif // Include string_view if appropriate -#ifdef PUGIXML_HAS_STRING_VIEW -# include +#ifndef PUGIXML_MODULE_EXPORT +# ifdef PUGIXML_HAS_STRING_VIEW +# include +# endif #endif // Macro for deprecated features @@ -150,11 +154,11 @@ // If C++ is 2017 or higher, add 'inline' qualifiers for constants // required for C++20 module #ifndef PUGIXML_CONSTANT -# if __cplusplus >= 201703 -# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR -# else -# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR -# endif +# if __cplusplus >= 201703 +# define PUGIXML_CONSTANT inline PUGIXML_CONSTEXPR +# else +# define PUGIXML_CONSTANT PUGIXML_CONSTEXPR +# endif #endif // Character interface macros @@ -166,6 +170,10 @@ # define PUGIXML_CHAR char #endif +#ifndef PUGIXML_MODULE_EXPORT +# define PUGIXML_MODULE_EXPORT +#endif + namespace pugi { // Character type used for all internal storage and operations; depends on PUGIXML_WCHAR_MODE @@ -183,7 +191,7 @@ namespace pugi } // The PugiXML namespace -namespace pugi +PUGIXML_MODULE_EXPORT namespace pugi { // Tree node types enum xml_node_type