'How can I add compiler warnings in CMake that exclude Protobuf files?
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?
Solution 1:[1]
I found I can use set_source_files_properties like this:
protobuf_generate_cpp(MYAPP_PROTO_SRCS MYAPP_PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/myapp.proto)
set(MYAPP_SRCS myapp.cpp)
set_source_files_properties${MYAPP_SRCS} PROPERTIES COMPILE_OPTIONS "-Wall;-Werror")
add_executable(myapp ${MYAPP_SRCS} ${MYAPP_PROTO_SRCS})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | parsley72 |
