Moving from CMake 3.21.2 to 4.0.1 and now CXX_STANDARD only seems to partially work?

Hello Y’all,

I’m moving my MSVC based project from my old PC to a new one. In the process I’m upgrading some build software alongside it, such as CMake which on my old machine is 3.21.2 and on the new one 4.0.1.

I used to set the C++ standard on 3 different projects in my solution, but now, only the very last target appears to actually take/listen to CMake’s CXX_STANDARD. I’ve had to update boost and change some other parts, but nothing I’d imagine should affect the standard being set.

No matter what I’ve tried, the C++ standard remains C++17 on the first 2 targets, but the last one to be set will happily switch to C++20 or even C++23.

Anyone else run into this issue?

Cheers,
gazoo

See if you can produce a minimal reproducer and post a link to godbolt or a github gist or somethign.

Turns out the culprit was a library I’m linking with had set INTERFACE_COMPILE_OPTIONS to /std:c++17, which ultimately was inherited overriding/preventing the CXX_STANDARD property from having any influence on the target I wanted it to impact.

I think the older CMake is more lax here either not setting that flag on the INTERFACE_COMPILE_OPTIONS or perhaps just letting CXX_STANDARD interfere/override the setting.

Cheers,
Gazoo