【发布时间】:2016-07-20 07:22:11
【问题描述】:
我们的项目使用了非常严格的警告集,但 Qt5 生成的 moc 文件生成的代码违反了这些警告。我们显然可以全局关闭警告,但我只想禁止 automoc 文件的警告。
例如:
In file included from /Users/stebro/client/build/NotificationServer/Notification_automoc.cpp:2:
/Users/stebro/client/build/NotificationServer/moc_NotificationServer.cpp:100:18: error: dereference of type '_t *' (aka 'void (carbonite::NotificationServer::**)(const QByteArray &, const QString, const QVariant)') that was reinterpret_cast from type 'void **' has undefined behavior [-Werror,-Wundefined-reinterpret-cast]
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&NotificationServer::notificationQueued)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
以下不起作用:
set_property(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
PROPERTY COMPILE_DEFINITIONS -Wundefined-reinterpret-cast
)
cmake 抱怨:
set_property DIRECTORY scope provided but requested directory was not
found. This could be because the directory argument was invalid or, it is
valid but has not been processed yet.
我不能使用 set_property(FILE ...) 因为我没有在构建 makefile 时自动执行的文件的完整列表(所以大概 GLOBing 也不起作用)。我不想手动维护将由构建生成的所有 moc 文件的列表。
【问题讨论】:
-
自从你问了这个问题后,你找到解决方法了吗?我目前遇到了同样的问题。
-
@Corristo:我们已经转移到 Qt 5.7 并且不再遇到这个问题(也许 Qt 的 automoc 清理了他们的行为)。如果您在 clang/OSX 环境中运行,我知道您可以通过在编译行中使用 -isystem
而不是 -I 来获得抑制“系统”标头的警告。可以将 ${CMAKE_CURRENT_BINARY_DIR} 指定为系统路径。 -
@Corristo:实际上,我说错了(我检查了我最初提交的日期——这条评论是针对我当前的项目,而不是我以前的)。不幸的是,我只是通过对所有代码进行全局抑制来解决 Qt 的不良行为,从而解决了这个问题。请参阅下面的答案。