I'm adding warnings (and treating them as errors) to my C++ project which uses CMake for builds. Initially I used target_compile_options. But as I've added more warnings I've found that they're being triggered by the generated protobuf files.
The build looks like this:
protobuf_generate_cpp(MYAPP_PROTO_SRCS MYAPP_PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/myapp.proto)
set(MYAPP_SRCS ${MYAPP_PROTO_SRCS} myapp.cpp)
add_executable(myapp ${MYAPP_SRCS})
target_compile_options(myapp PRIVATE -Wall -Werror)
What I want to do is to be able to set warnings for all source files except the generated protobuf file (in this case myapp.pb.cc
). Is there any standard way of doing this in CMake?
set_source_files_properties
is the proper way for set per-file compiler flags. Not sure why do you treat is a "HACK" or "a bit clunky". – Daimon