Setting properties for Qt autogen target

I have a library using Qt and I am using cppcheck. I do not want to run cppcheck on the resulting ‘autogen’ target, but you can’t set the target properties on the autogen target to disable cppcheck because the target is created (I think) during the generation step of cmake. See code below.

Is there a way to set properties for the Qt autogen targets to disable cppcheck on those targets? Is there another way to keep cppcheck from running on those targets?

set( CMAKE_CXX_CPPCHECK "/path/to/cppcheck" )

add_library( GUI SHARED )

set_target_properties( GUI PROPERTIES AUTORCC TRUE )

target_sources( GUI
  # cppcheck can't handle the resultant qrc_*.cpp files

# need to disable cppcheck on autogen target, but can't do this
# because GUI_autogen doesn't exist
set_property( TARGET GUI_autogen PROPERTY CXX_CPPCHECK "" )


You could create a .clang-tidy file in the build folder that disables all tests.

You may be able to set source file properties on them. CMake 3.27 also has the SKIP_LINTING property which may be able to help.

Are the source file properties for the Qt resource files (.qrc) transitive to the autogen target? It didn’t work for me. The GUI_autogen target still ran the resulting qrc_some_resource.cpp file through cppcheck.

You might be able to set the property on the qrc_some_resource.cpp filename (source properties can be loose, so this might be a benefit here).

I just installed 3.27 to play with the generator expressions for the _CPPCHECK property and cppcheck is no longer run on the auto targets!

Yes, autogen files are skipped for code checks starting with CMake 3.27, thanks to MR 8467.