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

**URL:** https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762
**Category:** Development
**Tags:** os:windows, gen:ninja
**Created:** [July 27, 2026, 9:54am UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762 "2026-07-27T09:54:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [July 27, 2026, 9:54am UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/1 "2026-07-27T09:54:29Z")

</div>

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

```cmake
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:

```bash
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.

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [July 27, 2026, 10:21am UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/2 "2026-07-27T10:21:33Z")

</div>

> [@ClausKlein](#):
>
> `CMAKE_CXX_STANDARD="26"`

I found a workaround:

> <https://github.com/ClausKlein/fmt-module/pull/5/commits/2f9aaf23ab09a14b1758ffcd92e8b8853f3c13a4>
>
> Add a workaround for CMake v4.4.0 configure error:
> MSVC 19.51.36248.0 with CMA…KE\_CXX\_STANDARD="26":
> Target requires "CXX26" but CMake does not know the flags to enable it

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 13, 2026, 11:07am UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/3 "2026-08-13T11:07:06Z")

</div>

```
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?

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 13, 2026, 11:24am UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/4 "2026-08-13T11:24:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 13, 2026, 1:51pm UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/5 "2026-08-13T13:51:08Z")

</div>

So this seem to me the pragmaticle default project settings:

```cmake
# 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()

```

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [August 13, 2026, 2:02pm UTC](https://discourse.cmake.org/t/target-requires-cxx26-but-cmake-does-not-know-the-flags-to-enable-it/15762/6 "2026-08-13T14:02:44Z")

</div>

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.
