From 380211624f1c6eaf94f86436999786fe2d4ec7ee Mon Sep 17 00:00:00 2001 From: Chris Phlipot Date: Wed, 6 May 2026 14:48:09 -0700 Subject: [PATCH] Force C11/C++17 compile (Fixes GCC 16 build) Currently the project requests the C11 and C++17 feature sets using target_compile_features, however this only gaurentees us a minimum C++ version of C++17, and allows compile to proceed with C++20 (the GCC 16 default) if it is already set. Building Stable-diffusion.cpp with C++20 results in build failures as std::u8string can no longer be assigned to std::string due to C++20 standards changes. Explictly set the required language standard to C++17 in order to ensure we pass/fail the build consistently across compiler toolchains even if compilers by default try to expose a superset of C++17 features. Tested build succeeds on Fedora 44 with GCC 16. --- CMakeLists.txt | 2 +- examples/cli/CMakeLists.txt | 2 +- examples/server/CMakeLists.txt | 2 +- thirdparty/CMakeLists.txt | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48ce456ea..190f6831a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,7 +253,7 @@ add_subdirectory(thirdparty) target_link_libraries(${SD_LIB} PUBLIC ggml zip) target_include_directories(${SD_LIB} PUBLIC . src include) target_include_directories(${SD_LIB} PUBLIC . thirdparty) -target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17) +set_target_properties(${SD_LIB} PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED ON CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) if (SD_BUILD_EXAMPLES) diff --git a/examples/cli/CMakeLists.txt b/examples/cli/CMakeLists.txt index db1f4ca37..655ab8331 100644 --- a/examples/cli/CMakeLists.txt +++ b/examples/cli/CMakeLists.txt @@ -17,4 +17,4 @@ if(SD_WEBM) target_compile_definitions(${TARGET} PRIVATE SD_USE_WEBM) target_link_libraries(${TARGET} PRIVATE webm) endif() -target_compile_features(${TARGET} PUBLIC c_std_11 cxx_std_17) +set_target_properties(${TARGET} PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED ON CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) diff --git a/examples/server/CMakeLists.txt b/examples/server/CMakeLists.txt index b70b525e5..0a781f408 100644 --- a/examples/server/CMakeLists.txt +++ b/examples/server/CMakeLists.txt @@ -101,4 +101,4 @@ if(WIN32 AND NOT MSVC) target_link_libraries(${TARGET} PRIVATE ws2_32) endif() -target_compile_features(${TARGET} PUBLIC c_std_11 cxx_std_17) +set_target_properties(${TARGET} PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED ON CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 4dfdf0d29..23fe1e28c 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -37,9 +37,9 @@ if(SD_WEBM AND NOT SD_USE_SYSTEM_WEBM) # C++11. Restore the parent flags so the main project keeps its own C++17 # requirements, then pin the libwebm targets to C++17 explicitly. set(CMAKE_CXX_FLAGS "${SD_LIBWEBM_PARENT_CXX_FLAGS}" CACHE STRING "" FORCE) - target_compile_features(mkvmuxer PRIVATE cxx_std_17) - target_compile_features(mkvparser PRIVATE cxx_std_17) - target_compile_features(webm PRIVATE cxx_std_17) + set_target_properties(mkvmuxer PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) + set_target_properties(mkvparser PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) + set_target_properties(webm PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) target_include_directories(webm INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libwebm) endif()