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.

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.

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.

Try :

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

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.

Try add_compile_options().