Skip to content

Commit

Permalink
Merge pull request #409 from tribal-tec/master
Browse files Browse the repository at this point in the history
Minor speedup with check targets, fix cpplint target
  • Loading branch information
tribal-tec committed Aug 21, 2015
2 parents 83718a9 + c3c2cbf commit d33b31f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 114 deletions.
24 changes: 19 additions & 5 deletions CommonCheckTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ include(CpplintTargets)

function(common_check_targets _name)
set(_exclude_pattern ".*moc_|.*qrc_.*\\.c.*$") # Qt moc and qrc files
add_clangcheck(${_name} EXCLUDE_PATTERN ${_exclude_pattern})
add_cppcheck(${_name} POSSIBLE_ERROR FAIL_ON_WARNINGS
EXCLUDE_PATTERN ${_exclude_pattern})
add_cpplint(${_name} CATEGORY_FILTER_OUT readability/streams
EXCLUDE_PATTERN ${_exclude_pattern})

# Get the list of files once for all check targets
get_target_property(_sources "${_name}" SOURCES)
set(_files)
foreach(_source ${_sources})
get_source_file_property(_lang "${_source}" LANGUAGE)
get_source_file_property(_loc "${_source}" LOCATION)
if("${_lang}" MATCHES "CXX" AND NOT ${_loc} MATCHES ${_exclude_pattern})
list(APPEND _files "${_loc}")
endif()
endforeach()

if(NOT _files)
return()
endif()

add_clangcheck(${_name} ${_files})
add_cppcheck(${_name} ${_files} POSSIBLE_ERROR FAIL_ON_WARNINGS)
add_cpplint(${_name} ${_files} CATEGORY_FILTER_OUT readability/streams)
endfunction()
4 changes: 2 additions & 2 deletions CommonGraph.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# common_graph(): Write .dot from the global properties and add Name-graph rule

include(CommonTarget)
if(COMMON_TARGET_DONE)
if(COMMON_GRAPH_DONE)
return()
endif()
set(COMMON_TARGET_DONE ON)
set(COMMON_GRAPH_DONE ON)

find_program(DOT_EXECUTABLE dot)
find_program(TRED_EXECUTABLE tred)
Expand Down
42 changes: 7 additions & 35 deletions CppcheckTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# include(CppcheckTargets)
# add_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR]
# [FAIL_ON_WARNINGS] [EXCLUDE_PATTERN]) -
# [FAIL_ON_WARNINGS]) -
# Create a target to check a target's sources with cppcheck and the
# indicated options
#
Expand All @@ -28,11 +28,11 @@ endif()

include(CMakeParseArguments)

if(NOT CPPCHECK_FOUND)
if(NOT CPPCHECK_EXECUTABLE)
find_package(cppcheck 1.66 QUIET)
endif()

if(NOT CPPCHECK_FOUND)
if(NOT CPPCHECK_EXECUTABLE)
add_custom_target(${PROJECT_NAME}-cppcheck
COMMENT "cppcheck executable not found")
set_target_properties(${PROJECT_NAME}-cppcheck PROPERTIES
Expand All @@ -45,19 +45,15 @@ if(NOT TARGET cppcheck)
EXCLUDE_FROM_DEFAULT_BUILD ON)
endif()

function(add_cppcheck _name)
if(NOT TARGET ${_name})
message(FATAL_ERROR
"add_cppcheck given a target name that does not exist: '${_name}' !")
endif()
if(NOT CPPCHECK_FOUND)
function(add_cppcheck _name _files)
if(NOT CPPCHECK_EXECUTABLE)
return()
endif()

if (CPPCHECK_IGNORED_PATHS)
if(CPPCHECK_IGNORED_PATHS)
string(REPLACE " " " -i" _ignored_paths ${CPPCHECK_IGNORED_PATHS})
set(CPPCHECK_IGNORED_PATHS -i${_ignored_paths})
endif(CPPCHECK_IGNORED_PATHS)
endif()

set(_cppcheck_args ${CPPCHECK_IGNORED_PATHS} --error-exitcode=2
--inline-suppr --suppress=unusedFunction --suppress=unmatchedSuppression
Expand Down Expand Up @@ -85,30 +81,6 @@ function(add_cppcheck _name)
${CPPCHECK_WARN_REGULAR_EXPRESSION})
endif()

