From 89ace4a28512aaafa9ddc73675344c4fd0264d71 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 31 Dec 2025 18:57:10 +0000 Subject: [PATCH 1/2] Added control of over the C++ standard used. --- CMakeLists.txt | 3 +++ include/vsg/io/convert_utf.h | 31 +++++++++++++++++++++++++++++++ src/vsg/CMakeLists.txt | 14 +++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c3d5522b2..85cb50f3ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,9 @@ if (VSG_SUPPORTS_Windowing) endif() endif() +set(VSG_CXX_TARGET 17 CACHE STRING "Set target C++ standard version, valid values are 17, 20 & 23") + + option(VSG_USE_dynamic_cast "Use dynamic_cast in vsg::Object::cast(), default is OFF and uses VSG native casting which provides 2-3x faster than using dynamic_cast<>." OFF) # this line needs to be after the call to setup_build_vars() diff --git a/include/vsg/io/convert_utf.h b/include/vsg/io/convert_utf.h index 5a58a9f2c6..53ff429340 100644 --- a/include/vsg/io/convert_utf.h +++ b/include/vsg/io/convert_utf.h @@ -27,6 +27,37 @@ namespace vsg inline void convert_utf(const std::string& src, std::string& dst) { dst = src; } inline void convert_utf(const std::wstring& src, std::wstring& dst) { dst = src; } + + #if defined(__cpp_char8_t) + inline void convert_utf(const std::u8string& src, std::u8string& dst) { dst = src; } + 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()); } + inline void convert_utf(const std::u8string& src, std::wstring& dst) { std::string temp_src(src.begin(), src.end()); convert_utf(temp_src, dst); } + + inline void convert_utf(const char8_t c, std::u8string& dst) + { + dst.clear(); + dst.push_back(c); + } + inline void convert_utf(const char8_t c, std::string& dst) + { + dst.clear(); + dst.push_back(c); + } + inline void convert_utf(const char8_t c, std::wstring& dst) + { + dst.clear(); + dst.push_back(static_cast(c)); + } + + template + T convert_utf(const std::u8string& src) + { + T dst; + convert_utf(src, dst); + return dst; + } + #endif + inline void convert_utf(const char c, std::string& dst) { dst.clear(); diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 753b6156a7..c5ba37910d 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -411,7 +411,19 @@ ASSIGN_SOURCE_GROUPS("Header Files" "${VSG_SOURCE_DIR}/include/vsg" ${HEADERS}) set_property(TARGET vsg PROPERTY VERSION ${VSG_VERSION_MAJOR}.${VSG_VERSION_MINOR}.${VSG_VERSION_PATCH}) set_property(TARGET vsg PROPERTY SOVERSION ${VSG_SOVERSION}) set_property(TARGET vsg PROPERTY POSITION_INDEPENDENT_CODE ON) -target_compile_features(vsg PUBLIC cxx_std_17) + +if (VSG_CXX_TARGET EQUAL 23) + target_compile_features(vsg PUBLIC cxx_std_23) +elseif (VSG_CXX_TARGET EQUAL 20) + target_compile_features(vsg PUBLIC cxx_std_20) +elseif (VSG_CXX_TARGET EQUAL 17) + target_compile_features(vsg PUBLIC cxx_std_17) +else() + message("Warning: invalid VSG_CXX_TARGET setting of " ${VSG_CXX_TARGET} " valid settings are 17, 20 or 23") + target_compile_features(vsg PUBLIC cxx_std_17) +endif() + + if(WIN32) set_property(TARGET vsg PROPERTY RUNTIME_OUTPUT_NAME vsg-${VSG_SOVERSION}) endif() From 96c388ae72eacd6b68a6fa55435d6857aa449213 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 1 Jan 2026 16:41:02 +0000 Subject: [PATCH 2/2] Standardized on using CMAKE_CXX_STANDARD to control the cxx_std_ used. --- CMakeLists.txt | 3 --- src/vsg/CMakeLists.txt | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85cb50f3ca..4c3d5522b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,9 +90,6 @@ if (VSG_SUPPORTS_Windowing) endif() endif() -set(VSG_CXX_TARGET 17 CACHE STRING "Set target C++ standard version, valid values are 17, 20 & 23") - - option(VSG_USE_dynamic_cast "Use dynamic_cast in vsg::Object::cast(), default is OFF and uses VSG native casting which provides 2-3x faster than using dynamic_cast<>." OFF) # this line needs to be after the call to setup_build_vars() diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index c5ba37910d..8b515214bb 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -412,15 +412,20 @@ set_property(TARGET vsg PROPERTY VERSION ${VSG_VERSION_MAJOR}.${VSG_VERSION_MINO set_property(TARGET vsg PROPERTY SOVERSION ${VSG_SOVERSION}) set_property(TARGET vsg PROPERTY POSITION_INDEPENDENT_CODE ON) -if (VSG_CXX_TARGET EQUAL 23) - target_compile_features(vsg PUBLIC cxx_std_23) -elseif (VSG_CXX_TARGET EQUAL 20) - target_compile_features(vsg PUBLIC cxx_std_20) -elseif (VSG_CXX_TARGET EQUAL 17) +# set up the C++ Standard used +if (NOT CMAKE_CXX_STANDARD) + # no CMAKE_CXX_STANDARD explicitly defined so default to 17 target_compile_features(vsg PUBLIC cxx_std_17) -else() - message("Warning: invalid VSG_CXX_TARGET setting of " ${VSG_CXX_TARGET} " valid settings are 17, 20 or 23") +elseif (${CMAKE_CXX_STANDARD} EQUAL 17) target_compile_features(vsg PUBLIC cxx_std_17) +elseif (${CMAKE_CXX_STANDARD} EQUAL 20) + target_compile_features(vsg PUBLIC cxx_std_20) # CMake minimum version 3.12 +elseif (${CMAKE_CXX_STANDARD} EQUAL 23) + target_compile_features(vsg PUBLIC cxx_std_23) # CMake minimum version 3.20 +elseif (${CMAKE_CXX_STANDARD} EQUAL 26) + target_compile_features(vsg PUBLIC cxx_std_26) # CMake minimum version 3.30 +else() + message(FATAL_ERROR "Invalid CMAKE_CXX_STANDARD value of " ${CMAKE_CXX_STANDARD} ", supported values are 17, 20 or 23.") endif()