我检查了以下链接
但是我无法将llvm-header-guard与run-clang-tidy.py结合使用来解决问题
我有以下 CMakeLists.txt 文件
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}
)
并使用以下批处理文件(例如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
这将创建以下输出
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
有人知道如何正确运行clang-tidy python脚本吗?
感谢您的帮助!