Skip to content

Commit 417f835

Browse files
Nesterov AlexanderNesterov Alexander
Nesterov Alexander
and
Nesterov Alexander
authored
Add cppcheck (#36)
* init cppcheck * update apple cppcheck Co-authored-by: Nesterov Alexander <[email protected]>
1 parent d2af243 commit 417f835

File tree

8 files changed

+139
-5
lines changed

8 files changed

+139
-5
lines changed

.github/workflows/main.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
1313
sudo apt-get update
1414
sudo apt-get install g++-9
15+
sudo apt-get install cppcheck
1516
sudo apt-get install mpich libmpich-dev
1617
sudo apt-get install libomp-9-dev libtbb-dev
1718
sudo apt-get install texlive*
@@ -40,7 +41,8 @@ jobs:
4041
- name: Setup environment
4142
run: |
4243
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
43-
sudo apt-get update
44+
sudo apt-get update
45+
sudo apt-get install cppcheck
4446
sudo apt-get install clang-8 mpich libmpich-dev libomp-9-dev libtbb-dev texlive*
4547
- name: Update submodules
4648
run: git submodule update --init --recursive
@@ -69,6 +71,7 @@ jobs:
6971
brew update-reset
7072
brew unlink [email protected]
7173
brew install open-mpi libomp tbb
74+
brew install cppcheck
7275
- name: Update submodules
7376
run: git submodule update --init --recursive
7477
- name: Run linter

.travis.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ matrix:
77
addons:
88
apt:
99
sources: ubuntu-toolchain-r-test
10-
packages: g++-5
10+
packages:
11+
- g++-5
12+
- cppcheck
1113
env: MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
1214
before_script:
1315
- python scripts/lint.py
@@ -17,20 +19,28 @@ matrix:
1719
addons:
1820
apt:
1921
sources: ubuntu-toolchain-r-test
20-
packages: g++-8
22+
packages:
23+
- g++-8
24+
- cppcheck
2125
env: MATRIX_EVAL="CC=gcc-8 && CXX=g++-8
2226

2327
- os: linux
2428
dist: xenial
2529
compiler: clang
2630
addons:
2731
apt:
28-
packages: clang-5.0
32+
packages:
33+
- clang-5.0
34+
- cppcheck
2935
env: MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
3036

3137
- os: linux
3238
dist: xenial
3339
compiler: clang
40+
addons:
41+
apt:
42+
packages:
43+
- cppcheck
3444

3545
- os: osx
3646
osx_image: xcode10.1
@@ -46,6 +56,7 @@ install:
4656
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew update-reset; fi
4757
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew unlink python@2; fi
4858
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew install open-mpi libomp tbb; fi
59+
- if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew install cppcheck; fi
4960

5061
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then sudo apt-get install mpich libmpich-dev; fi
5162
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then sudo apt-get install libomp-dev libtbb-dev; fi

modules/test_tasks/test_mpi/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ if( USE_MPI )
3131

3232
enable_testing()
3333
add_test(NAME ${ProjectId} COMMAND ${ProjectId})
34+
35+
if( UNIX )
36+
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
37+
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
38+
string(FIND ${SOURCE_FILE} ${PROJECT_BINARY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
39+
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
40+
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
41+
endif ()
42+
endforeach ()
43+
44+
find_program(CPPCHECK cppcheck)
45+
add_custom_target(
46+
"${ProjectId}_cppcheck" ALL
47+
COMMAND ${CPPCHECK}
48+
--enable=warning,performance,portability,information,missingInclude
49+
--language=c++
50+
--std=c++11
51+
--error-exitcode=1
52+
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
53+
--verbose
54+
--quiet
55+
${ALL_SOURCE_FILES}
56+
)
57+
endif( UNIX )
3458
else( USE_MPI )
3559
message( STATUS "-- ${ProjectId} - NOT BUILD!" )
3660
endif( USE_MPI )

modules/test_tasks/test_mpi/ops_mpi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int getParallelOperations(std::vector<int> global_vec,
6060

6161
int global_sum = 0;
6262
int local_sum = getSequentialOperations(local_vec, ops);
63-
MPI_Op op_code;
63+
MPI_Op op_code = MPI_OP_NULL;
6464
if (ops == "+" || ops == "-") { op_code = MPI_SUM; }
6565
if (ops == "max") { op_code = MPI_MAX; }
6666
MPI_Reduce(&local_sum, &global_sum, 1, MPI_INT, op_code, 0, MPI_COMM_WORLD);

modules/test_tasks/test_omp/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ if ( USE_OMP )
1717

1818
enable_testing()
1919
add_test(NAME ${ProjectId} COMMAND ${ProjectId})
20+
21+
if( UNIX )
22+
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
23+
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
24+
string(FIND ${SOURCE_FILE} ${PROJECT_BINARY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
25+
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
26+
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
27+
endif ()
28+
endforeach ()
29+
30+
find_program(CPPCHECK cppcheck)
31+
add_custom_target(
32+
"${ProjectId}_cppcheck" ALL
33+
COMMAND ${CPPCHECK}
34+
--enable=warning,performance,portability,information,missingInclude
35+
--language=c++
36+
--std=c++11
37+
--error-exitcode=1
38+
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
39+
--verbose
40+
--quiet
41+
${ALL_SOURCE_FILES}
42+
)
43+
endif( UNIX )
2044
else( USE_OMP )
2145
message( STATUS "-- ${ProjectId} - NOT BUILD!" )
2246
endif( USE_OMP )

modules/test_tasks/test_seq/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ if ( USE_SEQ )
1717

1818
enable_testing()
1919
add_test(NAME ${ProjectId} COMMAND ${ProjectId})
20+
21+
if( UNIX )
22+
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
23+
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
24+
string(FIND ${SOURCE_FILE} ${PROJECT_BINARY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
25+
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
26+
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
27+
endif ()
28+
endforeach ()
29+
30+
find_program(CPPCHECK cppcheck)
31+
add_custom_target(
32+
"${ProjectId}_cppcheck" ALL
33+
COMMAND ${CPPCHECK}
34+
--enable=warning,performance,portability,information,missingInclude
35+
--language=c++
36+
--std=c++11
37+
--error-exitcode=1
38+
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
39+
--verbose
40+
--quiet
41+
${ALL_SOURCE_FILES}
42+
)
43+
endif( UNIX )
2044
else( USE_SEQ )
2145
message( STATUS "-- ${ProjectId} - NOT BUILD!" )
2246
endif( USE_SEQ )

modules/test_tasks/test_std/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ if ( USE_STD )
1818

1919
enable_testing()
2020
add_test(NAME ${ProjectId} COMMAND ${ProjectId})
21+
22+
if( UNIX )
23+
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
24+
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
25+
string(FIND ${SOURCE_FILE} ${PROJECT_BINARY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
26+
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
27+
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
28+
endif ()
29+
endforeach ()
30+
31+
find_program(CPPCHECK cppcheck)
32+
add_custom_target(
33+
"${ProjectId}_cppcheck" ALL
34+
COMMAND ${CPPCHECK}
35+
--enable=warning,performance,portability,information,missingInclude
36+
--language=c++
37+
--std=c++11
38+
--error-exitcode=1
39+
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
40+
--verbose
41+
--quiet
42+
${ALL_SOURCE_FILES}
43+
)
44+
endif( UNIX )
2145
else( USE_STD )
2246
message( STATUS "-- ${ProjectId} - NOT BUILD!" )
2347
endif( USE_STD )

modules/test_tasks/test_tbb/CMakeLists.txt

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ if ( USE_TBB )
2222

2323
enable_testing()
2424
add_test(NAME ${ProjectId} COMMAND ${ProjectId})
25+
26+
if( UNIX )
27+
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
28+
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
29+
string(FIND ${SOURCE_FILE} ${PROJECT_BINARY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
30+
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
31+
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
32+
endif ()
33+
endforeach ()
34+
35+
find_program(CPPCHECK cppcheck)
36+
add_custom_target(
37+
"${ProjectId}_cppcheck" ALL
38+
COMMAND ${CPPCHECK}
39+
--enable=warning,performance,portability,information,missingInclude
40+
--language=c++
41+
--std=c++11
42+
--error-exitcode=1
43+
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
44+
--verbose
45+
--quiet
46+
${ALL_SOURCE_FILES}
47+
)
48+
endif( UNIX )
2549
else( USE_TBB )
2650
message( STATUS "-- ${ProjectId} - NOT BUILD!" )
2751
endif( USE_TBB )

0 commit comments

Comments
 (0)