Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use clang-tidy with qt project

How to use clang-tidy with qt project

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 5.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abarmotov
    wrote on 4 Apr 2018, 08:30 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 4 Apr 2018, 08:36 last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        abarmotov
        wrote on 4 Apr 2018, 12:51 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 4 Apr 2018, 13:14 last edited by
          #4

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

          1 Reply Last reply
          2
          • A Offline
            A Offline
            abarmotov
            wrote on 5 Apr 2018, 09:30 last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              abarmotov
              wrote on 13 Apr 2018, 11:14 last edited by
              #6

              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
              
              
              
              1 Reply Last reply
              1
              • A Offline
                A Offline
                Allan Jensen
                wrote on 22 Nov 2019, 12:20 last edited by
                #7

                Use bear, see https://www.kdab.com/clang-tidy-part-2-integrate-qmake-and-other-build-systems-using-bear/

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved