Procházet zdrojové kódy

#IQRV #comment 当你发现这就行了不用区分分号时震惊了

80374374 před 1 měsícem
rodič
revize
af45a4e4ad

+ 26 - 17
addin/cmake/CppCheckAnalysis.cmake

@@ -33,9 +33,9 @@ if(CPPCHECK_EXECUTABLE)
     message("cppcheck version: ${CPPCHECK_VERSION}")
 endif(CPPCHECK_EXECUTABLE)
 
-if(NOT TARGET analyse-all)
-    add_custom_target(analyse-all)
-    set_target_properties(analyse-all PROPERTIES EXCLUDE_FROM_ALL TRUE)
+if(NOT TARGET cppcheck_analyse_all)
+    add_custom_target(cppcheck_analyse_all)
+    set_target_properties(cppcheck_analyse_all PROPERTIES EXCLUDE_FROM_ALL TRUE)
 endif()
 
 # ::
@@ -63,7 +63,7 @@ endfunction()
 
 # ::
 #
-#     add_cppcheck(<target>
+#     target_add_cppcheck(<target>
 #                  [ALL]
 #                  [IGNORE_WARNINGS]
 #                  [IGNORE_STYLE]
@@ -100,7 +100,7 @@ endfunction()
 # include directories for a library, when it is being linked with an
 # executable.
 #
-function(add_cppcheck _target_name)
+function(target_add_cppcheck _target_name)
     if(NOT TARGET ${_target_name})
         message(FATAL_ERROR
             "[CppCheck] add_cppcheck given a target name that does not exist: '${_target_name}' !")
@@ -124,8 +124,8 @@ function(add_cppcheck _target_name)
     endif()
 
     set(_cppcheck_args)
-    list(APPEND _cppcheck_args "--xml")
-    list(APPEND _cppcheck_args "--xml-version=2")
+    #list(APPEND _cppcheck_args "--xml")
+    #list(APPEND _cppcheck_args "--xml-version=2")
     foreach(_cppcheck_opt ${CPPCHECK_PROJECT_OPTIONS})
         list(APPEND _cppcheck_args ${_cppcheck_opt})
     endforeach()
@@ -203,17 +203,28 @@ function(add_cppcheck _target_name)
     get_target_property(_cppcheck_sources "${_target_name}" SOURCES)
 
     list(APPEND _cppcheck_includes ${CPPCHECK_INCLUDES})
+    message(STATUS "[CppCheck] _cppcheck_includes:${_cppcheck_includes}")
 
     set(_files)
     foreach(_source ${_cppcheck_sources})
         get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
         get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
-        if("${_cppcheck_lang}" MATCHES "^CXX$" OR "${_cppcheck_lang}" MATCHES "^C$" OR "${_cppcheck_lang}" MATCHES "^CPP$")
+        if("${_cppcheck_lang}" MATCHES "^CXX$" OR "${_cppcheck_lang}" MATCHES "^C$")
             list(APPEND _files "${_cppcheck_loc}")
             message(STATUS "[CppCheck] append file: ${_cppcheck_lang}|${_cppcheck_loc}")
         endif()
     endforeach()
 
+    set(cppcheck_includes_arg)
+    foreach(dir ${_cppcheck_includes})
+        if(NOT cppcheck_includes_arg)
+            set(cppcheck_includes_arg "-I ${dir}")
+        else()
+            set(cppcheck_includes_arg "${cppcheck_includes_arg} -I ${dir}")
+        endif()
+    endforeach()
+    message(STATUS "[CppCheck] cppcheck_includes_arg:${cppcheck_includes_arg}")
+
     if (CPPCHECK_MODULE_DIRECTORY_STRUCTURE)
         set(cppcheck_target ${_module_cppcheck_tgt}-${_target_name})
         set(cppcheck_report_file ${CPPCHECK_REPORT_DIR}/${_module_name}-${_target_name})
@@ -229,9 +240,9 @@ function(add_cppcheck _target_name)
     endif()
 
     if(MSVC)
-        set(COMMAND_SCRPIT ${CMAKE_SOURCE_DIR}/cmake/scripts/cppcheck-wrapper/win.bat)
+        set(COMMAND_SCRPIT ${CMAKE_SOURCE_DIR}/addin/cmake/scripts/cppcheck-wrapper/win.bat)
     else()
