1
+ # Copyright (C) 2013 Daniel Scharrer
2
+ #
3
+ # This software is provided 'as-is', without any express or implied
4
+ # warranty. In no event will the author(s) be held liable for any damages
5
+ # arising from the use of this software.
6
+ #
7
+ # Permission is granted to anyone to use this software for any purpose,
8
+ # including commercial applications, and to alter it and redistribute it
9
+ # freely, subject to the following restrictions:
10
+ #
11
+ # 1. The origin of this software must not be misrepresented; you must not
12
+ # claim that you wrote the original software. If you use this software
13
+ # in a product, an acknowledgment in the product documentation would be
14
+ # appreciated but is not required.
15
+ # 2. Altered source versions must be plainly marked as such, and must not be
16
+ # misrepresented as being the original software.
17
+ # 3. This notice may not be removed or altered from any source distribution.
18
+
19
+
20
+ # Copyright (C) 2014 Greg Horn
21
+ # In order to comply with the above copyright, I am noting that I took
22
+ # Daniel's script and hacked it a bit, mostly changing paths and filters
23
+
24
+ find_package (PythonInterp 2.7 REQUIRED)
25
+
26
+ set (STYLE_FILTER)
27
+
28
+ # disable unwanted filters
29
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/braces,)
30
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/semicolon,)
31
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/blank_line,)
32
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/comma,)
33
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/operators,)
34
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/parens,)
35
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/indent,)
36
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/comments,)
37
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/newline,)
38
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/tab,)
39
+ set (STYLE_FILTER ${STYLE_FILTER} -whitespace/ending_newline,)
40
+
41
+ set (STYLE_FILTER ${STYLE_FILTER} -build /include_order,)
42
+ set (STYLE_FILTER ${STYLE_FILTER} -build /namespaces,)
43
+ set (STYLE_FILTER ${STYLE_FILTER} -build /include_what_you_use,)
44
+ set (STYLE_FILTER ${STYLE_FILTER} -build /include ,)
45
+
46
+ set (STYLE_FILTER ${STYLE_FILTER} -readability/streams,)
47
+ set (STYLE_FILTER ${STYLE_FILTER} -readability/todo,)
48
+
49
+ set (STYLE_FILTER ${STYLE_FILTER} -runtime/references,)
50
+ set (STYLE_FILTER ${STYLE_FILTER} -runtime/int,)
51
+ set (STYLE_FILTER ${STYLE_FILTER} -runtime/explicit,)
52
+ set (STYLE_FILTER ${STYLE_FILTER} -runtime/printf,)
53
+
54
+ set (STYLE_FILTER ${STYLE_FILTER} -legal/copyright)
55
+
56
+ function (add_style_check_target TARGET_NAME SOURCES_LIST)
57
+
58
+ if (NOT PYTHONINTERP_FOUND)
59
+ message (FATAL_ERROR "python not found!" )
60
+ endif ()
61
+
62
+ find_file (GOOGLE_CPP_LINT_PY NAMES cpplint.py PATHS ${CMAKE_SOURCE_DIR} DOC "google cpp style scan program." )
63
+ # if (NOT EXISTS ${CMAKE_SOURCE_DIR}/cmake/cpplint.py)
64
+ # message (FATAL_ERROR "${CMAKE_SOURCE_DIR}/cmake/cpplint.py not found!")
65
+ # endif()
66
+
67
+ list (REMOVE_DUPLICATES SOURCES_LIST)
68
+ list (SORT SOURCES_LIST)
69
+
70
+ add_custom_target (${TARGET_NAME} ALL
71
+ COMMAND "${CMAKE_COMMAND} " -E chdir
72
+ "${CMAKE_CURRENT_SOURCE_DIR} "
73
+ "${PYTHON_EXECUTABLE} "
74
+ "${CMAKE_SOURCE_DIR} /cpplint.py"
75
+ "--filter=${STYLE_FILTER} "
76
+ "--counting=detailed"
77
+ "--extensions=cpp,hpp,h"
78
+ "--linelength=250"
79
+ ${SOURCES_LIST}
80
+ DEPENDS ${SOURCES_LIST}
81
+ COMMENT "Linting ${TARGET_NAME} "
82
+ VERBATIM )
83
+
84
+ endfunction ()
0 commit comments