I am trying to run clang-tidy in my project for a submodule, but it throws errors for the standard libraries, like 'string' file not found or the same for 'cmath'. Development is under Windows with Qt Creator and MinGW.
This is my Cmake file
option(RUN_CLANG_TIDY "Run clang-tidy with the compiler." ON)
if(RUN_CLANG_TIDY)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "CMake_RUN_CLANG_TIDY requires an out-of-source build!")
endif()
file(GLOB CLION_PATH
"C:/Program Files/JetBrains/CLion*/bin/clang/win"
)
find_program(CLANG_TIDY_EXE NAMES clang-tidy
HINTS
"C:/Program Files/LLVM/bin"
"C:/Qt/Tools/QtCreator/bin/clang/bin"
"${CLION_PATH}"
)
if(NOT CLANG_TIDY_EXE)
message(WARNING "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
else()
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}")
message("-- Clang-tidy found: ${DO_CLANG_TIDY}")
endif()
endif()
...
add_library(...)
if(DO_CLANG_TIDY)
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
endif()
target_include_directories(...)
I already tried some stuff and checked everything under the clang-tidy tag here in stackoverflow.
What I tried:
1) Setting the Cmake C++ include path by
set(CPLUS_INCLUDE_PATH C:/Qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++)
2) Generating the compile_commands.json with
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
...
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-p C:/Users/User04/Documents/Projekte/build-my-project-Desktop_Qt_5_12_6_MinGW_64_bit-Debug")
and pointing clang-tidy with -p to it. Error: for the -p option: may not occur within a group
3) Using the -extra-arg parameter like
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-extra-arg=-I C:/Qt/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++")
also instead of -I
I tried -isystem
with same result: Error 'string' file not found [clang-diagnostic-error]
4) Trying to pass the stdlib to clang-tidy
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-extra-arg=-stdlib==libc++")
But nothing works.