Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/cleanCode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

name: Clean code

defaults:
run:
shell: bash

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

env:
BUILD_TYPE: Release

jobs:

cppCheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install cppCheck
run: sudo apt install -y cppcheck

- name: Configure CMake
run: cmake -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: CppCheck
run:
cppcheck --version
&& cmake --build ${{github.workspace}}/build --target hub-cppCheck


doxygen:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ssciwr/doxygen-install@v1.3.0

- name: Configure CMake
run: cmake -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DHUB_BUILD_DOC=ON

- name: Doxygen
run:
doxygen --version &&
cmake --build ${{github.workspace}}/build --target hub-doc-doxygen


format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install clang-format
run:
sudo apt install -y clang-format
&& clang-format --version

- name: Install cmake-format
run:
sudo apt install -y cmake-format
&& echo "cmake-format version $(cmake-format --version)"

- name: Configure CMake
run: cmake -B "${{github.workspace}}/build" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# todo please uncomment these above lines when project was fully formated
# - name: Format
# run: cmake --build ${{github.workspace}}/build --target hub-format
# && git diff --exit-code

Comment on lines +72 to +76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed when #27 pushing

1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Current head v.2.1.0 rc
* Add issue templates for bug report and feature request (#29)
* Add PULL_REQUEST_TEMPLATE file (#30)
* Add timeout for ci tests (#39)
* Add clean code (format, cppcheck, doxygen) asynchronous checks (#55)
- Tests
* Fix timeout error on macos (#33)
- Documentation
Expand Down
63 changes: 31 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,46 +220,45 @@ if(HUB_ENABLE_BINS)
add_subdirectory(bin)
endif()

if(NOT WIN32)
# Todo check if cppCheck exe exists on current system
find_package(cppcheck QUIET)
if(cppcheck_FOUND)
execute_process(
COMMAND cppcheck --version
COMMAND ${CPPCHECK_EXECUTABLE} --version
RESULT_VARIABLE CPP_CHECK_FOUND
OUTPUT_VARIABLE CPP_CHECK_OUTPUT
ERROR_VARIABLE CPP_CHECK_ERROR)
ERROR_VARIABLE CPP_CHECK_ERROR
)

if (NOT CPP_CHECK_FOUND)
string(REGEX MATCHALL "-.*$|[0-9]+" CPP_CHECK_VERSION_LIST ${CPP_CHECK_OUTPUT})
list(GET CPP_CHECK_VERSION_LIST 0 CPP_CHECK_VERSION_MAJOR)
list(GET CPP_CHECK_VERSION_LIST 1 CPP_CHECK_VERSION_MINOR)
# list(GET CPP_CHECK_VERSION_LIST 2 CPP_CHECK_VERSION_PATCH)
string(REGEX MATCHALL "-.*$|[0-9]+" CPP_CHECK_VERSION_LIST ${CPP_CHECK_OUTPUT})
list(GET CPP_CHECK_VERSION_LIST 0 CPP_CHECK_VERSION_MAJOR)
list(GET CPP_CHECK_VERSION_LIST 1 CPP_CHECK_VERSION_MINOR)
# list(GET CPP_CHECK_VERSION_LIST 2 CPP_CHECK_VERSION_PATCH)

# message(STATUS "${HEADER_MSG} Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR}.${CPP_CHECK_VERSION_PATCH} found")
message(STATUS "${HEADER_MSG} Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR} found")
message(STATUS "${HEADER_MSG} Cppcheck ${CPP_CHECK_VERSION_MAJOR}.${CPP_CHECK_VERSION_MINOR} found")

if(NOT ${CPP_CHECK_VERSION_MAJOR} EQUAL 2)
message(FATAL_ERROR "${CPP_CHECK_OUTPUT} unsupported")
endif()
if(NOT ${CPP_CHECK_VERSION_MAJOR} EQUAL 2)
message(FATAL_ERROR "${CPP_CHECK_OUTPUT} unsupported")
endif()

if (${CPP_CHECK_VERSION_MINOR} GREATER 10)
add_custom_target(
hub-cppCheck
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND
cppcheck -DCPP_CHECK src -I src --error-exitcode=1 --enable=all --suppress=missingIncludeSystem
--suppress=missingInclude --suppress=unusedFunction --suppress=virtualCallInConstructor --inline-suppr
COMMENT "Running cppCheck")
else()
add_custom_target(
hub-cppCheck
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND
cppcheck -DCPP_CHECK src -I src --error-exitcode=1 --enable=all
--suppress=missingInclude --suppress=unusedFunction --suppress=virtualCallInConstructor --inline-suppr
COMMENT "Running cppCheck")
endif()
custom_target_added(cppCheck)
if (${CPP_CHECK_VERSION_MINOR} GREATER 10)
add_custom_target(
hub-cppCheck
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND
cppcheck -DCPP_CHECK src -I src --error-exitcode=1 --enable=all --suppress=missingIncludeSystem
--suppress=missingInclude --suppress=unusedFunction --suppress=virtualCallInConstructor --inline-suppr
COMMENT "Running cppCheck")
else()
add_custom_target(
hub-cppCheck
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND
cppcheck -DCPP_CHECK src -I src --error-exitcode=1 --enable=all
--suppress=missingInclude --suppress=unusedFunction --suppress=virtualCallInConstructor --inline-suppr
COMMENT "Running cppCheck")
endif()
custom_target_added(cppCheck)

endif()

add_custom_target(
Expand Down
168 changes: 168 additions & 0 deletions cmake/Findcppcheck.cmake
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file coming from another project ?
If yes, please add source + check licence.

Copy link
Copy Markdown
Contributor Author

@hiergaut hiergaut Jun 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Findcppcheck.cmake line 20-28 :

# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems compatible with MPL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# - try to find cppcheck tool
#
# Cache Variables:
# CPPCHECK_EXECUTABLE
#
# Non-cache variables you might use in your CMakeLists.txt:
# CPPCHECK_FOUND
# CPPCHECK_UNUSEDFUNC_ARG
# CPPCHECK_STYLE_ARG
# CPPCHECK_QUIET_ARG
# CPPCHECK_INCLUDEPATH_ARG
# CPPCHECK_FAIL_REGULAR_EXPRESSION
# CPPCHECK_WARN_REGULAR_EXPRESSION
# CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even
# if we don't find this program.
#
# Requires these CMake modules:
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)

file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
set(CPPCHECK_ROOT_DIR
"${CPPCHECK_ROOT_DIR}"
CACHE PATH "Path to search for cppcheck")
mark_as_advanced(CPPCHECK_ROOT_DIR)

# cppcheck app bundles on Mac OS X are GUI, we want command line only
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
set(CMAKE_FIND_APPBUNDLE NEVER)

# If we have a custom path, look there first.
if(CPPCHECK_ROOT_DIR)
find_program(
CPPCHECK_EXECUTABLE
NAMES cppcheck cli
PATHS "${CPPCHECK_ROOT_DIR}"
PATH_SUFFIXES cli
NO_DEFAULT_PATH)
endif()

find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)

# Restore original setting for appbundle finding
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})

if(CPPCHECK_EXECUTABLE)
# Find out where our test file is
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")

# common to all version of cppcheck
set(CPPCHECK_QUIET_ARG --quiet)
set(CPPCHECK_FORCE_ARG --force)
set(CPPCHECK_VERBOSE_ARG --verbose)
set(CPPCHECK_INCLUDEPATH_ARG -I)
set(CPPCHECK_DEFINITION_ARG -D)
set(CPPCHECK_ALL_ARG --enable=all)

# Check for the two types of command line arguments by just trying them
execute_process(
COMMAND ${CPPCHECK_EXECUTABLE} --enable=style ${CPPCHECK_QUIET_ARG} ${_cppcheckdummyfile}
RESULT_VARIABLE _cppcheck_enable_style_result
OUTPUT_QUIET ERROR_QUIET)

if("${_cppcheck_enable_style_result}" EQUAL 0)

set(CPPCHECK_STYLE_ARG --enable=style)

# How to display errors and warnings:
if(MSVC)
set(CPPCHECK_TEMPLATE_ARG --template vs)
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
else()
## This is about the IDE, not the compiler for formatting support. Many IDE's
## support the gcc style error messages.
set(CPPCHECK_TEMPLATE_ARG --template gcc)
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
endif()

else()
message("This file supports only version of cppcheck is newer than 1.43!")

endif()

execute_process(
COMMAND ${CPPCHECK_EXECUTABLE} --enable=unusedFunctions ${CPPCHECK_QUIET_ARG} ${_cppcheckdummyfile}
RESULT_VARIABLE _cppcheck_enable_unused_functions_results
OUTPUT_QUIET ERROR_QUIET)

if("${_cppcheck_enable_unused_functions_results}" EQUAL 0)
set(CPPCHECK_UNUSEDFUNC_ARG --enable=unusedFunctions)
else()
execute_process(
COMMAND ${CPPCHECK_EXECUTABLE} --enable=unusedFunction ${CPPCHECK_QUIET_ARG} ${_cppcheckdummyfile}
RESULT_VARIABLE _cppcheck_enable_unused_function_results
OUTPUT_QUIET ERROR_QUIET)

if("${_cppcheck_enable_unused_function_results}" EQUAL 0)
set(CPPCHECK_UNUSEDFUNC_ARG --enable=unusedFunction)
else()
set(CPPCHECK_UNUSEDFUNC_ARG)
endif()

endif()

execute_process(
COMMAND ${CPPCHECK_EXECUTABLE} --enable=information ${CPPCHECK_QUIET_ARG} ${_cppcheckdummyfile}
RESULT_VARIABLE _cppcheck_enable_information_results
OUTPUT_QUIET ERROR_QUIET)

if("${_cppcheck_enable_information_results}" EQUAL 0)
# supported since
set(CPPCHECK_INFORMATION_ARG --enable=information)
else()
set(CPPCHECK_INFORMATION_ARG)
endif()

execute_process(
COMMAND ${CPPCHECK_EXECUTABLE} --enable=missingInclude ${CPPCHECK_QUIET_ARG} ${_cppcheckdummyfile}
RESULT_VARIABLE _cppcheck_missingInclude_results
OUTPUT_QUIET ERROR_QUIET)

if("${_cppcheck_missingInclude_results}" EQUAL 0)
# supported since
set(CPPCHECK_MISSING_INCLUDE_ARG --enable=missingInclude)
else()
set(CPPCHECK_MISSING_INCLUDE_ARG)
endif()

endif()

set(CPPCHECK_ALL
"${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
cppcheck
DEFAULT_MSG
CPPCHECK_ALL
CPPCHECK_EXECUTABLE
CPPCHECK_UNUSEDFUNC_ARG
CPPCHECK_STYLE_ARG
CPPCHECK_INFORMATION_ARG
CPPCHECK_MISSING_INCLUDE_ARG
CPPCHECK_ALL_ARG
CPPCHECK_INCLUDEPATH_ARG
CPPCHECK_DEFINITION_ARG
CPPCHECK_QUIET_ARG
CPPCHECK_FORCE_ARG
CPPCHECK_VERBOSE_ARG)

if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
mark_as_advanced(CPPCHECK_ROOT_DIR)
endif()

mark_as_advanced(CPPCHECK_EXECUTABLE)
17 changes: 17 additions & 0 deletions cmake/Findcppcheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* \file Findcppcheck.cpp
* \brief Dummy C++ source file used by CMake module Findcppcheck.cmake
*
* \author
* Ryan Pavlik, 2009-2010
* <rpavlik@iastate.edu>
* http://academic.cleardefinition.com/
*
*/



int main(int argc, char* argv[])
{
return 0;
}
Loading