1

I checked following links

but I can't solve the problem with the llvm-header-guard in combination with run-clang-tidy.py

I have following CMakeLists.txt file

cmake_minimum_required(VERSION 3.10)

project(Guard LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

file(WRITE ${PROJECT_SOURCE_DIR}/include/guard/Foo/Bar.h
   "#ifndef GUARD_FOO_BAR_H\n"
   "#define GUARD_FOO_BAR_H\n"
   "class BarC {\n"
   "public:\n"
   "  BarC();\n"
   "  ~BarC();\n"
   "};\n"
   "#endif // GUARD_FOO_BAR_H\n"
)

file(WRITE ${PROJECT_SOURCE_DIR}/lib/Foo/Bar.cpp
   "#include \"guard/Foo/Bar.h\"\n"
   "BarC::BarC(){}\n"
   "BarC::~BarC(){}\n"
)

include_directories(include)

add_library(Bar STATIC ${PROJECT_SOURCE_DIR}/lib/Foo/Bar.cpp)

add_custom_target(clang-tidy
   ALL
   COMMAND
      ${CMAKE_COMMAND} -E env "PATH=C:/LLVM/7.0.1-win64/bin;$ENV{PATH}" python C:/LLVM/7.0.1-win64/share/clang/run-clang-tidy.py -checks="llvm-header-guard" -header-filter=".*" -quiet
   DEPENDS
      Bar
   WORKING_DIRECTORY
      ${CMAKE_BINARY_DIR}
)

and use following batch file (e.g. scirpt.bat)

set "PATH=C:\Ninja\1.8.2\bin;%PATH%"
set "PATH=C:\CMake\3.12.0-win64-x64\bin;%PATH%"
set "PATH=C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\bin;%PATH%"
set CXX=g++

del /F /Q build
del /F /Q lib
del /F /Q include
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE:STRING=Release -G "Ninja" ..
ninja
pause

this creates following output

1 warning generated.
C:\Users\Zlatan\Guard\build\../include\guard/Foo/Bar.h:1:9: warning: header guard does not follow preferred style [llvm-header-guard]
#ifndef GUARD_FOO_BAR_H
        ^~~~~~~~~~~~~~~
        C:\USERS\ZLATAN\GUARD\BUILD\__\INCLUDE\GUARD\FOO\BAR_H
clang-tidy -header-filter=.* -checks=llvm-header-guard -p=C:\Users\Zlatan\Guard\build -quiet C:/Users/Zlatan/Guard/lib/Foo/Bar.cpp

Does somebody know how to run the clang-tidy python script correctly?

Thanks for the help!

ge45mue
  • 677
  • 8
  • 23
  • 1
    Possible duplicate of [clang-tidy header guard style warning](https://stackoverflow.com/questions/54088319/clang-tidy-header-guard-style-warning) This is a duplicate of your own question, there is nothing wrong with the way you're running it since it gives you a valid output. – pablo285 Jan 18 '19 at 13:59
  • When applying the suggested fix to the header file, the header guard looks like #define C:\USERS\ZLATAN\GUARD\BUILD\__\INCLUDE\GUARD\FOO\BAR_H. Therefore, I'm not able to compile the source any more. In my first question I only added the header file. In this questions I also added everything to reproduce and also added the information that I like to run clang-tidy with the run-clang-tidy.py script. – ge45mue Jan 21 '19 at 08:54

0 Answers0