cmake clang-tidy(或其他脚本)作为自定义目标 [英] cmake clang-tidy (or other script) as custom target
问题描述
我正在尝试为clang-tidy创建一个自定义cmake目标,以使我的项目更整齐.源文件夹看起来像这样:
I am trying to create a custom cmake target for clang-tidy, to lint my project. The source folder looks something like this:
src/scripts/run-clang-tidy.py
src/.clang-tidy
src/...
到目前为止,我的计划是使用自定义命令将这两个文件都复制到构建目录:
So far my plan was to copy both these files to the build directory with a custom command:
add_custom_command(
OUTPUT run-clang-tidy.py .clang-tidy
COMMAND cp ${CMAKE_SOURCE_DIR}/scripts/run-clang-tidy.py ${CMAKE_SOURCE_DIR}/.clang-tidy ${CMAKE_CURRENT_BINARY_DIR})
我现在想在构建目录(应该是工作目录)中调用带有自定义目标的run-clang-tidy.py
,以便我可以调用:
I now want to call run-clang-tidy.py
in the build directory (which should be the working directory), with a custom target, so that I can just call:
make lint
应该运行.clang-tidy
中指定的检查.
Which should run the checks specified in .clang-tidy
.
要使此脚本正常工作,还需要CMAKE_EXPORT_COMPILE_COMMANDS
选项.我尝试使用以下命令进行设置,但无法识别它:
For this script to work, it also needs the CMAKE_EXPORT_COMPILE_COMMANDS
option. I try to set it with the following command, but it does not recognize it:
add_definitions(-DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
对add_custom_target
的调用看起来如何?
推荐答案
从CMake 3.6开始,实现了clang-tidy
的本机集成[1 , 2 ].机制类似于自CMake 3.3以来的include-what-you-use
集成[ 3 ].
Since CMake 3.6, native integration of clang-tidy
is implemented [1, 2]. Mechanics are similar to include-what-you-use
integration that was there since CMake 3.3 [3].
这篇关于cmake clang-tidy(或其他脚本)作为自定义目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!