From ca4f7cfecc1f20d40285a8281bf0c42c2b9d11b3 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 30 Oct 2024 10:31:49 -0700 Subject: [PATCH] Auto-detect std::string_view support by default Instead of opting in std::string_view support via PUGIXML_STRING_VIEW define, always enable it when C++17 is supported; this still requires enabling C++17 support in the compiler, which this change doesn't attempt to do yet. --- .github/workflows/build.yml | 4 ++-- CMakeLists.txt | 10 ++-------- src/pugiconfig.hpp | 8 +++----- src/pugixml.hpp | 6 +++--- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b460b7..8d0fddb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: matrix: os: [ubuntu, macos] compiler: [g++, clang++] - defines: [standard, PUGIXML_WCHAR_MODE, PUGIXML_COMPACT, PUGIXML_NO_EXCEPTIONS, PUGIXML_STRING_VIEW] + defines: [standard, PUGIXML_WCHAR_MODE, PUGIXML_COMPACT, PUGIXML_NO_EXCEPTIONS] exclude: - os: macos compiler: g++ @@ -39,7 +39,7 @@ jobs: strategy: matrix: arch: [Win32, x64] - defines: [standard, PUGIXML_WCHAR_MODE, PUGIXML_COMPACT, PUGIXML_NO_EXCEPTIONS, PUGIXML_STRING_VIEW] + defines: [standard, PUGIXML_WCHAR_MODE, PUGIXML_COMPACT, PUGIXML_NO_EXCEPTIONS] steps: - uses: actions/checkout@v1 - name: cmake configure diff --git a/CMakeLists.txt b/CMakeLists.txt index ede427c..cf43abf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options") separate_arguments(PUGIXML_BUILD_DEFINES) # Technically not needed for this file. This is builtin CMAKE global variable. -option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF) +option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF) # Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS @@ -48,8 +48,7 @@ option(PUGIXML_INSTALL "Enable installation rules" ON) option(PUGIXML_NO_XPATH "Disable XPath" OFF) option(PUGIXML_NO_STL "Disable STL" OFF) option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" OFF) -option(PUGIXML_STRING_VIEW "Enable std::string_view overloads" OFF) # requires C++17 and for PUGIXML_NO_STL to be OFF -mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS PUGIXML_STRING_VIEW) +mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS) set(PUGIXML_PUBLIC_DEFINITIONS $<$:PUGIXML_WCHAR_MODE> @@ -57,7 +56,6 @@ set(PUGIXML_PUBLIC_DEFINITIONS $<$:PUGIXML_NO_XPATH> $<$:PUGIXML_NO_STL> $<$:PUGIXML_NO_EXCEPTIONS> - $<$:PUGIXML_STRING_VIEW> ) # This is used to backport a CMake 3.15 feature, but is also forwards compatible @@ -66,10 +64,6 @@ if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) MultiThreaded$<$:Debug>$<$>:DLL>) endif() -if (PUGIXML_STRING_VIEW AND (NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 17)) - message(WARNING "PUGIXML_STRING_VIEW requires CMAKE_CXX_STANDARD to be set to 17 or later") -endif() - if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp index cc138ba..af32925 100644 --- a/src/pugiconfig.hpp +++ b/src/pugiconfig.hpp @@ -46,13 +46,11 @@ // Uncomment this to switch to header-only version // #define PUGIXML_HEADER_ONLY -// Uncomment this to enable long long support +// Uncomment this to enable long long support (usually enabled automatically) // #define PUGIXML_HAS_LONG_LONG -// Uncomment this to enable support for std::string_view (requires c++17 and for PUGIXML_NO_STL to not be set) -// Note: In a future version of pugixml this macro will become obsolete. -// Support will then be enabled automatically if the used C++ standard supports it. -// #define PUGIXML_STRING_VIEW +// Uncomment this to enable support for std::string_view (usually enabled automatically) +// #define PUGIXML_HAS_STRING_VIEW #endif diff --git a/src/pugixml.hpp b/src/pugixml.hpp index f2d985e..b9155d8 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -38,8 +38,8 @@ # include #endif -// Check if std::string_view is both requested and available -#if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL) +// Check if std::string_view is available +#if !defined(PUGIXML_HAS_STRING_VIEW) && !defined(PUGIXML_NO_STL) # if __cplusplus >= 201703L # define PUGIXML_HAS_STRING_VIEW # elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L @@ -231,7 +231,7 @@ namespace pugi // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments. // This flag is off by default. const unsigned int parse_embed_pcdata = 0x2000; - + // This flag determines whether determines whether the the two pcdata should be merged or not, if no intermediatory data are parsed in the document. // This flag is off by default. const unsigned int parse_merge_pcdata = 0x4000;