简体   繁体   English

如何在 CMake 中添加排除 Protobuf 文件的编译器警告?

[英]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.我正在向我的 C++ 项目添加警告(并将它们视为错误),该项目使用 CMake 进行构建。 Initially I used target_compile_options .最初我使用target_compile_options But as I've added more warnings I've found that they're being triggered by the generated protobuf files.但是随着我添加了更多警告,我发现它们是由生成的 protobuf 文件触发的。

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 ).我想要做的是能够为除生成的 protobuf 文件(在本例中myapp.pb.cc )之外的所有源文件设置警告。 Is there any standard way of doing this in CMake?在 CMake 中有没有标准的方法来做到这一点?

I found I can use set_source_files_properties like this:我发现我可以像这样使用set_source_files_properties

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})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM