Last active
December 20, 2021 11:05
-
-
Save samolisov/eedc89dcc442cdcc808eb8c811fd0d09 to your computer and use it in GitHub Desktop.
CMake: add target for invoking Clang Static Analyzer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The solution is based upon this answer: | |
# https://stackoverflow.com/questions/19050461/cmake-add-target-for-invoking-clang-analyzer | |
function(add_clang_static_analysis target) | |
get_target_property(SRCs ${target} SOURCES) | |
add_library(${target}_analyze OBJECT EXCLUDE_FROM_ALL ${SRCs}) | |
if (MSVC) | |
list(APPEND ANALYZER_OPTIONS --analyze) | |
list(APPEND ANALYZER_OPTIONS "SHELL:/clang:-Xanalyzer /clang:-analyzer-opt-analyze-headers") | |
list(APPEND ANALYZER_OPTIONS "SHELL:/clang:-Xanalyzer /clang:-analyzer-output=html") | |
# see output in <build/<file>.plist directories | |
else() | |
list(APPEND ANALYZER_OPTIONS --analyze) | |
list(APPEND ANALYZER_OPTIONS "SHELL:-Xanalyzer -analyzer-opt-analyze-headers") | |
list(APPEND ANALYZER_OPTIONS "SHELL:-Xanalyzer -analyzer-output=html") | |
# see output in <build>/<tree>/CMakeFiles/<target>.dir/<file>.obj directories | |
endif(MSVC) | |
set_target_properties(${target}_analyze PROPERTIES | |
COMPILE_OPTIONS "${ANALYZER_OPTIONS}" | |
EXCLUDE_FROM_DEFAULT_BUILD true) | |
endfunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment