1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
6 find_package(PythonInterp 2.7 EXACT)
8 if(NOT PYTHONINTERP_FOUND OR NOT PYTHON_VERSION_MAJOR EQUAL 2)
9 message(WARNING "Python 2.7 was not found (required for cpplint check)")
10 set(ENABLE_CPPLINT OFF)
15 add_custom_target(cpplint_all ALL)
16 set(CPPLINT_ALL_OUTPUT_FILES "" CACHE INTERNAL "All cpplint output files")
19 function(add_cpplint_target TARGET_NAME)
20 if(NOT ENABLE_CPPLINT)
26 set(multiValueArgs "FOR_TARGETS" "FOR_SOURCES" "EXCLUDE_PATTERNS")
27 cmake_parse_arguments(CPPLINT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
29 foreach(target IN LISTS CPPLINT_FOR_TARGETS)
30 get_target_property(target_sources "${target}" SOURCES)
31 list(APPEND CPPLINT_FOR_SOURCES ${target_sources})
33 list(REMOVE_DUPLICATES CPPLINT_FOR_SOURCES)
35 set(all_output_files "")
36 foreach(source_file IN LISTS CPPLINT_FOR_SOURCES)
38 foreach(pattern IN LISTS CPPLINT_EXCLUDE_PATTERNS)
39 if(source_file MATCHES "${pattern}")
49 # ignore object libraries
50 if(NOT EXISTS "${source_file}")
54 file(RELATIVE_PATH source_file_relative "${CMAKE_CURRENT_SOURCE_DIR}" "${source_file}")
55 set(output_file "${CMAKE_CURRENT_BINARY_DIR}/cpplint/${source_file_relative}.cpplint")
56 string(REPLACE ".." "__" output_file "${output_file}")
57 get_filename_component(output_dir "${output_file}" DIRECTORY)
58 file(MAKE_DIRECTORY "${output_dir}")
65 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
66 -D "CPPLINT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cpplint.py"
67 -D "INPUT_FILE=${source_file}"
68 -D "OUTPUT_FILE=${output_file}"
69 -D "WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
70 -D "SKIP_RETURN_CODE=${ENABLE_CPPLINT_REPORT}"
71 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_run.cmake"
74 "${IE_MAIN_SOURCE_DIR}/scripts/cpplint.py"
75 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_run.cmake"
77 "[cpplint] ${source_file}"
80 list(APPEND all_output_files "${output_file}")
83 set(CPPLINT_ALL_OUTPUT_FILES
84 ${CPPLINT_ALL_OUTPUT_FILES} ${all_output_files}
86 "All cpplint output files")
88 add_custom_target(${TARGET_NAME} ALL
89 DEPENDS ${all_output_files}
90 COMMENT "[cpplint] ${TARGET_NAME}")
92 if(CPPLINT_FOR_TARGETS)
93 foreach(target IN LISTS CPPLINT_FOR_TARGETS)
94 add_dependencies(${target} ${TARGET_NAME})
98 add_dependencies(cpplint_all ${TARGET_NAME})
101 function(add_cpplint_report_target)
102 if(NOT ENABLE_CPPLINT OR NOT ENABLE_CPPLINT_REPORT)
106 set(cpplint_output_file "${CMAKE_BINARY_DIR}/cpplint/final_output.cpplint")
109 "${cpplint_output_file}"
112 -D "FINAL_OUTPUT_FILE=${cpplint_output_file}"
113 -D "OUTPUT_FILES=${CPPLINT_ALL_OUTPUT_FILES}"
114 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_merge.cmake"
116 ${CPPLINT_ALL_OUTPUT_FILES}
117 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_merge.cmake"
119 "[cpplint] Merge all output files"
122 set(cppcheck_output_file "${CMAKE_BINARY_DIR}/cpplint/cpplint-cppcheck-result.xml")
125 "${cppcheck_output_file}"
128 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
129 -D "CONVERT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cpplint_to_cppcheckxml.py"
130 -D "INPUT_FILE=${cpplint_output_file}"
131 -D "OUTPUT_FILE=${cppcheck_output_file}"
132 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_to_cppcheck_xml.cmake"
134 "${cpplint_output_file}"
135 "${IE_MAIN_SOURCE_DIR}/scripts/cpplint_to_cppcheckxml.py"
136 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_to_cppcheck_xml.cmake"
138 "[cpplint] Convert to cppcheck XML format"
141 set(report_dir "${IE_MAIN_SOURCE_DIR}/report/cpplint")
142 set(html_output_file "${report_dir}/index.html")
145 "${html_output_file}"
148 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
149 -D "CONVERT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cppcheck-htmlreport.py"
150 -D "INPUT_FILE=${cppcheck_output_file}"
151 -D "REPORT_DIR=${report_dir}"
152 -D "SOURCE_DIR=${IE_MAIN_SOURCE_DIR}"
153 -D "TITLE=${CMAKE_PROJECT_NAME}"
154 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_html.cmake"
156 "${cppcheck_output_file}"
157 "${IE_MAIN_SOURCE_DIR}/scripts/cppcheck-htmlreport.py"
158 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_html.cmake"
160 "[cpplint] Generate HTML report"
163 add_custom_target(cpplint_report
164 DEPENDS "${html_output_file}"
165 COMMENT "[cpplint] Generate report")