cmakevcpkgxerces-c

Why has xerces changed XMLCh to char16_t, can I change it back to wchar_t?


We've been working with an old, pre-built version of Xerces 3.1.1 which has:

3.1.1: Xerces_autoconf_config.hpp

#ifdef _NATIVE_WCHAR_T_DEFINED
#  define XERCES_XMLCH_T      wchar_t
#else
#  define XERCES_XMLCH_T      unsigned short
#endif
...
typedef XERCES_XMLCH_T              XMLCh;

Moving to use vcpkg it has installed 3.2.3 and we have compile errors because instead of wchar_t it is using:

3.2.3: Xerces_autoconf_config.hpp

#define XERCES_XMLCH_T char16_t
...
typedef XERCES_XMLCH_T              XMLCh;

We have lots of code making calls like src.setEncoding(L"UTF-16"); which obviously leads to errors such as:

void xercesc_3_2::InputSource::setEncoding(const XMLCh *const )': cannot convert argument 1 from 'const wchar_t [7]' to 'const XMLCh *const '

I'm not sure if Xerces has changed or if this is a result of vcpkg's default build settings. Is it possible to get it back to wchar_t (other than hacking sources), if so how? I am a total cmake noob unfortunately.


Solution

  • OK, according to the xerces-c docs:

    XMLCh type (UTF-16 character type):

    Option Description
    -Dxmlch-type=char16_t use char16_t (requires a C++11 compiler)
    -Dxmlch-type=uint16_t use uint16_t from or <stdint.h>, or another unsigned 16-bit type such as unsigned short if the standard types are unavailable
    -Dxmlch-type=wchar_t use wchar_t (Windows only)

    In vcpkg, this is partially exposed through features:

    vcpkg install xerces-c[xmlch-wchar] XMLCh type uses wchar_t