Can CXX_CLANG_TIDY use .clang-tidy file?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can CXX_CLANG_TIDY use .clang-tidy file?

Mateusz Loskot
Hi,

Am I correct clang-tidy run via CXX_CLANG_TIDY
ignores .clang-tidy configuration file?

I've tried number of ways to help it find the file,
i.e. copied the file to binary directories from where it seems run via
usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net
Reply | Threaded
Open this post in threaded view
|

Re: Can CXX_CLANG_TIDY use .clang-tidy file?

CMake mailing list

On 12/8/2018 7:47 PM, Mateusz Loskot wrote:
> Hi,
>
> Am I correct clang-tidy run via CXX_CLANG_TIDY
> ignores .clang-tidy configuration file?
>
> I've tried number of ways to help it find the file,
> i.e. copied the file to binary directories from where it seems run via
> usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7

I don't think anything was done to turn that off on purpose.  Can you
run the command from the command line and get it to work?  If so, you
should be able to get the same arguments to the clang tidy that CMake is
running.

-Bill

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can CXX_CLANG_TIDY use .clang-tidy file?

Mateusz Loskot
On Mon, 10 Dec 2018 at 18:31, Bill Hoffman via CMake <[hidden email]> wrote:

> On 12/8/2018 7:47 PM, Mateusz Loskot wrote:
> >
> > Am I correct clang-tidy run via CXX_CLANG_TIDY
> > ignores .clang-tidy configuration file?
> >
> > I've tried number of ways to help it find the file,
> > i.e. copied the file to binary directories from where it seems run via
> > usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7
>
> I don't think anything was done to turn that off on purpose.  Can you
> run the command from the command line and get it to work?  If so, you
> should be able to get the same arguments to the clang tidy that CMake is
> running.

Bill,

Thank you for the hint. It helped to discover it turns out to be a silly issue.

My .clang-tidy listed checks that would issue no warnings for the
target source files :)

Since, apparently, clang-tidy via
/usr/local/bin/cmake -E __run_co_compile --tidy=/usr/bin/clang-tidy-7
runs in quiet mode, while when run directly /usr/bin/clang-tidy-7,
it outputs a brief summary even if no analysis warnings are issued.
That left me with impression, .clang-tidy is not used.

To summary, for records and others looking for similar answers, here
is what works for me:

1. .clang-tidy is in source root directory

2. Top-level CMakeLists.txt

```
find_program(CLANG_TIDY
  NAMES clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0 clang-tidy-4.0 clang-tidy
```

and

```
set_target_properties(test_headers_all_in_one
  PROPERTIES
    CXX_CLANG_TIDY ${CLANG_TIDY})
```

Notice, since checks are specified in .clang-tidy configuration file,
no arguments need to be specified to clang-tidy.

3. Build analysed target

```
$ cd project
$ cmake -S . -B _build -DBoost_ARCHITECTURE=-x64 ..
$ VERBOSE=1 cmake --build _build --target test_headers_all_in_one

# alternative to the last command may be

$ cd _build
$ VERBOSE=1 make test_headers_all_in_one
```

Both, will run clang-tidy with checks read from .clang-tidy config,
and output of any warnings.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
--
Mateusz Loskot
http://mateusz.loskot.net