Skip to content

Commit 89ace4a

Browse files
committed
Added control of over the C++ standard used.
1 parent 05bb15b commit 89ace4a

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ if (VSG_SUPPORTS_Windowing)
9090
endif()
9191
endif()
9292

93+
set(VSG_CXX_TARGET 17 CACHE STRING "Set target C++ standard version, valid values are 17, 20 & 23")
94+
95+
9396
option(VSG_USE_dynamic_cast "Use dynamic_cast in vsg::Object::cast<T>(), default is OFF and uses VSG native casting which provides 2-3x faster than using dynamic_cast<>." OFF)
9497

9598
# this line needs to be after the call to setup_build_vars()

include/vsg/io/convert_utf.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ namespace vsg
2727

2828
inline void convert_utf(const std::string& src, std::string& dst) { dst = src; }
2929
inline void convert_utf(const std::wstring& src, std::wstring& dst) { dst = src; }
30+
31+
#if defined(__cpp_char8_t)
32+
inline void convert_utf(const std::u8string& src, std::u8string& dst) { dst = src; }
33+
inline void convert_utf(const std::wstring& src, std::u8string& dst) { std::string temp_dst; convert_utf(src, temp_dst); dst.assign(temp_dst.begin(), temp_dst.end()); }
34+
inline void convert_utf(const std::u8string& src, std::wstring& dst) { std::string temp_src(src.begin(), src.end()); convert_utf(temp_src, dst); }
35+
36+
inline void convert_utf(const char8_t c, std::u8string& dst)
37+
{
38+
dst.clear();
39+
dst.push_back(c);
40+
}
41+
inline void convert_utf(const char8_t c, std::string& dst)
42+
{
43+
dst.clear();
44+
dst.push_back(c);
45+
}
46+
inline void convert_utf(const char8_t c, std::wstring& dst)
47+
{
48+
dst.clear();
49+
dst.push_back(static_cast<wchar_t>(c));
50+
}
51+
52+
template<typename T>
53+
T convert_utf(const std::u8string& src)
54+
{
55+
T dst;
56+
convert_utf(src, dst);
57+
return dst;
58+
}
59+
#endif
60+
3061
inline void convert_utf(const char c, std::string& dst)
3162
{
3263
dst.clear();

src/vsg/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,19 @@ ASSIGN_SOURCE_GROUPS("Header Files" "${VSG_SOURCE_DIR}/include/vsg" ${HEADERS})
411411
set_property(TARGET vsg PROPERTY VERSION ${VSG_VERSION_MAJOR}.${VSG_VERSION_MINOR}.${VSG_VERSION_PATCH})
412412
set_property(TARGET vsg PROPERTY SOVERSION ${VSG_SOVERSION})
413413
set_property(TARGET vsg PROPERTY POSITION_INDEPENDENT_CODE ON)
414-
target_compile_features(vsg PUBLIC cxx_std_17)
414+
415+
if (VSG_CXX_TARGET EQUAL 23)
416+
target_compile_features(vsg PUBLIC cxx_std_23)
417+
elseif (VSG_CXX_TARGET EQUAL 20)
418+
target_compile_features(vsg PUBLIC cxx_std_20)
419+
elseif (VSG_CXX_TARGET EQUAL 17)
420+
target_compile_features(vsg PUBLIC cxx_std_17)
421+
else()
422+
message("Warning: invalid VSG_CXX_TARGET setting of " ${VSG_CXX_TARGET} " valid settings are 17, 20 or 23")
423+
target_compile_features(vsg PUBLIC cxx_std_17)
424+
endif()
425+
426+
415427
if(WIN32)
416428
set_property(TARGET vsg PROPERTY RUNTIME_OUTPUT_NAME vsg-${VSG_SOVERSION})
417429
endif()

0 commit comments

Comments
 (0)