Skip to content

Commit

Permalink
Auto-detect std::string_view support by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zeux committed Oct 30, 2024
1 parent 4d0043f commit ca4f7cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,16 +48,14 @@ 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
$<$<BOOL:${PUGIXML_WCHAR_MODE}>:PUGIXML_WCHAR_MODE>
$<$<BOOL:${PUGIXML_COMPACT}>:PUGIXML_COMPACT>
$<$<BOOL:${PUGIXML_NO_XPATH}>:PUGIXML_NO_XPATH>
$<$<BOOL:${PUGIXML_NO_STL}>:PUGIXML_NO_STL>
$<$<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
Expand All @@ -66,10 +64,6 @@ if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>: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()
Expand Down
8 changes: 3 additions & 5 deletions src/pugiconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/pugixml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
# include <string>
#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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ca4f7cf

Please sign in to comment.