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. Running clang tidy for a qmake project from the command line

Running clang tidy for a qmake project from the command line

Scheduled Pinned Locked Moved Unsolved General and Desktop
clang-tidyqmakelinuxclang
2 Posts 2 Posters 1.8k 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.
  • B Offline
    B Offline
    bepzi
    wrote on 25 Aug 2020, 18:59 last edited by bepzi
    #1

    Context: my project (Qt 5.12, qmake-based) is developed on Windows with Qt Creator and automatically tested on an Ubuntu 20.04 build server. I'd like to use clang-tidy to get additional static analysis checks in my CI system (e.g, fail the build if clang-tidy reports something.)

    I've tried to use bear to generate a compile_commands.json file when my project is compiled in CI:

    #!/bin/bash
    # Compile
    mkdir build && cd build
    qmake -spec linux-clang ../main.pro
    make qmake_all
    bear make  # generates compile_commands.json
    
    # Lint
    run-clang-tidy
    

    This almost works (clang-tidy will run with the settings defined in my .clang-tidy file), but the generated compile_commands.json is written in terms of moc_*.cpp files, which means clang-tidy is reporting warnings on the code that moc generated -- not my actual code. For example, I see stuff like this:

    /home/user/Code/MyProject/build/src/core/moc_mysourcefile.cpp:97:9: warning: function-like macro 'QT_MOC_LITERAL' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]             #define QT_MOC_LITERAL(idx, ofs, len) \          
                                                                                ^                                                                                                            
    
    /home/user/Code/MyProject/build/src/core/moc_mysourcefile.cpp:99:93: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]                                                      qptrdiff(offsetof(qt_meta_stringdata_NotificationFullDateTimeDelegate_t, stringdata0) + ofs \                                                                                                                ^                                                                                                                    (  )   
    

    What I really want is the kind of warnings I get when I do Analyze > Clang-Tidy in Qt Creator on Windows. In Qt Creator, clang-tidy is able to provide static analysis on my actual source code.

    Is there a way to get good clang-tidy checks in my headless Linux CI system?

    Things I've looked at:

    • https://forum.qt.io/topic/89509/how-to-use-clang-tidy-with-qt-project/7
    • https://www.kdab.com/clang-tidy-part-2-integrate-qmake-and-other-build-systems-using-bear/
    • https://forum.qt.io/topic/112106/you-can-generate-a-compile_commands-json-with-qt-creator-what/1
    1 Reply Last reply
    1
    • . Offline
      . Offline
      ._Miro_.
      wrote on 5 Jul 2023, 08:35 last edited by
      #2

      If you still have the same problem I published a bash solution which uses compiledb which allows to generate the file compile_commands.json with qmake on macOS: https://github.com/MiroYld/QtBuildTool

      1 Reply Last reply
      0

      • Login

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