Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

False warnings on code generated by QT Automoc #74

Open
borgmanJeremy opened this issue Jul 14, 2020 · 1 comment
Open

False warnings on code generated by QT Automoc #74

borgmanJeremy opened this issue Jul 14, 2020 · 1 comment

Comments

@borgmanJeremy
Copy link

borgmanJeremy commented Jul 14, 2020

I ported a code base from qmake to cmake and have started cleaning up compiler warnings. In doing so, I noticed that the cpp files generated by QT's Automoc triggers warnings on -Wundefined-reinterpret-cast and -Wuseless-cast.

There isn't much that can be done to fix the warnings since the code is autogenerated by qt. Since I reference this repo for handy defaults I thought I would post this to see if it would help others as a good default.

To fix this in my project I added the following lines to my CMake file:

# Ignore warnings related to autogenerated code from MOC
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/[project_name]_autogen/mocs_compilation.cpp PROPERTIES COMPILE_FLAGS "-Wno-undefined-reinterpret-cast")
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/[project_name]_autogen/mocs_compilation.cpp PROPERTIES COMPILE_FLAGS "-Wno-useless-cast")
@markon
Copy link

markon commented Sep 26, 2022

The solution you posted unfortunately doesn't seem to work for me (with clang). Maybe I just did it wrong. What helped me was to "kind of" disable clang-tidy on those files, more or less like it was done here: Kitware/CMake@b13bc86

For example:

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/[project_name]_autogen/.clang-tidy" "
---
Checks: '-*,llvm-twine-local'
...
")

It works until cppcheck or other checks come in, though. (still trying to figure it out). Probably a similar approach/solution will work.

EDIT: For cppcheck I had to do the following:

  1. Create a file in the project root, e.g., "cppcheck-suppressions.txt":
*:*_autogen/*
  1. Add this property:
dynamic_project_options(
        ....
        CPPCHECK_OPTIONS "--suppressions-list=${PROJECT_SOURCE_DIR}/cppcheck-suppressions.txt"
)

and it skipped all the files in the build/*/*_autogen/ folders.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants