Skip to content

Commit 2b730b4

Browse files
committed
c++ tooling
1 parent a8af34d commit 2b730b4

8 files changed

+174
-74
lines changed

.clang-tidy

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- mode: yaml -*-
2+
# vi: set ft=yaml :
3+
#
4+
# Name prefix Description
5+
# abseil- Checks related to Abseil library.
6+
# altera- Checks related to OpenCL programming for FPGAs.
7+
# android- Checks related to Android.
8+
# boost- Checks related to Boost library.
9+
# bugprone- Checks that target bug-prone code constructs.
10+
# cert- Checks related to CERT Secure Coding Guidelines.
11+
# clang-analyzer- Clang Static Analyzer checks.
12+
# concurrency- Checks related to concurrent programming (including threads, fibers, coroutines, etc.).
13+
# cppcoreguidelines- Checks related to C++ Core Guidelines.
14+
# darwin- Checks related to Darwin coding conventions.
15+
# fuchsia - Checks related to Fuchsia coding conventions.
16+
# google- Checks related to Google coding conventions.
17+
# hicpp- Checks related to High Integrity C++ Coding Standard.
18+
# linuxkernel- Checks related to the Linux Kernel coding conventions.
19+
# llvm- Checks related to the LLVM coding conventions.
20+
# llvmlibc- Checks related to the LLVM-libc coding standards.
21+
# misc- Checks that we didn’t have a better category for.
22+
# modernize- Checks that advocate usage of modern (currently “modern” means “C++11”) language constructs.
23+
# mpi- Checks related to MPI (Message Passing Interface).
24+
# objc- Checks related to Objective-C coding conventions.
25+
# openmp- Checks related to OpenMP API.
26+
# performance- Checks that target performance-related issues.
27+
# portability- Checks that target portability-related issues that don’t relate to any particular coding style.
28+
# readability- Checks that target readability-related issues that don’t relate to any particular coding style.
29+
# zircon- Checks related to Zircon kernel coding conventions.
30+
#
31+
---
32+
# https://clang.llvm.org/extra/clang-tidy/
33+
Checks: "*,
34+
-abseil-*,
35+
-altera-*,
36+
-android-*,
37+
-clang-diagnostic-old-style-cast,
38+
-cppcoreguidelines-avoid-magic-numbers,
39+
-cppcoreguidelines-non-private-member-variables-in-classes,
40+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
41+
-fuchsia-*,
42+
-google-*,
43+
-hicpp-no-array-decay,
44+
-llvm*,
45+
-misc-non-private-member-variables-in-classes,
46+
-modernize-use-trailing-return-type,
47+
-readability-avoid-const-params-in-decls,
48+
-readability-else-after-return,
49+
-readability-magic-numbers,
50+
-readability-static-accessed-through-instance,
51+
-zircon-*,
52+
"
53+
WarningsAsErrors: ''
54+
HeaderFilterRegex: ''
55+
FormatStyle: none

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Ignore compile_commands
2+
compile_commands.json
3+
.clangd/
4+
15
# numpy.i
26
numpy.i
37

INSTALL

-73
This file was deleted.

INSTALL.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# General instructions
2+
3+
These general instructions will build the binary and library versions of
4+
trackcpp, and also the python package. Before starting, read the requirements
5+
in the sections below. If you intend
6+
7+
REQUIREMENTS
8+
9+
(See below).
10+
11+
INSTRUCTIONS
12+
13+
1. Compile with 'make all'.
14+
15+
1. Install with 'make install' or, alternatively, install a symbolic link to
16+
the local compiled versions with 'make develop'.
17+
18+
# trackcpp
19+
20+
REQUIREMENTS
21+
22+
- a C++ compiler with C++11 support (tested with GCC 4.8)
23+
- pthread
24+
- blas
25+
- gsl (GNU Scientific Library)
26+
27+
For Debian systems the requirements can be installed using:
28+
29+
```command
30+
# Debian
31+
apt install libgsl-dev libblas-dev swig
32+
```
33+
34+
Clang tooling: As we are using Makefiles, we can use Bear to generate a compilation database file.
35+
36+
```command
37+
apt install bear clang-tools clang-format clang-tidy
38+
```
39+
40+
INSTRUCTIONS
41+
42+
1. Compile with 'make all'.
43+
44+
1. Install trackcpp with 'make install'. The installation directory is
45+
$(DEST_DIR), with DEST_DIR=/usr/local/bin by default. Alternatively, install a
46+
symbolic link to the local compiled version with 'make develop'.
47+
48+
# trackcpp Python package
49+
50+
REQUIREMENTS
51+
52+
- a C++ compiler with C++11 support (tested with GCC 4.8)
53+
- blas
54+
- gsl (GNU Scientific Library)
55+
- SWIG 2 (tested with SWIG 2.0.11)
56+
- Python 3 (tested with Python 3.4) with header files
57+
- Python setuptools (>=16.0)
58+
- libtrackcpp.a (see previous section)
59+
60+
INSTRUCTIONS
61+
62+
1. Check include and library paths in Makefile. On a Linux system, the default
63+
options should work (tested on Ubuntu 14.04 LTS); if necessary, alter the
64+
paths. An auxiliary script named 'compile' is provided and may be helpful on
65+
Mac OS X.
66+
67+
1. Run 'make all'.
68+
69+
1. Install the package with 'make install'. This will run 'python3 setup.py
70+
install', installing the Python package to a default location. Arguments to
71+
the command can be supplied through the variable SETUPARGS. Alternatively, the
72+
development version can be installed by running 'make develop', which will run
73+
'python3 setup.py develop' instead; arguments can be supplied the same way.

Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,34 @@ PYTHON_PACKAGE_DIR = python_package
8282

