How to use clang-tidy with qt project



  • I can use https://github.com/KDE/clazy with: qmake -spec linux-clang QMAKE_CXX=clazy
    Is it possible to use clang-tidy same way ?
    QtCreator 4.6.0. can clang-tidy but is too damn slow and not convenient.


  • Qt Champions 2017

    Hi
    I used ccache same way (in the .pro file) so if clang-tidy also works
    as a meta compiler then
    it should work.



  • Yes, the question is: can clang-tidy works with .pro as clazy ?
    I dont know )
    Another way is to use find *.cpp and call clang-tidy for every file, while no solution exists.


  • Qt Champions 2017

    Hi
    why not just try it ?
    its one line in the .pro file



  • I tried QMAKE_CXX=clang-tidy - not worked
    This way or another ?



  • Created script to run clang-tidy manually, usage: ./RunClangTidy.sh /where/my.pro logSuffix

    #!/bin/bash
    
    # Run qmake to generate Makefile
    qmake $1
    
    # Checks
    CHECKS="clang-*,cppcoreguidelines-*,modernize-*,performance-*,-clang-diagnostic-old-style-cast,-clang-diagnostic-sign-conversion,\
    -modernize-use-auto,-cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,\
    -clang-diagnostic-conversion,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-cstyle-cast,-clang-diagnostic-missing-variable-declarations,\
    -clang-diagnostic-documentation-unknown-command,-clang-diagnostic-covered-switch-default"
    
    # Warnings (from qtcreator - options - c++ - code model - clang)
    WARN="-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-unused-macros -Wno-newline-eof -Wno-exit-time-destructors -Wno-global-constructors \
    -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation -Wno-shadow -Wno-switch-enum -Wno-missing-prototypes -Wno-used-but-marked-unused \
    -Wno-unknown-pragmas -Wno-unused-parameter"
    
    # Get project includes from Makefile
    INCLUDES=$(cat Makefile| grep "^INCPATH *="| awk -F"=" '{print $2}')
    
    # Get project defines from Makefile
    DEFINES=$(cat Makefile| grep "^DEFINES *="| awk -F"=" '{print $2}')
    
    # Then COPY_FILE variable in Makefile contains all files of the project (QMake version 3.1)
    LOGF="CLANG-TIDY-LOG_$2.CPP"
    LOGF_NOQT="CLANG-TIDY-LOG_$2_NOQT.CPP"
    (
    date
    FILE_COUNT=0
    cat Makefile | grep "COPY_FILE" | grep cpp | while read -rd " " file
    do
        [[ "${file##*cpp}" ]] && continue
    
        H="${file%.*}"
    
        ((FILE_COUNT++))
        echo "=== PROCESSING FILE: $FILE_COUNT $file [$H] ============================================================"
    
        clang-tidy \
        -checks="$CHECKS" \
        -header-filter="$H*" $file \
        -- \
        -std=c++1z \
        -D_REENTRANT -fPIC \
        $WARN $DEFINES $INCLUDES
    done
    date
    ) 2>&1 | tee $LOGF
    cat $LOGF | grep -v QtCore > $LOGF_NOQT
    
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.