1 # Copyright (C) 2018-2019 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
7 find_package(PythonInterp 2.7 EXACT)
9 if(NOT PYTHONINTERP_FOUND)
10 message(WARNING "Python was not found (required for cpplint check)")
11 set(ENABLE_CPPLINT OFF)
16 add_custom_target(cpplint_all ALL)
17 set(CPPLINT_ALL_OUTPUT_FILES "" CACHE INTERNAL "All cpplint output files")
20 function(add_cpplint_target TARGET_NAME)
21 if(NOT ENABLE_CPPLINT)
27 set(multiValueArgs "FOR_TARGETS" "FOR_SOURCES" "EXCLUDE_PATTERNS")
28 cmake_parse_arguments(CPPLINT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
30 foreach(target IN LISTS CPPLINT_FOR_TARGETS)
31 get_target_property(target_sources "${target}" SOURCES)
32 list(APPEND CPPLINT_FOR_SOURCES ${target_sources})
34 list(REMOVE_DUPLICATES CPPLINT_FOR_SOURCES)
36 set(all_output_files "")
37 foreach(source_file IN LISTS CPPLINT_FOR_SOURCES)
39 foreach(pattern IN LISTS CPPLINT_EXCLUDE_PATTERNS)
40 if(source_file MATCHES "${pattern}")
50 file(RELATIVE_PATH source_file_relative "${CMAKE_CURRENT_SOURCE_DIR}" "${source_file}")
51 set(output_file "${CMAKE_CURRENT_BINARY_DIR}/cpplint/${source_file_relative}.cpplint")
52 string(REPLACE ".." "__" output_file "${output_file}")
53 get_filename_component(output_dir "${output_file}" DIRECTORY)
54 file(MAKE_DIRECTORY "${output_dir}")
61 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
62 -D "CPPLINT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cpplint.py"
63 -D "INPUT_FILE=${source_file}"
64 -D "OUTPUT_FILE=${output_file}"
65 -D "WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
66 -D "SKIP_RETURN_CODE=${ENABLE_CPPLINT_REPORT}"
67 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_run.cmake"
70 "${IE_MAIN_SOURCE_DIR}/scripts/cpplint.py"
71 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_run.cmake"
73 "[cpplint] ${source_file}"
76 list(APPEND all_output_files "${output_file}")
79 set(CPPLINT_ALL_OUTPUT_FILES
80 ${CPPLINT_ALL_OUTPUT_FILES} ${all_output_files}
82 "All cpplint output files")
84 add_custom_target(${TARGET_NAME} ALL
85 DEPENDS ${all_output_files}
86 COMMENT "[cpplint] ${TARGET_NAME}")
88 if(CPPLINT_FOR_TARGETS)
89 foreach(target IN LISTS CPPLINT_FOR_TARGETS)
90 add_dependencies(${target} ${TARGET_NAME})
94 add_dependencies(cpplint_all ${TARGET_NAME})
97 function(add_cpplint_report_target)
98 if(NOT ENABLE_CPPLINT OR NOT ENABLE_CPPLINT_REPORT)
102 set(cpplint_output_file "${CMAKE_BINARY_DIR}/cpplint/final_output.cpplint")
105 "${cpplint_output_file}"
108 -D "FINAL_OUTPUT_FILE=${cpplint_output_file}"
109 -D "OUTPUT_FILES=${CPPLINT_ALL_OUTPUT_FILES}"
110 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_merge.cmake"
112 ${CPPLINT_ALL_OUTPUT_FILES}
113 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_merge.cmake"
115 "[cpplint] Merge all output files"
118 set(cppcheck_output_file "${CMAKE_BINARY_DIR}/cpplint/cpplint-cppcheck-result.xml")
121 "${cppcheck_output_file}"
124 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
125 -D "CONVERT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cpplint_to_cppcheckxml.py"
126 -D "INPUT_FILE=${cpplint_output_file}"
127 -D "OUTPUT_FILE=${cppcheck_output_file}"
128 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_to_cppcheck_xml.cmake"
130 ${cpplint_output_file}
131 "${IE_MAIN_SOURCE_DIR}/scripts/cpplint_to_cppcheckxml.py"
132 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_to_cppcheck_xml.cmake"
134 "[cpplint] Convert to cppcheck XML format"
137 set(report_dir "${IE_MAIN_SOURCE_DIR}/report/cpplint")
138 set(html_output_file "${report_dir}/index.html")
141 "${html_output_file}"
144 -D "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
145 -D "CONVERT_SCRIPT=${IE_MAIN_SOURCE_DIR}/scripts/cppcheck-htmlreport.py"
146 -D "INPUT_FILE=${cppcheck_output_file}"
147 -D "REPORT_DIR=${report_dir}"
148 -D "SOURCE_DIR=${IE_MAIN_SOURCE_DIR}"
149 -D "TITLE=${CMAKE_PROJECT_NAME}"
150 -P "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_html.cmake"
152 "${cppcheck_output_file}"
153 "${IE_MAIN_SOURCE_DIR}/scripts/cppcheck-htmlreport.py"
154 "${IE_MAIN_SOURCE_DIR}/cmake/cpplint_html.cmake"
156 "[cpplint] Generate HTML report"
159 add_custom_target(cpplint_report
160 DEPENDS "${html_output_file}"
161 COMMENT "[cpplint] Generate report")