CMake add target for invoking clang analyzer

前端 未结 2 1454
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 13:58

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
analyz         


        
相关标签:
2条回答
  • 2020-12-24 14:24

    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.

    0 讨论(0)
  • 2020-12-24 14:39

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

    0 讨论(0)
提交回复
热议问题