Target requires "CXX26" but CMake does not know the flags to enable it

I want to test c++26 with import std; too

if(FMT_MODULE)
    add_library(fmt-module)
    add_library(fmt::fmt-module ALIAS fmt-module)
    target_compile_options(
        fmt-module
        PUBLIC $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/utf-8>
    )

    if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND ${CMAKE_CXX_STANDARD} EQUAL 26)
        target_compile_features(fmt-module PUBLIC cxx_std_23)
        target_compile_options(fmt-module PUBLIC /std:c++latest)
    else()
        # XXX target_compile_features(fmt-module PUBLIC cxx_std_26)
        target_compile_features(fmt-module PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
    endif()

# ...

But windows preset fails to configure:

Preset CMake variables:

  CMAKE_BUILD_TYPE="Release"
  CMAKE_CXX_COMPILER="cl"
  CMAKE_CXX_EXTENSIONS:BOOL="FALSE"
  CMAKE_CXX_FLAGS_RELEASE="/W3 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /Zc:enumTypes /Zc:lambda /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew /EHsc"
  CMAKE_CXX_SCAN_FOR_MODULES:BOOL="TRUE"
  CMAKE_CXX_STANDARD="26"
  CMAKE_CXX_STANDARD_REQUIRED:BOOL="TRUE"
  CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE"
  CMAKE_INSTALL_PREFIX:PATH="D:/a/fmt-module/fmt-module/stagedir"
  CMAKE_MESSAGE_LOG_LEVEL="VERBOSE"
  CMAKE_PREFIX_PATH:STRING="D:/a/fmt-module/fmt-module/stagedir"
  CMAKE_VERIFY_INTERFACE_HEADER_SETS:BOOL="TRUE"
  FMT_DEVELOPER_MODE:BOOL="TRUE"

-- use ccache
-- The CXX compiler identification is MSVC 19.51.36248.0
-- Detecting CXX compiler ABI info
CMake Error in D:/a/fmt-module/fmt-module/build/CMakeFiles/CMakeScratch/TryCompile-hqbuux/CMakeLists.txt:
  Target "cmTC_91db6" requires the language dialect "CXX26" .  But the
  current compiler "MSVC" does not support this, or CMake does not know the
  flags to enable it.


CMake Error at C:/hostedtoolcache/windows/Python/3.14.6/x64/Lib/site-packages/cmake/data/share/cmake-4.4/Modules/CMakeDetermineCompilerABI.cmake:123 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  C:/hostedtoolcache/windows/Python/3.14.6/x64/Lib/site-packages/cmake/data/share/cmake-4.4/Modules/CMakeTestCXXCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
  CMakeLists.txt:13 (project)


-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.

I found a workaround:

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

@ben.boeckel @vito.gamberini why is this not supported?

Because MSVC has not been recorded as supporting C++26 in CMake’s internal bookkeeping.

So when you ask for C++26, CMake reports that it does not know how to enable that standard for MSVC.

So this seem to me the pragmaticle default project settings:

# Neither of these two are technically needed, but they make the expectation clear
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC AND CMAKE_CXX_STANDARD EQUAL 26)
    set(CMAKE_CXX_STANDARD_REQUIRED OFF)
else()
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

If you actually require C++26, you should set the appropriate feature on the target with that requirement.

If you don’t require C++26, you should not set the feature on the target. Or set the feature to the standard actually required by the target.

In general, you shouldn’t be messing with the global CMAKE_* flags at all. If the codebase supports optional features based on the C++ standard available, the downstream user building the code sets these flags to communicate a global minimum. Overwriting their decisions is usually wrong.

In CI, it is appropriate to set these cache variables via -D flags (or whatever mechanism) to enforce various language levels to verify the code builds under those conditions.

MSVC doesn’t have stable support for C++26, so it should not be in a CI matrix which includes C++26 generally.