Skip to content

Cmake ignores CMAKE_C_FLAGS in Visual Studio

This may be an issue, or it may be that CMake does not support separate C and CXX compiler flags for Visual Studio. If it's the later, please comment and close this issue.

Attached is a bare bones project. It has a C and C++ source file. Different compiler flags are specified for C and C++ files. When the project is generated with "cmake -S . -B buildvs -G"Visual Studio 17 2022"", the Visual Studio project does not have different compiler options for the C and C++ files. Both files get the C++ flags. This can be seen by looking at the command line item in the Properties of each file in Visual Studio. Also can be seen by the C4127 warning from the C file not being ignored.

Using CMake V3.22.5, Visual Studio Community 2022.

Regards

Ashley

CCompilerFlagsIgnored.zip

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information