# CMAKE\_CXX\_STANDARD: cmake 3.16 vs 3.24

**URL:** https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623
**Category:** Usage
**Created:** [October 6, 2022, 5:04pm UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623 "2022-10-06T17:04:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![malaterre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/malaterre/32/1971_2.png) [@malaterre](https://discourse.cmake.org/u/malaterre)
#### Post date: [October 6, 2022, 5:04pm UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/1 "2022-10-06T17:04:12Z")

</div>

I am observing a change in behavior in between cmake 3.16.3 and 3.24.2.

Basically the following is working as expected in cmake 3.16.3 :

```auto
cmake_minimum_required(VERSION 3.10)
project(p)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("${my_code}" MY_VAR)

```

However in cmake 3.24.1, the `try_compile` fails because -std=c++98 is being added after my -std=c++11. Is there a way to preseve the behavior from 3.16 ?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [October 7, 2022, 4:41am UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/2 "2022-10-07T04:41:34Z")

</div>

@tambre might have some idea what’s going on with this one.

---

<div class="post-metadata">

### Author: ![tambre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tambre/32/5127_2.png) [@tambre](https://discourse.cmake.org/u/tambre)
#### Post date: [October 7, 2022, 8:22pm UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/3 "2022-10-07T20:22:49Z")

</div>

Please provide the resulting zipped build directory of a clean build with `--debug-trycompile --trace --trace-expand --trace-redirect=trace.txt`.

> However in cmake 3.24.1, the `try_compile` fails because -std=c++98 is being added after my -std=c++11.

I presume this is with `CMP0128` set to `NEW`? If there’s a change with it still being `OLD` then that’s a bug.

---

<div class="post-metadata">

### Author: ![malaterre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/malaterre/32/1971_2.png) [@malaterre](https://discourse.cmake.org/u/malaterre)
#### Post date: [October 10, 2022, 7:39am UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/4 "2022-10-10T07:39:05Z")

</div>

> [@tambre](#):
>
> Please provide the resulting zipped build directory of a clean build with `--debug-trycompile --trace --trace-expand --trace-redirect=trace.txt`.

Here you go:

[bad.tgz](https://discourse.cmake.org/uploads/short-url/fLvvxuBAbeNMHZzOrKs0JZOU54H.tgz) (131.3 KB)  
[good.tgz](https://discourse.cmake.org/uploads/short-url/5jVrYnyUPmstazAN62ZsICziD0F.tgz) (116.7 KB)

Full code is:

```auto
cmake_minimum_required(VERSION 3.10)
if(POLICY CMP0128)
  cmake_policy(SET CMP0128 OLD)
endif()
project(p VERSION 1.0.0)
set(CMAKE_CXX_EXTENSIONS OFF) # important
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Atomics REQUIRED)

```

Use case:

- [cmake: Detect whether or not atomic is needed by malaterre · Pull Request #1008 · google/highway · GitHub](https://github.com/google/highway/pull/1008)

Highway is not compiled with any particular `CMAKE_CXX_STANDARD` set.

---

<div class="post-metadata">

### Author: ![malaterre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/malaterre/32/1971_2.png) [@malaterre](https://discourse.cmake.org/u/malaterre)
#### Post date: [October 13, 2022, 6:43am UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/5 "2022-10-13T06:43:54Z")

</div>

@tambre do you need any additional details ? thanks

---

<div class="post-metadata">

### Author: ![tambre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tambre/32/5127_2.png) [@tambre](https://discourse.cmake.org/u/tambre)
#### Post date: [October 13, 2022, 6:46am UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/6 "2022-10-13T06:46:18Z")

</div>

Sorry, I’m simply very busy. Should hopefully have the time for a closer look over the weekend.

---

<div class="post-metadata">

### Author: ![tambre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tambre/32/5127_2.png) [@tambre](https://discourse.cmake.org/u/tambre)
#### Post date: [October 15, 2022, 1:50pm UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/7 "2022-10-15T13:50:20Z")

</div>

Would you be able to build CMake from source and bisect 3.16.3 and 3.24.2 for this issue?  
I’ve combed through the CMP0128 implementation once again and I suspect this is more likely to have resulted from an earlier refactor.

---

<div class="post-metadata">

### Author: ![malaterre](https://discourse.cmake.org/user_avatar/discourse.cmake.org/malaterre/32/1971_2.png) [@malaterre](https://discourse.cmake.org/u/malaterre)
#### Post date: [October 18, 2022, 5:58am UTC](https://discourse.cmake.org/t/cmake-cxx-standard-cmake-3-16-vs-3-24/6623/8 "2022-10-18T05:58:46Z")

</div>

Ok, then I’ll try to find some time then. I did report an issue to track progress, and communicate with upstream. Thanks

- [https://gitlab.kitware.com/cmake/cmake/-/issues/24063](https://gitlab.kitware.com/cmake/cmake/-/issues/24063)
