2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2013,2014, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 find_program(CPPCHECK_EXECUTABLE
37 DOC "cppcheck executable")
38 mark_as_advanced(CPPCHECK_EXECUTABLE)
39 option(CPPCHECK_XML_OUTPUT "Whether to produce XML output from cppcheck (mainly for Jenkins)"
41 mark_as_advanced(CPPCHECK_XML_OUTPUT)
43 # Depends on stderr redirection and cat
44 if (CPPCHECK_EXECUTABLE AND UNIX)
45 # Produce the list of files to check
46 file(GLOB_RECURSE _inputfiles RELATIVE ${CMAKE_SOURCE_DIR}
47 ${CMAKE_SOURCE_DIR}/src/*.c
48 ${CMAKE_SOURCE_DIR}/src/*.cpp
49 ${CMAKE_SOURCE_DIR}/src/*.cu)
50 file(GLOB_RECURSE _files_to_ignore RELATIVE ${CMAKE_SOURCE_DIR}
51 ${CMAKE_SOURCE_DIR}/src/nb_kernel_Elec*.c
52 ${CMAKE_SOURCE_DIR}/src/gromacs/linearalgebra/gmx_blas/*.c
53 ${CMAKE_SOURCE_DIR}/src/gromacs/linearalgebra/gmx_lapack/*.c
54 ${CMAKE_SOURCE_DIR}/src/contrib/*.c
55 ${CMAKE_SOURCE_DIR}/src/contrib/*.cpp
56 ${CMAKE_SOURCE_DIR}/src/contrib/*.cu
57 ${CMAKE_SOURCE_DIR}/src/external/*.c
58 ${CMAKE_SOURCE_DIR}/src/external/*.cpp
59 ${CMAKE_SOURCE_DIR}/src/external/*.cu
61 list(REMOVE_ITEM _inputfiles ${_files_to_ignore})
63 # Set flags for cppcheck
65 set(_outputopt --template=gcc)
66 if (CPPCHECK_XML_OUTPUT)
71 --enable=style -DLINUX
72 -I src/gromacs/legacyheaders -I src
73 -I src/external/thread_mpi/include
74 -I src/external/tng_io/include
75 -I ${CMAKE_BINARY_DIR}/src -I ${CMAKE_BINARY_DIR}/src/gromacs/utility
79 --suppress=variableScope
80 --suppress=unnecessaryForwardDeclaration
81 --suppress=unusedVariable
82 --suppress=unreadVariable
83 --suppress=unusedStructMember
84 --suppress=invalidscanf
85 --suppress=sizeofCalculation
86 --suppress=missingInclude:src/programs/mdrun/gmx_gpu_utils/gmx_gpu_utils.cu
87 --suppress=*:src/external/Random123-1.08/include/Random123/features/compilerfeatures.h
91 --suppress=variableScope
92 --suppress=unnecessaryForwardDeclaration
93 --suppress=invalidscanf:src/gromacs/fileio/matio.cpp
94 --suppress=invalidscanf:src/gromacs/gmxlib/xvgr.cpp
95 --suppress=invalidscanf:src/gromacs/gmxpreprocess/pdb2top.cpp
96 --suppress=*:src/gromacs/selection/scanner.cpp)
98 # This list will hold the list of all files with cppcheck errors
99 # (one per input file)
102 foreach (_filename ${_inputfiles})
103 set(_target_name cppcheck-${_filename}.${_outputext})
104 string(REPLACE "/" "_" _target_name ${_target_name})
105 list(APPEND _filelist ${_target_name})
106 if (_filename MATCHES "\\.cpp$")
108 set(_lang_flags ${_cxx_flags})
111 set(_lang_flags ${_c_flags})
114 OUTPUT ${_target_name}
115 COMMAND ${CPPCHECK_EXECUTABLE} ${_common_flags} ${_lang_flags}
116 ${_filename} 2> ${CMAKE_CURRENT_BINARY_DIR}/${_target_name}
117 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
118 IMPLICIT_DEPENDS ${_lang} ${CMAKE_SOURCE_DIR}/${_filename}
119 COMMENT "Running cppcheck for ${_filename}"
121 if (NOT CPPCHECK_XML_OUTPUT)
123 OUTPUT ${_target_name}
124 COMMAND cat ${CMAKE_CURRENT_BINARY_DIR}/${_target_name}
128 if (NOT CPPCHECK_XML_OUTPUT)
129 set(_target_name cppcheck-errors.${_outputext})
131 OUTPUT ${_target_name}
132 COMMAND cat ${_filelist} > ${_target_name}
134 COMMENT "Combining cppcheck results"
136 list(APPEND _filelist ${_target_name})
138 add_custom_target(cppcheck DEPENDS ${_filelist})
140 add_custom_target(cppcheck
141 COMMAND ${CMAKE_COMMAND} -E echo
142 "cppcheck was not found by CMake. Rerun CMake specifying CPPCHECK_EXECUTABLE."