if ( COMMAND ocv_pylint_add_target )
return ( )
endif ( )
find_package ( Pylint QUIET )
if ( NOT PYLINT_FOUND OR NOT PYLINT_EXECUTABLE )
include ( "${CMAKE_CURRENT_LIST_DIR}/FindPylint.cmake" )
endif ( )
if ( NOT PYLINT_FOUND )
macro ( ocv_pylint_add_target ) # dummy
endmacro ( )
return ( )
endif ( )
macro ( ocv_pylint_cleanup )
foreach ( __id ${ PYLINT_TARGET_ID } )
ocv_clear_vars (
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ C W D
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ T A R G E T
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ R C F I L E
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ O P T I O N S
)
endforeach ( )
ocv_clear_vars ( PYLINT_TARGET_ID )
endmacro ( )
ocv_pylint_cleanup ( )
macro ( ocv_pylint_add_target )
cmake_parse_arguments ( __pylint "" "CWD;TARGET;RCFILE;" "OPTIONS" ${ ARGN } )
if ( __pylint_UNPARSED_ARGUMENTS )
message ( WARNING " Unsupported arguments: ${ __pylint_UNPARSED_ARGUMENTS }
( k e e p v e r s i o n s o f o p e n c v / o p e n c v _ c o n t r i b s y n c h r o n i z e d )
" )
endif ( )
ocv_assert ( __pylint_TARGET )
set ( __cwd ${ __pylint_CWD } )
if ( __cwd STREQUAL "default" )
get_filename_component ( __cwd "${__pylint_TARGET}" DIRECTORY )
endif ( )
set ( __rcfile ${ __pylint_RCFILE } )
if ( NOT __rcfile AND NOT __pylint_OPTIONS )
if ( __cwd )
set ( __path "${__cwd}" )
else ( )
get_filename_component ( __path "${__pylint_TARGET}" DIRECTORY )
endif ( )
while ( __path MATCHES "^${CMAKE_SOURCE_DIR}" )
if ( EXISTS "${__path}/pylintrc" )
set ( __rcfile "${__path}/pylintrc" )
break ( )
endif ( )
if ( EXISTS "${__path}/.pylintrc" )
set ( __rcfile "${__path}/.pylintrc" )
break ( )
endif ( )
get_filename_component ( __path "${__path}" DIRECTORY )
endwhile ( )
if ( NOT __rcfile )
set ( __rcfile "${CMAKE_BINARY_DIR}/pylintrc" )
endif ( )
endif ( )
list ( LENGTH PYLINT_TARGET_ID __id )
list ( APPEND PYLINT_TARGET_ID ${ __id } )
set ( PYLINT_TARGET_ID "${PYLINT_TARGET_ID}" CACHE INTERNAL "" )
set ( PYLINT_TARGET_ ${ __id } _CWD "${__cwd}" CACHE INTERNAL "" )
set ( PYLINT_TARGET_ ${ __id } _TARGET "${__pylint_TARGET}" CACHE INTERNAL "" )
set ( PYLINT_TARGET_ ${ __id } _RCFILE "${__rcfile}" CACHE INTERNAL "" )
set ( PYLINT_TARGET_ ${ __id } _OPTIONS "${__pylint_options}" CACHE INTERNAL "" )
endmacro ( )
macro ( ocv_pylint_add_directory_recurse __path )
file ( GLOB_RECURSE __python_scripts ${ __path } /*.py )
list ( LENGTH __python_scripts __total )
if ( __total EQUAL 0 )
message ( WARNING "Pylint: Python files are not found: ${__path}" )
endif ( )
foreach ( __script ${ __python_scripts } )
ocv_pylint_add_target ( TARGET ${ __script } ${ ARGN } )
endforeach ( )
endmacro ( )
macro ( ocv_pylint_add_directory __path )
file ( GLOB __python_scripts ${ __path } /*.py )
list ( LENGTH __python_scripts __total )
if ( __total EQUAL 0 )
message ( WARNING "Pylint: Python files are not found: ${__path}" )
endif ( )
foreach ( __script ${ __python_scripts } )
ocv_pylint_add_target ( TARGET ${ __script } ${ ARGN } )
endforeach ( )
endmacro ( )
function ( ocv_pylint_finalize )
if ( NOT PYLINT_FOUND )
return ( )
endif ( )
add_custom_command (
O U T P U T " $ { C M A K E _ B I N A R Y _ D I R } / p y l i n t r c "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t " $ { C M A K E _ S O U R C E _ D I R } / p l a t f o r m s / s c r i p t s / p y l i n t r c " " $ { C M A K E _ B I N A R Y _ D I R } / p y l i n t r c "
D E P E N D S " $ { C M A K E _ S O U R C E _ D I R } / p l a t f o r m s / s c r i p t s / p y l i n t r c "
)
set ( PYLINT_CONFIG_SCRIPT "" )
ocv_cmake_script_append_var ( PYLINT_CONFIG_SCRIPT
P Y L I N T _ E X E C U T A B L E
P Y L I N T _ T A R G E T _ I D
)
set ( __sources "" )
foreach ( __id ${ PYLINT_TARGET_ID } )
ocv_cmake_script_append_var ( PYLINT_CONFIG_SCRIPT
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ C W D
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ T A R G E T
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ R C F I L E
P Y L I N T _ T A R G E T _ $ { _ _ i d } _ O P T I O N S
)
list ( APPEND __sources ${ PYLINT_TARGET_${__id } _TARGET} ${ PYLINT_TARGET_${__id } _RCFILE} )
endforeach ( )
list ( REMOVE_DUPLICATES __sources )
list ( LENGTH PYLINT_TARGET_ID __total )
set ( PYLINT_TOTAL_TARGETS "${__total}" CACHE INTERNAL "" )
message ( STATUS "Pylint: registered ${__total} targets. Build 'check_pylint' target to run checks (\" cmake --build . --target check_pylint\ " or \" make check_pylint\ ")" )
configure_file ( "${OpenCV_SOURCE_DIR}/cmake/templates/pylint.cmake.in" "${CMAKE_BINARY_DIR}/pylint.cmake" @ONLY )
add_custom_target ( check_pylint
C O M M A N D $ { C M A K E _ C O M M A N D } - P " $ { C M A K E _ B I N A R Y _ D I R } / p y l i n t . c m a k e "
C O M M E N T " R u n n i n g p y l i n t "
D E P E N D S $ { _ _ s o u r c e s }
S O U R C E S $ { _ _ s o u r c e s }
)
endfunction ( )