get_target_property(_imported_target "${_name}" IMPORTED)
if(_imported_target)
return()
endif()

cmake_parse_arguments(add_cppcheck "" "EXCLUDE_PATTERN" "" ${ARGN})
if(NOT add_cppcheck_EXCLUDE_PATTERN)
set(add_cppcheck_EXCLUDE_PATTERN "^$") # Empty string regex
endif()

get_target_property(_cppcheck_sources "${_name}" SOURCES)
set(_files)
foreach(_source ${_cppcheck_sources})
get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
if("${_cppcheck_lang}" MATCHES "CXX" AND NOT ${_cppcheck_loc} MATCHES ${add_cppcheck_EXCLUDE_PATTERN})
list(APPEND _files "${_cppcheck_loc}")
endif()
endforeach()

if(NOT _files) # nothing to check
return()
endif()

add_test(NAME ${_name}-cppcheck
COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_QUIET_ARG}
${CPPCHECK_TEMPLATE_ARG} ${_cppcheck_args} ${_files}
Expand Down
48 changes: 10 additions & 38 deletions CpplintTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# include(CpplintTargets)
# add_cpplint(TARGET target [CATEGORY_FILTER_OUT category ...]
# [EXTENSIONS extension ...] [VERBOSE level]
# [COUNTING level_of_detail] [ROOT subdir] [LINELENGTH digits]
# [EXCLUDE_PATTERN pattern ...])
# [COUNTING level_of_detail] [ROOT subdir] [LINELENGTH digits])
# Create a target to check a target's sources with cpplint and the indicated
# options
#
Expand All @@ -19,7 +18,7 @@ include(CMakeParseArguments)

if(NOT CPPLINT_FOUND)
find_package(cpplint QUIET)
endif(NOT CPPLINT_FOUND)
endif()

if(NOT CPPLINT_FOUND)
add_custom_target(${PROJECT_NAME}-cpplint COMMENT "${CPPLINT_NOT_FOUND_MSG}")
Expand All @@ -33,17 +32,14 @@ if(NOT TARGET cpplint)
EXCLUDE_FROM_DEFAULT_BUILD ON)
endif()

