Skip to content

Commit 1d77861

Browse files
azeeyscpeters
andauthored
Add a codecheck make target (#682)
Utilizes ignition-cmake's IgnCodecheck module to create the codecheck target. Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org> Co-authored-by: Steve Peters <scpeters@openrobotics.org>
1 parent d087d47 commit 1d77861

File tree

10 files changed

+39
-9
lines changed

10 files changed

+39
-9
lines changed

CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,28 @@ else (build_errors)
280280
add_subdirectory(doc)
281281
endif(BUILD_SDF)
282282

283+
########################################
284+
# Setup Codecheck
285+
include (IgnCodeCheck)
286+
set(CPPCHECK_DIRS
287+
${PROJECT_SOURCE_DIR}/src
288+
${PROJECT_SOURCE_DIR}/include
289+
${PROJECT_SOURCE_DIR}/test/integration
290+
${PROJECT_SOURCE_DIR}/test/performance)
291+
292+
set(CPPCHECK_INCLUDE_DIRS
293+
${PROJECT_BINARY_DIR}
294+
${PROJECT_SOURCE_DIR}/include
295+
${PROJECT_SOURCE_DIR}/test/integration
296+
${PROJECT_SOURCE_DIR}/test/performance)
297+
298+
# Ignore vendored directories.
299+
file(WRITE ${PROJECT_BINARY_DIR}/cppcheck.suppress
300+
"*:${PROJECT_SOURCE_DIR}/src/win/*\n"
301+
"*:${PROJECT_SOURCE_DIR}/src/urdf/*\n"
302+
)
303+
ign_setup_target_for_codecheck()
304+
283305
########################################
284306
# Make the package config file
285307
configure_file(${CMAKE_SOURCE_DIR}/cmake/sdformat_pc.in

cmake/SearchForStuff.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ macro (check_gcc_visibility)
126126
check_cxx_compiler_flag(-fvisibility=hidden GCC_SUPPORTS_VISIBILITY)
127127
endmacro()
128128

129+
########################################
130+
# Find ignition cmake2
131+
# Only for using the testing macros and creating the codecheck target, not
132+
# really being use to configure the whole project
133+
find_package(ignition-cmake2 REQUIRED)
134+
set(IGN_CMAKE_VER ${ignition-cmake2_VERSION_MAJOR})
135+
129136
########################################
130137
# Find ignition math
131138
# Set a variable for generating ProjectConfig.cmake

include/sdf/Console.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace sdf
7373
/// \brief Constructor.
7474
/// \param[in] _stream Pointer to an output stream operator. Can be
7575
/// NULL/nullptr.
76-
public: ConsoleStream(std::ostream *_stream) :
76+
public: explicit ConsoleStream(std::ostream *_stream) :
7777
stream(_stream) {}
7878

7979
/// \brief Redirect whatever is passed in to both our ostream

include/sdf/Exception.hh

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ namespace sdf
126126
/// \param[in] _line Line number where the error occurred
127127
/// \param[in] _msg Error message
128128
public: InternalError(const char *_file, std::int64_t _line,
129+
// cppcheck-suppress passedByValue
129130
const std::string _msg);
130131

131132
/// \brief Destructor
@@ -148,8 +149,11 @@ namespace sdf
148149
/// \param[in] _msg Function where assertion failed
149150
public: AssertionInternalError(const char *_file,
150151
std::int64_t _line,
152+
// cppcheck-suppress passedByValue
151153
const std::string _expr,
154+
// cppcheck-suppress passedByValue
152155
const std::string _function,
156+
// cppcheck-suppress passedByValue
153157
const std::string _msg = "");
154158
/// \brief Destructor
155159
public: virtual ~AssertionInternalError();

include/sdf/Param.hh

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ namespace sdf
282282
template<typename T>
283283
std::string ParamPrivate::TypeToString() const
284284
{
285+
// cppcheck-suppress syntaxError
285286
if constexpr (std::is_same_v<T, bool>)
286287
return "bool";
287288
else if constexpr (std::is_same_v<T, char>)

include/sdf/parser_urdf.hh

+4
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ namespace sdf
7373
private: void ParseSDFExtension(TiXmlDocument &_urdfXml);
7474

7575
/// list extensions for debugging
76+
// cppcheck-suppress unusedPrivateFunction
77+
// cppcheck-suppress unmatchedSuppression
7678
private: void ListSDFExtensions();
7779

7880
/// list extensions for debugging
81+
// cppcheck-suppress unusedPrivateFunction
82+
// cppcheck-suppress unmatchedSuppression
7983
private: void ListSDFExtensions(const std::string &_reference);
8084
};
8185
}

src/Error.cc

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ namespace sdf
5757
inline namespace SDF_VERSION_NAMESPACE {
5858

5959
/////////////////////////////////////////////////
60-
// cppcheck-suppress unusedFunction
6160
std::ostream &operator<<(std::ostream &_out, const sdf::Error &_err)
6261
{
6362
_out << "Error Code "

src/SDF.cc

-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static std::function<std::string(const std::string &)> g_findFileCB;
5151
std::string SDF::version = SDF_VERSION; // NOLINT(runtime/string)
5252

5353
/////////////////////////////////////////////////
54-
// cppcheck-suppress passedByValue
5554
void setFindCallback(std::function<std::string(const std::string &)> _cb)
5655
{
5756
g_findFileCB = _cb;
@@ -69,7 +68,6 @@ std::string findFile(const std::string &_filename, bool _searchLocalPath,
6968
{
7069
// Check to see if the URI in the global map is the first part of the
7170
// given filename
72-
// cppcheck-suppress stlIfStrFind
7371
if (_filename.find(iter->first) == 0)
7472
{
7573
std::string suffix = _filename;

src/ign.cc

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "ign.hh"
2828

2929
//////////////////////////////////////////////////
30-
// cppcheck-suppress unusedFunction
3130
extern "C" SDFORMAT_VISIBLE int cmdCheck(const char *_path)
3231
{
3332
int result = 0;
@@ -96,7 +95,6 @@ extern "C" SDFORMAT_VISIBLE int cmdCheck(const char *_path)
9695
}
9796

9897
//////////////////////////////////////////////////
99-
// cppcheck-suppress unusedFunction
10098
extern "C" SDFORMAT_VISIBLE char *ignitionVersion()
10199
{
102100
#ifdef _MSC_VER
@@ -109,7 +107,6 @@ extern "C" SDFORMAT_VISIBLE char *ignitionVersion()
109107
//////////////////////////////////////////////////
110108
/// \brief Print the full description of the SDF spec.
111109
/// \return 0 on success, -1 if SDF could not be initialized.
112-
// cppcheck-suppress unusedFunction
113110
extern "C" SDFORMAT_VISIBLE int cmdDescribe(const char *_version)
114111
{
115112
sdf::SDFPtr sdf(new sdf::SDF());
@@ -130,7 +127,6 @@ extern "C" SDFORMAT_VISIBLE int cmdDescribe(const char *_version)
130127
}
131128

132129
//////////////////////////////////////////////////
133-
// cppcheck-suppress unusedFunction
134130
extern "C" SDFORMAT_VISIBLE int cmdPrint(const char *_path)
135131
{
136132
if (!sdf::filesystem::exists(_path))

test/integration/locale_fix_cxx.cc

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ TEST(CheckFixForLocal, CheckFixForCxxLocal)
2525
{
2626
struct CommaDecimalPointFacet : std::numpunct<char>
2727
{
28-
// cppcheck-suppress unusedFunction
2928
char do_decimal_point() const
3029
{
3130
return ',';

0 commit comments

Comments
 (0)