I'm trying to control compiler warnings individually for C and C++ code in a cmake-based build:
For gcc and clang, I can set additional flags that are applied only to the C compiler like this with TARGET_COMPILE_OPTIONS:
target_compile_options(MyLib PRIVATE
$<$<AND:$<COMPILE_LANGUAGE:C>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>: -Wall>)
Now I want to do the same, but for MSVC:
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CXX_COMPILER_ID:MSVC>>: /W4>
This does not work -- it seems COMPILE_LANGUAGE:C is ignored by MSVC-based builds in mixed C/C++ projects. I'm testing with Visual Studio 2019.
Does anybody have a solution for this?
(Other than just using a separate target for the C code)
#define _CRT_SECURE_NO_WARNINGSand#define _CRT_SECURE_NO_DEPRECATEand#define _CRT_NONSTDC_NO_DEPRECATE. I place them at the top of every C source file, before any#includestatements. - Weather Vane