-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass include paths to cppcheck #117
Changes from all commits
6e187e7
f46461d
ff52dd1
d8fe783
5a301a0
c3d0e8d
d75d168
fc7f33c
4a50e31
75ef8c0
e67e564
85fd5b8
cf38eef
9eb4af9
fedce3e
ba7108b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
find_package(ament_cmake_core REQUIRED) | ||
|
||
file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS | ||
"*.c" | ||
"*.cc" | ||
|
@@ -24,5 +26,30 @@ file(GLOB_RECURSE _source_files FOLLOW_SYMLINKS | |
) | ||
if(_source_files) | ||
message(STATUS "Added test 'cppcheck' to perform static code analysis on C / C++ code") | ||
ament_cppcheck() | ||
|
||
# Get include paths for added targets | ||
set(_all_include_dirs "") | ||
# BUILDSYSTEM_TARGETS only supported in CMake >= 3.7 | ||
if(NOT CMAKE_VERSION VERSION_LESS "3.7.0") | ||
get_directory_property(_build_targets DIRECTORY ${CMAKE_SOURCE_DIR} BUILDSYSTEM_TARGETS) | ||
foreach(_target ${_build_targets}) | ||
get_property(_include_dirs | ||
TARGET ${_target} | ||
PROPERTY INCLUDE_DIRECTORIES | ||
) | ||
|
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails on Windows in this case: ros2/ros2#942. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the case that's failing. From the referenced ticket, it looks like the failures are due to headers from external packages not being passed to cppcheck (which is the intended behavior). For this case, we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the proper include directories ros2/rclpy#577 sets an additional include dir. |
||
foreach(_include_dir ${_include_dirs}) | ||
string(REGEX MATCH "^${CMAKE_SOURCE_DIR}.*" _is_match ${_include_dir}) | ||
if(_is_match) | ||
list_append_unique(_all_include_dirs ${_include_dir}) | ||
jacobperron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
endif() | ||
endforeach() | ||
endforeach() | ||
endif() | ||
|
||
ament_cppcheck(INCLUDE_DIRS ${_all_include_dirs}) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing a similar cppcheck complaint in
rmw_connext
andrmw_opensplice
where they use a macroRMW_CHECK_TYPE_IDENTIFIERS_MATCH
that is definedrmw
.https://ci.ros2.org/view/nightly/job/nightly_osx_extra_rmw_release/313/testReport/junit/rmw_opensplice_cpp/cppcheck/error__unknownMacro__src_rmw_wait_cpp_80_/
https://ci.ros2.org/job/nightly_osx_debug/1175/testReport/junit/rmw_connext_shared_cpp/cppcheck/error__unknownMacro___Users_osrf_jenkins_agent_workspace_nightly_osx_debug_ws_src_ros2_rmw_connext_rmw_connext_shared_cpp_include_rmw_connext_shared_cpp_wait_hpp_51_/
Any way to tell cppcheck where to look for macros without checking external files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sloretz See #125.
You can pass cppcheck one or more include directories that contain the macros it is trying to resolve.
I'm not satisfied with the solution, but I think anything better would require changes in
cppcheck
itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I missed that PR