# CMAKE toolchain does not set the compiler option -std to gnu17 or c++17 although I have added "set(CMAKE\_CXX\_STANDARD 17)" in CMakeLists.txt.

**URL:** https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770
**Category:** Code
**Tags:** tool:cmake
**Created:** [May 1, 2024, 7:51am UTC](https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770 "2024-05-01T07:51:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sahu.swapnil25](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@sahu.swapnil25](https://discourse.cmake.org/u/sahu.swapnil25)
#### Post date: [May 1, 2024, 7:51am UTC](https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770/1 "2024-05-01T07:51:53Z")

</div>

This is regarding the build of a project by new compiler that I have configured in cmake toolchain file. For new compiler, I have configured CMAKE\_CXX\_COMPILER and CMAKE\_CXX\_COMPILER\_ID.

Also, for c++17 feature I have set below 2 variable.

```auto
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")

```

I have requested for C++17 features through CMakeLists.txt from our project by stmt “set(CMAKE\_CXX\_STANDARD 17)”. But Compiler flags to enable C++17, such as std=c++17, are not specified at compile time, C++17 source file cannot be compiled.

I have looked for CXX\_FLAGS in flags.make of our project but “-std=c++17” in not added here by “Unix Makefiles” Generator.

I have to ask below query related to add new compiler in cmake tool chain file -

1. If we add any new compiler in cmake toolchain file that is not listed in cmake source code whether CMAKE\_CXX\_STANDARD variable will be supported to enable language feature, or we have to list new compiler in cmake source code.

2. Whether something is missing in cmake tool chain file so CMAKE\_CXX\_STANDARD might not work.

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [May 6, 2024, 8:16pm UTC](https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770/2 "2024-05-06T20:16:17Z")

</div>

Try :

```auto
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

```

---

<div class="post-metadata">

### Author: ![sahu.swapnil25](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@sahu.swapnil25](https://discourse.cmake.org/u/sahu.swapnil25)
#### Post date: [May 10, 2024, 7:06am UTC](https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770/3 "2024-05-10T07:06:43Z")

</div>

I have already tried this. But still c++17 flag not enabled. I think CMAKE\_CXX\_STANDARD works for compilers which are supported in cmake source files.

Please let me know whether my understanding is correct.  
@Oodini thank for reply.

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [May 14, 2024, 2:00pm UTC](https://discourse.cmake.org/t/cmake-toolchain-does-not-set-the-compiler-option-std-to-gnu17-or-c-17-although-i-have-added-set-cmake-cxx-standard-17-in-cmakelists-txt/10770/4 "2024-05-14T14:00:26Z")

</div>

Try [add\_compile\_options()](https://cmake.org/cmake/help/latest/command/add_compile_options.html).
