[CMake] Ignoring Visual Studio 2015 warnings in .inl files
Niels Dekker - address until 2018
niels_dekker_address_until_2018 at xs4all.nl
Fri Oct 2 17:45:55 EDT 2015
On 02 Oct 2015 10:53 PM, compix (Wladimir) wrote:
> I'm trying to ignore warnings in VS2015 in .inl files with
> set(CMAKE_CXX_FLAGS "/w")
> set(CMAKE_C_FLAGS "/w")
>
> Unfortunately it doesn't work.
> I'd be glad if anyone could help me out.
First of all, it is often preferable to fix warnings, instead of
ignoring them. Of course... :-)
Then it appears that with VS2010 - VS2015, adding "/w" to
CMAKE_CXX_FLAGS may trigger another warning, "warning D9025:
overriding '/W1' with '/w'". For details, you may check
http://public.kitware.com/pipermail/vtkusers/2015-September/092255.html However,
that issue does not occur when you replace your "/w" by "/W0".
ITK and VTK basically use the following two CMake commands to disable
MSVC warnings:
string(REGEX REPLACE "(^| )[/-]W[0-4]( |$)" " "
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
For example, look at macro(itk_module_warnings_disable) in
https://github.com/InsightSoftwareConsortium/ITK/blob/master/CMake/ITKModuleMacros.cmake#L327
Keep in mind that doing so disables all warnings in a project. If you
want to disable only warnings from header files, you can do #pragma
warning(push, 0) before the #include statement, and #pragma
warning(pop) afterwards. But of course, that's just Visual C++, not CMake!
Good luck!
Niels
--
Niels Dekker
Scientific programmer
LKEB, Division of Image Processing
Leiden University Medical Center
More information about the CMake
mailing list