# CXX\_CLANG\_TIDY not running for library

**URL:** https://discourse.cmake.org/t/cxx-clang-tidy-not-running-for-library/6547
**Category:** Code
**Tags:** tool:cmake
**Created:** [September 21, 2022, 10:04pm UTC](https://discourse.cmake.org/t/cxx-clang-tidy-not-running-for-library/6547 "2022-09-21T22:04:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DaAwesomeP](https://discourse.cmake.org/user_avatar/discourse.cmake.org/daawesomep/32/2794_2.png) [@DaAwesomeP](https://discourse.cmake.org/u/DaAwesomeP)
#### Post date: [September 21, 2022, 10:04pm UTC](https://discourse.cmake.org/t/cxx-clang-tidy-not-running-for-library/6547/1 "2022-09-21T22:04:17Z")

</div>

I am writing a library, and I cannot get clang-tidy to run on build. This is a headers-only library because all of the classes provided have templates, and you cannot define template class members outside of the template class. I suppose this means that compiling the library alone will produce a mostly empty result, but I would still expect it to run clang-tidy. Or maybe I’m missing something key in how this works?

`CMakeLists.txt`:

```auto
cmake_minimum_required(VERSION 3.18)
project(
    somelib
    LANGUAGES CXX
)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols")

ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
find_package(Boost 1.74.0 REQUIRED COMPONENTS log)
find_package(OpenSSL 1.1.0 REQUIRED)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)

add_library(
    ${CMAKE_PROJECT_NAME}
    include/somelib/A.hpp
    include/somelib/B.hpp
)
target_compile_features(${CMAKE_PROJECT_NAME} PUBLIC cxx_std_17)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Werror)
set_target_properties(
    ${CMAKE_PROJECT_NAME}
    PROPERTIES
        LINKER_LANGUAGE CXX
        CXX_EXTENSIONS OFF
        CXX_CLANG_TIDY "${CLANG_TIDY_EXE};")

target_include_directories(
    ${CMAKE_PROJECT_NAME}
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

install(
    TARGETS ${CMAKE_PROJECT_NAME}
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
)

```

`.clang-tidy`:

```nohighlight
Checks: "*"
WarningsAsErrors: "*"
HeaderFilterRegex: ".*"

```

File tree:

```nohighlight
.
├── .clang-tidy
├── CMakeLists.txt
├── .gitignore
├── include
│ └── somelib
│ ├── A.hpp
│ ├── B.hpp
└── README.md

```

Commands:

```bash
$ cmake -H. -B_builds/Debug -DCMAKE_BUILD_TYPE=Debug
-- The CXX compiler identification is GNU 10.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found suitable version "1.74.0", minimum required is "1.74.0") found components: log 
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found suitable version "1.1.1n", minimum required is "1.1.0")  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/myuser/libsomelib/_builds/Debug
$ cmake --build _builds/Debug
Scanning dependencies of target somelib
[100%] Linking CXX static library libsomelib.a
[100%] Built target somelib

```

What am I missing?

Thanks!

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [September 22, 2022, 6:46am UTC](https://discourse.cmake.org/t/cxx-clang-tidy-not-running-for-library/6547/2 "2022-09-22T06:46:05Z")

</div>

`clang-tidy` takes the role of the compiler, so it only runs on source files. You need at least one source file that include the various header files of the library.

---

<div class="post-metadata">

### Author: ![DaAwesomeP](https://discourse.cmake.org/user_avatar/discourse.cmake.org/daawesomep/32/2794_2.png) [@DaAwesomeP](https://discourse.cmake.org/u/DaAwesomeP)
#### Post date: [September 22, 2022, 6:51pm UTC](https://discourse.cmake.org/t/cxx-clang-tidy-not-running-for-library/6547/3 "2022-09-22T18:51:14Z")

</div>

Ah, thank you! That did it!

Changes made:

```auto
add_library(
    ${CMAKE_PROJECT_NAME}
    include/somelib/A.hpp
    include/somelib/B.hpp
    src/lintHelper.cpp
)

```

`src/lintHelper.cpp`:

```cpp
#include <somelib/A.hpp>
#include <somelib/B.hpp>

```
