I need to disable all warnings from a directory of a project which uses the external library ProtocolBuffers, which produces its own warnings.
These are some of the 151 warnings I get:
my.pb.cc: warning C4512: 'google::protobuf::FatalException' : assignment operator could not be generated
my.pb.cc: warning C4244: 'initializing' : conversion from '__int64' to 'int', possible loss of data
my.pb.cc: warning C4125: decimal digit terminates octal escape sequence
my.pb.cc: warning C4127: conditional expression is constant
my.pb.cc
xutility(2132): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS.
Where xutility
is a Visual Studio include file.
If I add these lines in my CMakeLists.txt file:
# Use a lower warning level threshold for autogenerated files
set(PROTOBUF_FILES_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/*.pb.*")
file(GLOB PROTOBUF_FILES ${PROTOBUF_FILES_PATH})
set_source_files_properties(${PROTOBUF_FILES} PROPERTIES COMPILE_FLAGS /W2)
I get all warnings from my generated pb.cc
files disabled, but I still have 15 warnings left from ProtoBuf's internal code, of the type:
my.pb.cc
xutility(2132): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS.
How can I disable these last warnings, possibly adjusting my CMakeLists.txt file adding the -D_SCL_SECURE_NO_WARNINGS
option, just for files with extension *.pb.*
, considering I cannot modify ProtoBuf itself?
Without knowing much about xutility
or how it is used by Protobuf, I would suggest trying to expand your set_source_files_properties()
call to include COMPILE_DEFINITIONS
:
set_source_files_properties(${PROTOBUF_FILES} PROPERTIES
COMPILE_DEFINITIONS _SCL_SECURE_NO_WARNINGS
COMPILE_FLAGS /W2
)