include(CheckCXXCompilerFlag)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    check_cxx_compiler_flag("-fanalyzer" HAS_GCC_STATIC_ANALYZER)
    if(HAS_GCC_STATIC_ANALYZER AND NOT ENABLE_LINTING)
        option(ENABLE_GCC_STATIC_ANALYZER "Enable linting with the GCC static analyzer" OFF)
        if(ENABLE_GCC_STATIC_ANALYZER)
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fanalyzer")
            set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fanalyzer")
        endif()
    endif()
endif()
