Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. clang-tidy: adjust used compile commands / pass flags possible?
Forum Updated to NodeBB v4.3 + New Features

clang-tidy: adjust used compile commands / pass flags possible?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
4 Posts 2 Posters 585 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.
  • M Offline
    M Offline
    matse
    wrote on 4 Dec 2024, 08:33 last edited by
    #1

    Hello,

    I have a quite complex and large project, that uses an own build system on top of cmake and uses e.g. Intel compiler.
    Currently I can load the CMakeLists.txt and work on the project in QtCreator (15.0.0) just fine.
    Now I wanted to use clang-tidy on one file, unfortunately this is currently not possible for me in QtCreator. I managed to get it working from the command-line, so let me first explain what I had to do to get it running:

    I enabled

    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    

    to generate a compile_commands.json file in my build directory build/ninja/Debug
    When first trying to run:

    clang-tidy source/my_file.cpp -p build/ninja/Debug
    

    where I specified the build path (to the location where also compile_commands.json is) with the -p switch.
    With this I got an error like:

    error: 'Kokkos_Core.hpp' file not found [clang-diagnostic-error]
       13 | #include "Kokkos_Core.hpp"
    

    For any reason I could build the library just finie and it picked up this header and the corresponding library, but clang-tidy did not find it. So I manually added the path to the library with the -I switch:

    clang-tidy source/my_file.cpp -p build/ninja/Debug -- -I $TRILINOS_DIR/include/
    

    With this I got the next error:

    error: unknown argument: '-no-diag-error-limit' [clang-diagnostic-error]
    

    This is an Intel flag, specified in the compile_commands.json file.
    I removed this flag manually in my compile_commands.json and finally clang-tidy works fine from the command line.
    However - it would be great to see the problems in QtCreator with the visual feedback. Unfortunately if I run clang-tidy on the same file, I get the same error as before on the command line:

    error: unknown argument: '-no-diag-error-limit' [clang-diagnostic-error]
    

    Is there a way to adjust this in a similar way, as before manually or how does QtCreator invode clang-tidy (and is there a way to adjust this behavior)?

    Maybe anybody can help me here.
    Thanks and many greetings
    matse

    1 Reply Last reply
    0
    • M Offline
      M Offline
      matse
      wrote on 4 Dec 2024, 08:50 last edited by
      #2

      A little update on this:
      I just saw the QtCreator output:

      Creating compilation database for Clang-Tidy in "/tmp/QtCreator-GXwzFX/Clang-Tidy.XgcZGh" ...
      

      So in /tmp/QtCreator-GXwzFX/Clang-Tidy.XgcZGh/compilation_commands.json I removed -no-diag-error-limit for my source file and this helped with the first error. Now I get the other error (that I first got on the command line):

      error: 'Kokkos_Core.hpp' file not found [clang-diagnostic-error]
         13 | #include "Kokkos_Core.hpp"
      

      So I'm looking for a way to adjust the include path or pass parameters to clang-tidy. Of course it would be also nice if QtCreator would use a compilation_database, that is persistent or if I could find a better way to cope with the situation.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cristian-adam
        wrote on 4 Dec 2024, 15:42 last edited by
        #3

        Try setting the environment variable QTC_CLANG_CMD_OPTIONS_BLACKLIST=-no-diag-error-limit before starting Qt Creator.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          matse
          wrote on 5 Dec 2024, 15:19 last edited by
          #4

          @cristian-adam Thanks for the quick help! This is really great and works like a charm. I can simply pass all the arguments via the environment variable - how nice!
          I will mark this as solved. Thanks again for the help and many greetings
          matse

          1 Reply Last reply
          1
          • M matse has marked this topic as solved on 5 Dec 2024, 15:19

          1/4

          4 Dec 2024, 08:33

          • Login

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