This library is header-only, so the most basic way to use it is to
- Download the sources
- Set your include path to
lib/inc
Note that you need your compiler to use at least C++20 mode in order for the build to succeed.
With modern CMake, the easiest way to use this library is:
include(FetchContent)
FetchContent_Declare(sys_string
GIT_REPOSITORY https://github.com/gershnik/sys_string.git
GIT_TAG <desired tag like v3.2>
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(sys_string)
...
target_link_libraries(mytarget
PRIVATE
sys_string::sys_string
)Alternatively, you can clone this repository somewhere and do this:
add_subdirectory(<download_path>/lib, sys_string)
...
target_link_libraries(mytarget
PRIVATE
sys_string::sys_string
)Note that you need your compiler to default to at least C++20 or set CMAKE_CXX_STANDARD to at least 20 in order for the build to succeed.
You can also build and install this library on your system using CMake.
- Download or clone this repository into SOME_PATH
- On the command line:
cd SOME_PATH
cmake -S . -B build
#install to /usr/local
sudo cmake --install build
#or for a different prefix
#cmake --install build --prefix /usrOnce the library has been installed, it can be used in the following ways:
Set the include directory to <prefix>/include, where <prefix> is the install prefix from above.
find_package(sys_string)
target_link_libraries(mytarget
PRIVATE
sys_string::sys_string
)Add the output of pkg-config --cflags sys_string to your compiler flags.
Note that the default installation prefix /usr/local might not be in the list of places your
pkg-config looks into. If so, you might need to do:
export PKG_CONFIG_PATH=/usr/local/share/pkgconfigbefore running pkg-config.
To use this library with Clang 13-15 (Xcode 13-14), you will need some workarounds. By default,
libc++ that ships with these compilers disables the standard C++ ranges library that
sys_string depends on.
You can work around this in two ways:
- Include
sys_stringheaders before any standard library ones - Enable ranges yourself. You can use something like this before including any standard library headers:
#include <version>
#if defined(_LIBCPP_VERSION)
#if _LIBCPP_VERSION >= 13000 && _LIBCPP_VERSION < 160000
#undef _LIBCPP_HAS_NO_INCOMPLETE_RANGES
#endif
#endifWhichever method you use, you can set the following macros (either on the command line or before including any library headers) to control the library behavior:
SYS_STRING_NO_S_MACRO- set it to 1 to disable the shortS()macro. See Usage for details.SYS_STRING_USE_GENERIC- set it to 1 to useconst char *as the defaultsys_stringstorage regardless of platform.SYS_STRING_USE_ICU- set it to 1 to use ICU instead of internal code for case conversion, normalization and grapheme iteration. ICU headers must be present on the include path and available via#include <unicode/...>. You will also need to link with ICU libraries.SYS_STRING_WIN_BSTR- set it to 1 to useBSTRas the defaultsys_stringstorage on Windows. It has no effect on other platforms.SYS_STRING_WIN_HSTRING- set it to 1 to useHSTRINGas the defaultsys_stringstorage on Windows. It has no effect on other platforms.SYS_STRING_ENABLE_PYTHON- set it to 1 to enable Python support. This requires the header<Python.h>to be available on the include path. If enabled, thesys_string_pystrand related classes become available. This doesn't change the defaultsys_string.SYS_STRING_USE_PYTHON- set it to 1 to make Python strings the defaultsys_stringstorage. This automatically enablesSYS_STRING_ENABLE_PYTHONand has the same requirements.