/
CppLint.cmake
101 lines (84 loc) · 3.34 KB
/
CppLint.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright (C) 2013 Daniel Scharrer
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the author(s) be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
# Copyright (C) 2014 Greg Horn
# In order to comply with the above copyright, I am noting that I took
# Daniel's script and hacked it a bit, mostly changing paths and filters
find_package(PythonInterp)
set(STYLE_FILTER)
# disable unwanted filters
set(STYLE_FILTER ${STYLE_FILTER}-whitespace/semicolon,)
set(STYLE_FILTER ${STYLE_FILTER}-whitespace/blank_line,)
set(STYLE_FILTER ${STYLE_FILTER}-whitespace/operators,)
set(STYLE_FILTER ${STYLE_FILTER}-whitespace/indent,)
set(STYLE_FILTER ${STYLE_FILTER}-whitespace/comments,)
set(STYLE_FILTER ${STYLE_FILTER}-build/include_order,)
set(STYLE_FILTER ${STYLE_FILTER}-build/namespaces,)
set(STYLE_FILTER ${STYLE_FILTER}-build/include_what_you_use,)
set(STYLE_FILTER ${STYLE_FILTER}-readability/streams,)
set(STYLE_FILTER ${STYLE_FILTER}-runtime/references,)
set(STYLE_FILTER ${STYLE_FILTER}-runtime/int,)
set(STYLE_FILTER ${STYLE_FILTER}-runtime/explicit,)
set(STYLE_FILTER ${STYLE_FILTER}-readability/nolint,)
# THESE SHOW LEGITAMITE WARNINGS WHICH SHOULD BE FIXED:
set(STYLE_FILTER ${STYLE_FILTER}-runtime/printf,)
# Add a target that runs cpplint.py
#
# Parameters:
# - TARGET_NAME the name of the target to add
# - SOURCES_LIST a complete list of source and include files to check
function(add_style_check_target TARGET_NAME SOURCES_LIST0)# PROJECT)
if(NOT PYTHONINTERP_FOUND)
return()
endif()
list(REMOVE_DUPLICATES SOURCES_LIST0)
list(SORT SOURCES_LIST0)
# filtering out unwanted files
set(SOURCES_LIST)
foreach(item ${SOURCES_LIST0})
#string(REGEX MATCH ".*\\.hpp$" dummy ${item})
string(REGEX MATCH ".*_runtime_str\\.h" dummy ${item})
if(NOT dummy)
string(REGEX MATCH ".*meta\\.cpp" dummy ${item})
endif()
if(NOT dummy)
list(APPEND SOURCES_LIST ${item})
endif()
endforeach()
list(LENGTH SOURCES_LIST LISTCOUNT)
if (LISTCOUNT)
add_custom_target(lint_${TARGET_NAME}
COMMAND "${CMAKE_COMMAND}" -E chdir
"${CMAKE_CURRENT_SOURCE_DIR}"
"${PYTHON_EXECUTABLE}"
"${CMAKE_SOURCE_DIR}/misc/cpplint.py"
"--filter=${STYLE_FILTER}"
"--counting=detailed"
"--extensions=cpp,hpp,h"
"--linelength=100"
# "--project=${PROJECT}"
${SOURCES_LIST}
DEPENDS ${SOURCES_LIST}
COMMENT "Linting ${TARGET_NAME}"
VERBATIM)
else()
add_custom_target(lint_${TARGET_NAME}
COMMAND echo "Nothing to do"
COMMENT "Linting ${TARGET_NAME}"
VERBATIM)
endif()
endfunction()