Skip to content

Commit

Permalink
Correct CMake Logic and update cpplint to Python3 (gazebosim#117)
Browse files Browse the repository at this point in the history
* Update cpplint to python3 compatible-version
* Find and use Python3 if available
* Split targets but maintain codecheck
* Add Ignition-specific default filters and suppressions

Co-authored-by: Louise Poubel <louise@openrobotics.org>
Signed-off-by: Michael Carroll <michael@openrobotics.org>
  • Loading branch information
mjcarroll and chapulina authored Nov 10, 2020
1 parent c8a4718 commit a559c57
Show file tree
Hide file tree
Showing 4 changed files with 1,004 additions and 287 deletions.
18 changes: 8 additions & 10 deletions cmake/IgnCodeCheck.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# Setup the codecheck target, which will run cppcheck and cppplint.
function(ign_setup_target_for_codecheck)
include(IgnPython)

find_program(CPPCHECK_PATH cppcheck)
find_program(PYTHON_PATH python)
find_program(FIND_PATH find)

if(NOT CPPCHECK_PATH)
message(STATUS "The program [cppcheck] was not found! Skipping codecheck setup")
return()
endif()

if(NOT PYTHON_PATH)
message(STATUS "python not found! Skipping codecheck setup.")
return()
endif()

if(NOT FIND_PATH)
message(STATUS "The program [find] was not found! Skipping codecheck setup.")
return()
Expand All @@ -37,17 +32,20 @@ function(ign_setup_target_for_codecheck)

message(STATUS "Adding codecheck target")

# Setup the codecheck target
add_custom_target(codecheck

add_custom_target(cppcheck
# First cppcheck
COMMAND ${CPPCHECK_PATH} ${CPPCHECK_BASE} ${CPPCHECK_EXTRA} -I ${CPPCHECK_INCLUDE_DIRS} ${CPPCHECK_RULES} `${CPPCHECK_FIND}`

# Second cppcheck
COMMAND ${CPPCHECK_PATH} ${CPPCHECK_BASE} --enable=missingInclude `${CPPCHECK_FIND}`
)

add_custom_target(cpplint
# cpplint cppcheck
COMMAND python ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}`
COMMAND ${PYTHON_EXECUTABLE} ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}`
)

add_custom_target(codecheck
DEPENDS cpplint cppcheck
)
endfunction()
25 changes: 25 additions & 0 deletions cmake/IgnPython.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2020 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copied from ament/ament_cmake: ament_cmake/ament_cmake_core/cmake/core/python.cmake

set(PYTHON_VERSION "" CACHE STRING
"Specify specific Python version to use ('major.minor' or 'major')")

# if not specified otherwise use Python 3
if(NOT PYTHON_VERSION)
set(PYTHON_VERSION "3")
endif()

find_package(PythonInterp ${PYTHON_VERSION} REQUIRED)
3 changes: 2 additions & 1 deletion cmake/IgnUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,8 @@ macro(ign_build_tests)

# Find the Python interpreter for running the
# check_test_ran.py script
find_package(PythonInterp QUIET)

include(IgnPython)

# Build all the tests
foreach(target_name ${test_list})
Expand Down
Loading

0 comments on commit a559c57

Please sign in to comment.