0

in my project I have a multiple modules and I want to integrate cppcheck or clang-tidy with cmake. The problem is that in case of integration mentioned tools in cmake and perform static analysis I get report only for last checked module. Is there a possibility to get one report for all modules from the project? I tried many different configurations but none of them worked.

Here is my exmaple of cpp integration with cmake:

find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=warning"
"--inconclusive"
"--force"
"--inline-suppr"
"--suppressions-list=${CMAKE_SOURCE_DIR}/CppCheckSuppressions.txt"
"--xml"
"--output-file=${CMAKE_SOURCE_DIR}/cppcheck-results.xml"
)
starball
  • 20,030
  • 7
  • 43
  • 238
emes9
  • 1

1 Answers1

0

Is there a possibility to get one report for all modules from the project? I tried many different configurations but none of them worked.

I think the answer at the time of this writing is no.

There's a relevant discussion on the CMake discourse site: parallel cppcheck invocation corrupts common output file, which links to this feature-request on Kitware's GitLab: Support file specifc properties for CMAKE__CPPCHECK #22020, which depends on Introduce SOURCE_FILE_PROPERTY generator expression that operates on properties of source files #21986, which (if I understand correctly) seems to imply that the next step in getting what you want isn't fully what you want, and instead will be getting one cppechck output file per source file to compile (based on a source file property like LOCATION).

Note: CMake runs analysis tools per-source file instead of invoking them with batches of source file, which I think is a good thing, since it leverages the generated buildsystem to avoid re-running analysis for files which don't need to be re-built. You can confirm that yourself if you look at the source code of what CMake generates for various buildsystems (for example, cmMakefileTargetGenerator::WriteObjectRuleFiles and cmNinjaTargetGenerator::WriteCompileRule).

It wouldn't be difficult to write a custom command using the build events signature of add_custom_command to concatenate all those output files into one file at the end of building a target, though. You could use the built-in cmake -E cat commandline command, or write and run a CMake script that gets a list of files under the common output directory, reads them, concatenates them, and writes the output to a file.

starball
  • 20,030
  • 7
  • 43
  • 238