-        set(COMMAND_SCRPIT ${CMAKE_SOURCE_DIR}/cmake/scripts/cppcheck-wrapper/uos.sh)
+        set(COMMAND_SCRPIT ${CMAKE_SOURCE_DIR}/addin/cmake/scripts/cppcheck-wrapper/uos.sh)
     endif(MSVC)
 
     add_custom_target(
@@ -239,10 +250,7 @@ function(add_cppcheck _target_name)
         COMMAND
         ${COMMAND_SCRPIT}
         ${CPPCHECK_EXECUTABLE}
-        ${_cppcheck_check_config}
         "${_cppcheck_includes}"
-        "${CPPCHECK_EXCLUDED_HEADERS}"
-        ${cppcheck_report_file}
         ${CPPCHECK_QUIET_ARG}
         ${CPPCHECK_TEMPLATE_ARG}
         ${_cppcheck_args}
@@ -250,13 +258,14 @@ function(add_cppcheck _target_name)
         WORKING_DIRECTORY
         "${CMAKE_CURRENT_SOURCE_DIR}"
         COMMENT
-        "${cppcheck_target}: Running cppcheck on target ${_target_name}..."
-        VERBATIM)
+        "[CppCheck] ${cppcheck_target}: Running cppcheck on target ${_target_name}..."
+        VERBATIM
+        )
 
 
-    set_target_properties(${cppcheck_target} PROPERTIES FOLDER "Code Analysis")
+    set_target_properties(${cppcheck_target} PROPERTIES FOLDER "CodeAnalysis")
 
-    add_dependencies(analyse-all ${cppcheck_target})
+    add_dependencies(cppcheck_analyse_all ${cppcheck_target})
 
     if (CPPCHECK_MODULE_DIRECTORY_STRUCTURE)
         add_dependencies(${_module_cppcheck_tgt} ${cppcheck_target})

+ 2 - 8
addin/cmake/FindCPPCHECK.cmake

@@ -64,20 +64,14 @@ if(CPPCHECK_EXECUTABLE)
     set(CPPCHECK_INFORMATION_ARG "--enable=information")
     set(CPPCHECK_UNUSEDFUNC_ARG "--enable=unusedFunction")
     set(CPPCHECK_MISSINGINCLUDE_ARG "--enable=missingInclude")
-
-    if(MSVC)
-        set(CPPCHECK_TEMPLATE_ARG --template vs)
-    elseif(CMAKE_COMPILER_IS_GNUCXX)
-        set(CPPCHECK_TEMPLATE_ARG --template gcc)
-    else()
-        set(CPPCHECK_TEMPLATE_ARG --template gcc)
-    endif()
+    set(CPPCHECK_TEMPLATE_ARG "--template='{file}|{line}|{severity}|{id}|{message}'")
 
     set(CPPCHECK_QUIET_ARG "--quiet")
     set(CPPCHECK_INCLUDEPATH_ARG "-I")
 
 endif(CPPCHECK_EXECUTABLE)
 
+#just test
 set(CPPCHECK_ALL
     "${CPPCHECK_EXECUTABLE} ${CPPCHECK_ENABLEALL_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
 

+ 40 - 4
addin/cmake/scripts/cppcheck-wrapper/win.bat

@@ -1,7 +1,43 @@
 @setlocal enabledelayedexpansion
 @echo off
 
-echo 第一个参数: %1
-echo 第二个参数: %2
-echo 第三个参数: %3
-echo 所有参数: %*
+:: Wrapper script for the CppcheckTargets CMake module
+::
+:: This wrapper script is required because the targets' property
+:: INCLUDE_DIRECTORIES is a list that can contain generators that refer
+:: to even more lists of include directories when evaluated.
+::
+:: We need the generators evaluated to be able to build the cppcheck
+:: command line for the include directories.
+::
+:: For convenience, this wrapper script also runs a tool to post-process
+:: the cppcheck results.
+
+set cppcheck_exec=%1
+shift
+::set check_config=%1
+::shift
+set includes=%1
+shift
+::set header_exclusions=%1
+::shift
+::set report_file=%1
+::shift
+
+echo cppcheck_exec: %cppcheck_exec%
+::echo check_config: %check_config%
+echo includes: %includes%
+::echo header_exclusions: %header_exclusions%
+::echo report_file: %report_file%
+
+set parsed_includes=
+for %%i in ("%includes%") do (
+	echo %%i
+	set str=%%i
+	set str=!str:"=!
+	echo "=============="
+	set parsed_includes=!parsed_includes! -I !str!
+)
+echo parsed_includes: %parsed_includes%
+
+%cppcheck_exec% %parsed_includes% %*