From 0dab887946c6c49d3ced0d07af805d6513553de2 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Sat, 29 Aug 2020 21:45:47 -0500 Subject: [PATCH 1/4] Simplify ament_lint include logic Previously the logic did not handle generator expressions in a consistent way and required users to add recursive dependencies to cppcheck e.g. https://github.com/ros2/rosidl_typesupport_connext/pull/57 . This should fix that. Performance impact should be assessed. Signed-off-by: Dan Rose --- .../ament_cmake_cppcheck_lint_hook.cmake | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake index 2a04658e..88ec2095 100644 --- a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake +++ b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake @@ -50,29 +50,7 @@ if(_source_files) if(NOT CMAKE_VERSION VERSION_LESS "3.7.0") get_directory_property(_build_targets DIRECTORY ${PROJECT_SOURCE_DIR} BUILDSYSTEM_TARGETS) foreach(_target ${_build_targets}) - # Include directories property is different for INTERFACE libraries - get_target_property(_target_type ${_target} TYPE) - if(${_target_type} STREQUAL "INTERFACE_LIBRARY") - get_target_property(_include_dirs ${_target} INTERFACE_INCLUDE_DIRECTORIES) - else() - get_target_property(_include_dirs ${_target} INCLUDE_DIRECTORIES) - endif() - - # Only append include directories that are from the package being tested - # This accomplishes two things: - # 1. Reduces execution time (less include directories to search) - # 2. cppcheck will not check for errors in external packages - foreach(_include_dir ${_include_dirs}) - # TODO(jacobperron): Escape special regex characters in PROJECT_SOURCE_DIR - # Related CMake feature request: https://gitlab.kitware.com/cmake/cmake/issues/18409 - # Check if include directory is a subdirectory of the source directory - string(REGEX MATCH "^${PROJECT_SOURCE_DIR}/.*" _is_subdirectory ${_include_dir}) - # Check if include directory is part of a generator expression (e.g. $) - string(REGEX MATCH "^\\$<.*:${PROJECT_SOURCE_DIR}/.*>$" _is_genexp_subdirectory "${_include_dir}") - if(_is_subdirectory OR _is_genexp_subdirectory) - list_append_unique(_all_include_dirs ${_include_dir}) - endif() - endforeach() + list(APPEND _all_include_dirs $>) endforeach() endif() From 08818eba37b3b4ec2840eac229e9a8798555581d Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Sat, 29 Aug 2020 23:38:34 -0500 Subject: [PATCH 2/4] Update ament_cmake_cppcheck_lint_hook.cmake --- .../cmake/ament_cmake_cppcheck_lint_hook.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake index 88ec2095..05c24db6 100644 --- a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake +++ b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake @@ -50,7 +50,11 @@ if(_source_files) if(NOT CMAKE_VERSION VERSION_LESS "3.7.0") get_directory_property(_build_targets DIRECTORY ${PROJECT_SOURCE_DIR} BUILDSYSTEM_TARGETS) foreach(_target ${_build_targets}) - list(APPEND _all_include_dirs $>) + if(${_target_type} STREQUAL "INTERFACE_LIBRARY") + list(APPEND _all_include_dirs $>) + else() + list(APPEND _all_include_dirs $>) + endif() endforeach() endif() From 343cc1f9ffb336be13a98a937e6d39985a84acf9 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Sun, 30 Aug 2020 00:50:35 -0500 Subject: [PATCH 3/4] unbreak it? --- .../cmake/ament_cmake_cppcheck_lint_hook.cmake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake index 05c24db6..c342714d 100644 --- a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake +++ b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake @@ -50,11 +50,10 @@ if(_source_files) if(NOT CMAKE_VERSION VERSION_LESS "3.7.0") get_directory_property(_build_targets DIRECTORY ${PROJECT_SOURCE_DIR} BUILDSYSTEM_TARGETS) foreach(_target ${_build_targets}) - if(${_target_type} STREQUAL "INTERFACE_LIBRARY") - list(APPEND _all_include_dirs $>) - else() + get_target_property(_target_type "${_target}" TYPE) + if(NOT ${_target_type} STREQUAL "INTERFACE_LIBRARY") list(APPEND _all_include_dirs $>) - endif() + endif() endforeach() endif() From 4bf1453e232708a9d0eb6a9c31e55796cbafe6b9 Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Sun, 30 Aug 2020 01:26:41 -0500 Subject: [PATCH 4/4] ... --- ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake index c342714d..ccaccf49 100644 --- a/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake +++ b/ament_cmake_cppcheck/cmake/ament_cmake_cppcheck_lint_hook.cmake @@ -52,7 +52,7 @@ if(_source_files) foreach(_target ${_build_targets}) get_target_property(_target_type "${_target}" TYPE) if(NOT ${_target_type} STREQUAL "INTERFACE_LIBRARY") - list(APPEND _all_include_dirs $>) + list(APPEND _all_include_dirs $) endif() endforeach() endif()