function(add_cpplint _name)
set(oneValueArgs VERBOSE COUNTING ROOT LINELENGTH EXCLUDE_PATTERN)
set(multiValueArgs CATEGORY_FILTER_OUT EXTENSIONS)
cmake_parse_arguments(add_cpplint "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT TARGET ${_name})
message(FATAL_ERROR
"add_cpplint is given a target name that does not exist: '${_name}' !")
endif()
function(add_cpplint _name _files)
if(NOT CPPLINT_FOUND)
return()
endif( )
endif()

set(oneValueArgs VERBOSE COUNTING ROOT LINELENGTH)
set(multiValueArgs CATEGORY_FILTER_OUT EXTENSIONS)
cmake_parse_arguments(add_cpplint "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(_cpplint_args)

Expand All @@ -53,7 +49,7 @@ function(add_cpplint _name)
if (add_cpplint_CATEGORY_FILTER_OUT)
string(REPLACE ";" ",-" add_cpplint_CATEGORY_FILTER_OUT "${add_cpplint_CATEGORY_FILTER_OUT}")
set(_category_filter "--filter=${_category_filter_in},-${add_cpplint_CATEGORY_FILTER_OUT}")
endif(add_cpplint_CATEGORY_FILTER_OUT)
endif()
list(APPEND _cpplint_args ${_category_filter})

# handles allowed extensions
Expand Down Expand Up @@ -83,30 +79,6 @@ function(add_cpplint _name)
list(APPEND _cpplint_args "--linelength=${add_cpplint_LINELENGTH}")
endif()

# handles exclude pattern
if(NOT add_cpplint_EXCLUDE_PATTERN)
set(add_cpplint_EXCLUDE_PATTERN "^$") # Empty string regex
endif()

get_target_property(_imported_target "${_name}" IMPORTED)
if(_imported_target)
return()
endif()

get_target_property(_cpplint_sources "${_name}" SOURCES)
set(_files)
foreach(_source ${_cpplint_sources})
get_source_file_property(_cpplint_lang "${_source}" LANGUAGE)
get_source_file_property(_cpplint_loc "${_source}" LOCATION)
if("${_cpplint_lang}" MATCHES "CXX" AND NOT ${_cpplint_loc} MATCHES ${add_cpplint_EXCLUDE_PATTERN})
list(APPEND _files "${_cpplint_loc}")
endif()
endforeach()

if(NOT _files) # nothing to check
return()
endif(NOT _files)

if(CPPLINT_ADD_TESTS)
if(NOT TARGET ${PROJECT_NAME}-tests)
add_custom_target(${PROJECT_NAME}-tests)
Expand All @@ -129,4 +101,4 @@ function(add_cpplint _name)
endif()
add_dependencies(${PROJECT_NAME}-cpplint cpplint_run_${_name})
add_dependencies(cpplint ${PROJECT_NAME}-cpplint)
endfunction(add_cpplint)
endfunction()
6 changes: 3 additions & 3 deletions Findcpplint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp QUIET)
endif()

if(NOT PYTHON_FOUND)
if(NOT PYTHONLIBS_FOUND)
find_package(PythonLibs QUIET)
endif()

if(PYTHON_EXECUTABLE AND PYTHON_FOUND)
if(PYTHON_EXECUTABLE AND PYTHONLIBS_FOUND)
set(_python_found true)
endif()

Expand Down Expand Up @@ -70,7 +70,7 @@ else(_python_found)
set(CPPLINT_NOT_FOUND_MSG "Could NOT find python needed to run cpplint.py. Please check both executable and libraries are installed.")
endif(_python_found)

find_package_handle_standard_args(cpplint "${CPPLINT_NOT_FOUND_MSG}" PYTHON_EXECUTABLE PYTHON_FOUND CPPLINT_SCRIPT)
find_package_handle_standard_args(cpplint "${CPPLINT_NOT_FOUND_MSG}" PYTHON_EXECUTABLE PYTHONLIBS_FOUND CPPLINT_SCRIPT)

if(CPPLINT_FOUND OR CPPLINT_MARK_AS_ADVANCED)
mark_as_advanced(CPPLINT_ROOT_DIR)
Expand Down
33 changes: 2 additions & 31 deletions clangcheckTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# include(clangcheckTargets)
# add_clangcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR]
# [FAIL_ON_WARNINGS] [EXCLUDE_PATTERN]) -
# [FAIL_ON_WARNINGS]) -
# Create a target to check a target's sources with clang-check and the
# indicated options

Expand All @@ -28,10 +28,7 @@ if(NOT TARGET clangcheck)
add_custom_target(clangcheck)
endif()

function(add_clangcheck _name)
if(NOT TARGET ${_name})
message(FATAL_ERROR "add_clangcheck given non-existing target '${_name}'")
endif()
function(add_clangcheck _name _files)
if(NOT CLANGCHECK)
return()
endif()
Expand All @@ -40,32 +37,6 @@ function(add_clangcheck _name)
-fatal-assembler-warnings -extra-arg=-Qunused-arguments
${CLANGCHECK_EXTRA_ARGS})

get_target_property(_imported_target "${_name}" IMPORTED)
if(_imported_target)
return()
endif()

cmake_parse_arguments(add_clangcheck "" "EXCLUDE_PATTERN" "" ${ARGN})
if(NOT add_clangcheck_EXCLUDE_PATTERN)
set(add_clangcheck_EXCLUDE_PATTERN "^$") # Empty string regex
endif()

get_target_property(_clangcheck_sources "${_name}" SOURCES)
set(_files)
foreach(_source ${_clangcheck_sources})
get_source_file_property(_clangcheck_lang "${_source}" LANGUAGE)
get_source_file_property(_clangcheck_loc "${_source}" LOCATION)
if("${_clangcheck_lang}" MATCHES "CXX" AND
NOT ${_clangcheck_loc} MATCHES ${add_clangcheck_EXCLUDE_PATTERN} AND
${_clangcheck_loc} MATCHES "\\.(cpp|cxx)$")
list(APPEND _files "${_clangcheck_loc}")
endif()
endforeach()

if(NOT _files) # nothing to check
return()
endif()

if(ENABLE_CLANGCHECK_TESTS)
add_test(NAME ${_name}_clangcheck_test
COMMAND "${CLANGCHECK}" ${_clangcheck_args} ${_files}
Expand Down

0 comments on commit d33b31f

Please sign in to comment.