Search code examples
xcodexcode9code-analysisstatic-code-analysiscppcheck

How can I show cppcheck output in Xcode?


I want to display cppcheck output directly in the Xcode Issue Navigator. How can I do that?


Solution

  • Here is a simple script that you can add as a Run Script Phase in your Build Phases in Xcode:

    #!/bin/bash
    srcDir=src
    if which cppcheck >/dev/null; then
    cppcheck -j 4 --enable=all --inline-suppr $srcDir 2>cppcheck.txt 1>/dev/null
    pwd=$(pwd)
    sed "s|\[|${pwd}/|" cppcheck.txt | sed 's|\]: |: warning: |'
    rm cppcheck.txt
    else
    echo "warning: cppcheck not installed, install here: http://brewformulas.org/Cppcheck"
    fi