8383
$(shell touch $(SRCDIR)/output.cpp) # this is so that last compilation time always goes into executable
8484

85+
WARNINGS_CFLAGS += -Wall
86+
WARNINGS_CFLAGS += -Wextra # reasonable and standard
87+
WARNINGS_CFLAGS += -Wshadow # warn the user if a variable declaration shadows one from a parent context
88+
WARNINGS_CFLAGS += -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor.
89+
# This helps catch hard to track down memory errors
90+
# WARNINGS_CFLAGS += -Wdouble-promotion # warn if float is implicit promoted to double
91+
# WARNINGS_CFLAGS += -Wformat=2 # warn on security issues around functions that format output (ie printf)
92+
# WARNINGS_CFLAGS += -Wold-style-cast # warn for c-style casts
93+
# WARNINGS_CFLAGS += -Wsign-conversion # warn on sign conversions
94+
WARNINGS_CFLAGS += -Wcast-align # warn for potential performance problem casts
95+
WARNINGS_CFLAGS += -Wconversion # warn on type conversions that may lose data
96+
WARNINGS_CFLAGS += -Wduplicated-branches # warn if if / else branches have duplicated code
97+
WARNINGS_CFLAGS += -Wduplicated-cond # warn if if / else chain has duplicated conditions
98+
WARNINGS_CFLAGS += -Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
99+
WARNINGS_CFLAGS += -Wlogical-op # warn about logical operations being used where bitwise were probably wanted
100+
WARNINGS_CFLAGS += -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
101+
WARNINGS_CFLAGS += -Wnull-dereference # warn if a null dereference is detected
102+
WARNINGS_CFLAGS += -Woverloaded-virtual # warn if you overload (not override) a virtual function
103+
WARNINGS_CFLAGS += -Wpedantic # warn if non-standard C++ is used
104+
WARNINGS_CFLAGS += -Wunused # warn on anything being unused
105+
WARNINGS_CFLAGS += -Wuseless-cast # warn if you perform a cast to the same type
106+
85107
ifeq ($(MAKECMDGOALS),trackcpp-debug)
86108
CFLAGS = $(MACHINE) $(DBG_FLAG) $(DFLAGS) -pthread
87109
else
88110
CFLAGS = $(MACHINE) $(OPT_FLAG) $(DFLAGS) -pthread
89111
endif
112+
CFLAGS += $(WARNINGS_CFLAGS)
90113

91114
LIBOBJECTS = $(addprefix $(OBJDIR)/, $(LIBSOURCES_CPP:.cpp=.o))
92115
BINOBJECTS = $(addprefix $(OBJDIR)/, $(BINSOURCES_CPP:.cpp=.o))

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# trackcpp
2-
Particle tracking code
2+
3+
Particle tracking code
4+
5+
## Code check
6+
7+
In order to use clang-tidy, a compile_commands.json file must be present at the root of the repository.
8+
In order to generate one and still use make as the build system:
9+
10+
```command
11+
# Compile using 'bear <build command>'
12+
bear make -j$(nproc)
13+
```

tools/compile-command.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
set -exu
3+
make clean
4+
bear make

tools/static-analyser.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -exu
3+
clang-tidy-12 src/*.cpp

0 commit comments

Comments
 (0)