2023-01-16 01:02:17 -06:00
|
|
|
# Copyright (C) 2018-2023 Intel Corporation
|
2019-04-12 10:25:53 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
|
|
|
|
if(ENABLE_CPPLINT)
|
2023-09-26 13:57:29 -05:00
|
|
|
find_host_package(Python3 QUIET COMPONENTS Interpreter)
|
2019-04-12 10:25:53 -05:00
|
|
|
|
2023-09-26 13:57:29 -05:00
|
|
|
if(NOT Python3_Interpreter_FOUND)
|
2020-05-13 13:12:22 -05:00
|
|
|
message(WARNING "Python3 interpreter was not found (required for cpplint check)")
|
2019-04-12 10:25:53 -05:00
|
|
|
set(ENABLE_CPPLINT OFF)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-06-03 04:45:12 -05:00
|
|
|
if(ENABLE_CPPLINT AND NOT TARGET cpplint_all)
|
2019-04-12 10:25:53 -05:00
|
|
|
add_custom_target(cpplint_all ALL)
|
2020-04-27 13:21:29 -05:00
|
|
|
set_target_properties(cpplint_all PROPERTIES FOLDER cpplint)
|
2019-04-12 10:25:53 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
function(add_cpplint_target TARGET_NAME)
|
|
|
|
if(NOT ENABLE_CPPLINT)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(options "")
|
|
|
|
set(oneValueArgs "")
|
2020-04-13 13:17:23 -05:00
|
|
|
set(multiValueArgs FOR_TARGETS FOR_SOURCES EXCLUDE_PATTERNS CUSTOM_FILTERS)
|
2019-04-12 10:25:53 -05:00
|
|
|
cmake_parse_arguments(CPPLINT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
|
|
|
foreach(target IN LISTS CPPLINT_FOR_TARGETS)
|
|
|
|
get_target_property(target_sources "${target}" SOURCES)
|
|
|
|
list(APPEND CPPLINT_FOR_SOURCES ${target_sources})
|
|
|
|
endforeach()
|
|
|
|
list(REMOVE_DUPLICATES CPPLINT_FOR_SOURCES)
|
|
|
|
|
2020-04-13 13:17:23 -05:00
|
|
|
set(custom_filter "")
|
|
|
|
foreach(filter IN LISTS CPPLINT_CUSTOM_FILTERS)
|
|
|
|
string(CONCAT custom_filter "${custom_filter}" "," "${filter}")
|
|
|
|
endforeach()
|
|
|
|
|
2019-04-12 10:25:53 -05:00
|
|
|
set(all_output_files "")
|
|
|
|
foreach(source_file IN LISTS CPPLINT_FOR_SOURCES)
|
|
|
|
set(exclude FALSE)
|
|
|
|
foreach(pattern IN LISTS CPPLINT_EXCLUDE_PATTERNS)
|
|
|
|
if(source_file MATCHES "${pattern}")
|
2020-02-11 13:48:49 -06:00
|
|
|
set(exclude ON)
|
2019-04-12 10:25:53 -05:00
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(exclude)
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
2020-02-11 13:48:49 -06:00
|
|
|
# ignore object libraries
|
|
|
|
if(NOT EXISTS "${source_file}")
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
2019-04-12 10:25:53 -05:00
|
|
|
file(RELATIVE_PATH source_file_relative "${CMAKE_CURRENT_SOURCE_DIR}" "${source_file}")
|
2023-10-01 14:23:06 -05:00
|
|
|
file(RELATIVE_PATH source_file_relative_root "${CMAKE_SOURCE_DIR}" "${source_file}")
|
2019-04-12 10:25:53 -05:00
|
|
|
set(output_file "${CMAKE_CURRENT_BINARY_DIR}/cpplint/${source_file_relative}.cpplint")
|
|
|
|
string(REPLACE ".." "__" output_file "${output_file}")
|
|
|
|
get_filename_component(output_dir "${output_file}" DIRECTORY)
|
|
|
|
file(MAKE_DIRECTORY "${output_dir}")
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT
|
|
|
|
"${output_file}"
|
|
|
|
COMMAND
|
|
|
|
"${CMAKE_COMMAND}"
|
2023-09-26 13:57:29 -05:00
|
|
|
-D "Python3_EXECUTABLE=${Python3_EXECUTABLE}"
|
2023-10-09 13:30:32 -05:00
|
|
|
-D "CPPLINT_SCRIPT=${OpenVINODeveloperScripts_DIR}/cpplint/cpplint.py"
|
2019-04-12 10:25:53 -05:00
|
|
|
-D "INPUT_FILE=${source_file}"
|
|
|
|
-D "OUTPUT_FILE=${output_file}"
|
|
|
|
-D "WORKING_DIRECTORY=${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
-D "SKIP_RETURN_CODE=${ENABLE_CPPLINT_REPORT}"
|
2020-04-13 13:17:23 -05:00
|
|
|
-D "CUSTOM_FILTER=${custom_filter}"
|
2023-10-09 13:30:32 -05:00
|
|
|
-P "${OpenVINODeveloperScripts_DIR}/cpplint/cpplint_run.cmake"
|
2019-04-12 10:25:53 -05:00
|
|
|
DEPENDS
|
|
|
|
"${source_file}"
|
2023-10-09 13:30:32 -05:00
|
|
|
"${OpenVINODeveloperScripts_DIR}/cpplint/cpplint.py"
|
|
|
|
"${OpenVINODeveloperScripts_DIR}/cpplint/cpplint_run.cmake"
|
2019-04-12 10:25:53 -05:00
|
|
|
COMMENT
|
2023-10-01 14:23:06 -05:00
|
|
|
"[cpplint] ${source_file_relative_root}"
|
2019-04-12 10:25:53 -05:00
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
list(APPEND all_output_files "${output_file}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_target(${TARGET_NAME} ALL
|
|
|
|
DEPENDS ${all_output_files}
|
|
|
|
COMMENT "[cpplint] ${TARGET_NAME}")
|
2020-04-27 13:21:29 -05:00
|
|
|
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER cpplint)
|
2019-04-12 10:25:53 -05:00
|
|
|
|
|
|
|
if(CPPLINT_FOR_TARGETS)
|
|
|
|
foreach(target IN LISTS CPPLINT_FOR_TARGETS)
|
|
|
|
add_dependencies(${target} ${TARGET_NAME})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_dependencies(cpplint_all ${TARGET_NAME})
|
|
|
|
endfunction()
|