0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-25 20:14:10 +08:00

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.
This commit is contained in:
Arseny Kapoulkine 2024-10-30 10:31:49 -07:00
parent 4d0043fb6c
commit ca4f7cfecc
4 changed files with 10 additions and 18 deletions

View File

@ -12,7 +12,7 @@ jobs:
matrix: matrix:
os: [ubuntu, macos] os: [ubuntu, macos]
compiler: [g++, clang++] 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: exclude:
- os: macos - os: macos
compiler: g++ compiler: g++
@ -39,7 +39,7 @@ jobs:
strategy: strategy:
matrix: matrix:
arch: [Win32, x64] 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: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: cmake configure - name: cmake configure

View File

@ -32,7 +32,7 @@ set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options")
separate_arguments(PUGIXML_BUILD_DEFINES) separate_arguments(PUGIXML_BUILD_DEFINES)
# Technically not needed for this file. This is builtin CMAKE global variable. # 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 # 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 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_XPATH "Disable XPath" OFF)
option(PUGIXML_NO_STL "Disable STL" OFF) option(PUGIXML_NO_STL "Disable STL" OFF)
option(PUGIXML_NO_EXCEPTIONS "Disable Exceptions" 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)
mark_as_advanced(PUGIXML_NO_XPATH PUGIXML_NO_STL PUGIXML_NO_EXCEPTIONS PUGIXML_STRING_VIEW)
set(PUGIXML_PUBLIC_DEFINITIONS set(PUGIXML_PUBLIC_DEFINITIONS
$<$<BOOL:${PUGIXML_WCHAR_MODE}>:PUGIXML_WCHAR_MODE> $<$<BOOL:${PUGIXML_WCHAR_MODE}>:PUGIXML_WCHAR_MODE>
@ -57,7 +56,6 @@ set(PUGIXML_PUBLIC_DEFINITIONS
$<$<BOOL:${PUGIXML_NO_XPATH}>:PUGIXML_NO_XPATH> $<$<BOOL:${PUGIXML_NO_XPATH}>:PUGIXML_NO_XPATH>
$<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL> $<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL>
$<$<BOOL:${PUGIXML_NO_EXCEPTIONS}>:PUGIXML_NO_EXCEPTIONS> $<$<BOOL:${PUGIXML_NO_EXCEPTIONS}>:PUGIXML_NO_EXCEPTIONS>
$<$<BOOL:${PUGIXML_STRING_VIEW}>:PUGIXML_STRING_VIEW>
) )
# This is used to backport a CMake 3.15 feature, but is also forwards compatible # 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$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>) MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>)
endif() 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) if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif() endif()

View File

@ -46,13 +46,11 @@
// Uncomment this to switch to header-only version // Uncomment this to switch to header-only version
// #define PUGIXML_HEADER_ONLY // #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 // #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) // Uncomment this to enable support for std::string_view (usually enabled automatically)
// Note: In a future version of pugixml this macro will become obsolete. // #define PUGIXML_HAS_STRING_VIEW
// Support will then be enabled automatically if the used C++ standard supports it.
// #define PUGIXML_STRING_VIEW
#endif #endif

View File

@ -38,8 +38,8 @@
# include <string> # include <string>
#endif #endif
// Check if std::string_view is both requested and available // Check if std::string_view is available
#if defined(PUGIXML_STRING_VIEW) && !defined(PUGIXML_NO_STL) #if !defined(PUGIXML_HAS_STRING_VIEW) && !defined(PUGIXML_NO_STL)
# if __cplusplus >= 201703L # if __cplusplus >= 201703L
# define PUGIXML_HAS_STRING_VIEW # define PUGIXML_HAS_STRING_VIEW
# elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L # 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. // the document; this flag is only recommended for parsing documents with many PCDATA nodes in memory-constrained environments.
// This flag is off by default. // This flag is off by default.
const unsigned int parse_embed_pcdata = 0x2000; 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 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. // This flag is off by default.
const unsigned int parse_merge_pcdata = 0x4000; const unsigned int parse_merge_pcdata = 0x4000;