1 get_cmake_property(ENABLED_LANGUAGES ENABLED_LANGUAGES)
2 include(CheckCXXCompilerFlag)
3 include(CheckCCompilerFlag)
5 function(list_append var)
7 list(FIND ${var} ${arg} index)
9 list(APPEND ${var} ${arg})
12 set(${var} ${${var}} PARENT_SCOPE)
17 string(REPLACE "+" "x" var ${arg})
18 string(REGEX REPLACE "[^A-Za-z0-9_-]+" "-" var ${var})
19 list(FIND ENABLED_LANGUAGES CXX index)
20 if(${index} GREATER -1)
21 check_cxx_compiler_flag(${arg} xx${var})
23 list_append(ANALYZER ${arg})
26 list(FIND ENABLED_LANGUAGES C index)
27 if(${index} GREATER -1)
28 check_c_compiler_flag(${arg} cc${var})
30 list_append(ANALYZER ${arg})
38 if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
39 # https://learn.microsoft.com/en-us/cpp/build/reference/analyze-code-analysis
40 analyzer_flag(/analyze)
41 elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
42 # https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html
43 analyzer_flag(-fanalyzer) # 10.1+
46 function(target_compile_analyzer)
47 foreach(target ${ARGN})
48 target_compile_options(${target} PRIVATE ${ANALYZER})