CMake add target for invoking clang analyzer

你说的曾经没有我的故事 提交于 2019-11-29 00:20:43

问题


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?


回答1:


You can use scan-build when running cmake.

scan-build cmake /path/to/source
scan-build make

scan-build sets the CC and CXX environment variables which are picked up by cmake.




回答2:


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>?).



来源:https://stackoverflow.com/questions/19050461/cmake-add-target-for-invoking-clang-analyzer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!