CMake添加调用clang分析器的目标 [英] CMake add target for invoking clang analyzer
问题描述
我基本上想要达到 http:// blog .alexrp.com / 2013/09/26 / clangs-static-analyzer-and-automake ,但使用CMake。
analyze_srcs = foo.c
analyze_plists = $(analyze_srcs:%。c =%。plist)
CLEANFILES = $(analyze_plists)
$(analyze_plists) .plist:%.c
@echoCCSA$ @
@ $(COMPILE)--analyze $< -o $ @
analyze:$(analyze_plists)
.PHONY:analyze
所以你可以运行
make analyze
make clean
我想我需要使用 add_custom_command / add_custom_target
,并以某种方式更改对象文件
然后获取生成的文件的列表,或者将它们传递到脚本,将它们合并为1个输出文件。
$ b我发现了一种方法:
p> function(add_clang_static_analysis target)
get_target_property(SRCs $ {target} SOURCES)
add_library($ {target} _analyze OBJECT EXCLUDE_FROM_ALL $ {SRCs})
set_target_properties($ {target} _analyze PROPERTIES
COMPILE_OPTIONS--analyze
EXCLUDE_FROM_DEFAULT_BUILD true)
endfunction )
将clang的plist文件(以这种方式获得扩展名。 $< TARGET_OBJECTS:objlibtarget>
?)。
I'd basically like to achieve the same as http://blog.alexrp.com/2013/09/26/clangs-static-analyzer-and-automake, but with CMake.
analyze_srcs = foo.c
analyze_plists = $(analyze_srcs:%.c=%.plist)
CLEANFILES = $(analyze_plists)
$(analyze_plists): %.plist: %.c
@echo " CCSA " $@
@$(COMPILE) --analyze $< -o $@
analyze: $(analyze_plists)
.PHONY: analyze
So you can run
make analyze
make clean
I guess I need to use add_custom_command/add_custom_target
and somehow change the "object file" extension just for that target.
Afterwards get a list of the generated files to perhaps pass them to a script for combining them into 1 output file.
Can anyone point me in the right direction?
I found a way:
function(add_clang_static_analysis target)
get_target_property(SRCs ${target} SOURCES)
add_library(${target}_analyze OBJECT EXCLUDE_FROM_ALL ${SRCs})
set_target_properties(${target}_analyze PROPERTIES
COMPILE_OPTIONS "--analyze"
EXCLUDE_FROM_DEFAULT_BUILD true)
endfunction()
Combining clang's plist files (which get extension .o this way) into a report is still open ($<TARGET_OBJECTS:objlibtarget>
?).
这篇关于CMake添加调用clang分析器的目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!