Skip to content
Merged
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
15 changes: 6 additions & 9 deletions .github/workflows/CI-mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ jobs:
run: |
export PATH="/mingw64/lib/ccache/bin:$PATH"
# set RDYNAMIC to work around broken MinGW detection
make VERBOSE=1 RDYNAMIC=-lshlwapi -j$(nproc) cppcheck
env:
LDFLAGS: -fuse-ld=lld # use lld for faster linking
# use lld for faster linking
make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) cppcheck

- name: Build test
run: |
export PATH="/mingw64/lib/ccache/bin:$PATH"
# set RDYNAMIC to work around broken MinGW detection
make VERBOSE=1 RDYNAMIC=-lshlwapi -j$(nproc) testrunner
env:
LDFLAGS: -fuse-ld=lld # use lld for faster linking
# use lld for faster linking
make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) testrunner

- name: Run test
run: |
export PATH="/mingw64/lib/ccache/bin:$PATH"
# set RDYNAMIC to work around broken MinGW detection
make VERBOSE=1 RDYNAMIC=-lshlwapi -j$(nproc) check
env:
LDFLAGS: -fuse-ld=lld # use lld for faster linking
# use lld for faster linking
make VERBOSE=1 RDYNAMIC=-lshlwapi LDOPTS=-fuse-ld=lld -j$(nproc) check
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ jobs:
- name: Build cppcheck
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) HAVE_RULES=yes CXXFLAGS="-w"
make -j$(nproc) HAVE_RULES=yes CXXOPTS="-w"

- name: Build test
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) testrunner HAVE_RULES=yes CXXFLAGS="-w"
make -j$(nproc) testrunner HAVE_RULES=yes CXXOPTS="-w"

- name: Run test
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
- name: Build with Unsigned char
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) CXXFLAGS=-funsigned-char testrunner
make -j$(nproc) CXXOPTS=-funsigned-char testrunner

- name: Test with Unsigned char
run: |
Expand Down Expand Up @@ -569,7 +569,7 @@ jobs:
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
# compile with verification and ast matchers
make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXFLAGS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXOPTS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1

- name: CMake
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Compile instrumented
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) all CXXFLAGS="-g -fprofile-arcs -ftest-coverage" HAVE_RULES=yes
make -j$(nproc) all CXXOPTS="-g -fprofile-arcs -ftest-coverage" HAVE_RULES=yes

- name: Run instrumented tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cppcheck-premium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
tar xzvf cppcheckpremium.tar.gz
mv cppcheckpremium-devdrop-20250713 cppcheckpremium
# Overwrite cppcheck binary
make -j$(nproc) CXXFLAGS=-O2 MATCHCOMPILER=yes
make -j$(nproc) CXXOPTS=-O2 MATCHCOMPILER=yes
cp cppcheck cppcheckpremium/

- name: Generate a license file
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: build cppcheck
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) -s CXXFLAGS="-w"
make -j$(nproc) -s CXXOPTS="-w"
strip -s ./cppcheck

scriptcheck:
Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:

- name: run dmake
run: |
make -j3 CXXFLAGS="-w" run-dmake
make -j3 CXXOPTS="-w" run-dmake

- name: check diff
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
# valgrind cannot handle DWARF 5 yet so force version 4
# work around performance regression with -inline-deferral
make -j$(nproc) -s CXXFLAGS="-O2 -w -DHAVE_BOOST -gdwarf-4 -mllvm -inline-deferral" MATCHCOMPILER=yes
make -j$(nproc) -s CXXOPTS="-O2 -w -DHAVE_BOOST -gdwarf-4 -mllvm -inline-deferral" MATCHCOMPILER=yes
env:
CC: clang-14
CXX: clang++-14
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ jobs:
- name: Build cppcheck
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes

- name: Build test
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
CXXFLAGS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes

- name: Run valgrind
run: |
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ else ifneq ($(HAVE_RULES),)
$(error invalid HAVE_RULES value '$(HAVE_RULES)')
endif

override CXXFLAGS += $(CXXOPTS)
override LDFLAGS += $(LDOPTS)

ifndef PREFIX
PREFIX=/usr
endif
Expand Down
4 changes: 2 additions & 2 deletions createrelease
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# - ensure cfg files etc are included (win_installer/cppcheck.wxs)
#
# self check, fix critical issues:
# make clean && make CXXFLAGS=-O2 MATCHCOMPILER=yes -j4
# make clean && make CXXOPTS=-O2 MATCHCOMPILER=yes -j4
# ./cppcheck -D__CPPCHECK__ -D__GNUC__ -DCHECK_INTERNAL -DHAVE_RULES --std=c++11 --library=cppcheck-lib --library=qt --enable=style --inconclusive --inline-suppr --suppress=bitwiseOnBoolean --suppress=shadowFunction --suppress=useStlAlgorithm --suppress=*:externals/picojson.h --suppress=functionConst --suppress=functionStatic --suppress=normalCheckLevelMaxBranches --xml cli gui/*.cpp lib 2> selfcheck.xml
#
# Generate lib/checkers.cpp (TODO the premium checkers should not be statically coded)
Expand Down Expand Up @@ -155,7 +155,7 @@ cp -R ~/cppcheck/cfg .
cp -R ~/cppcheck/addons .
cp -R ~/cppcheck/platforms .
cd ~/cppcheck
make clean ; make -j12 FILESDIR=~/.cppcheck/$tag MATCHCOMPILER=yes CXXFLAGS=-O2
make clean ; make -j12 FILESDIR=~/.cppcheck/$tag MATCHCOMPILER=yes CXXOPTS=-O2
mv cppcheck ~/.cppcheck/cppcheck-$tag

git checkout main
2 changes: 1 addition & 1 deletion generate_coverage_report
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
make clean
rm -rf coverage_report
make test CXXFLAGS="-g -fprofile-arcs -ftest-coverage"
make test CXXOPTS="-g -fprofile-arcs -ftest-coverage"
test/cfg/runtests.sh
gcov lib/*.cpp -o lib/
lcov --directory ./ --capture --output-file lcov_tmp.info -b ./
Expand Down
69 changes: 31 additions & 38 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ When building the command line tool, [PCRE](http://www.pcre.org/) is optional. I

There are multiple compilation choices:
* CMake - cross platform build tool
* Windows: Visual Studio
* Windows: Qt Creator + MinGW
* GNU make
* GCC (g++)
* Clang (clang++)
* (Windows) Visual Studio
* (Windows) Qt Creator + MinGW
* GNU compilers - via make or directly

The minimum required Python version is 3.6.

Expand All @@ -57,10 +55,8 @@ The minimum required version is CMake 3.13.
Example, compiling Cppcheck with cmake:

```shell
mkdir build
cd build
cmake ..
cmake --build .
cmake -S . -B build
cmake --build build
```

If you want to compile the GUI you can use the flag.
Expand All @@ -82,19 +78,15 @@ Using cmake you can generate project files for Visual Studio,XCode,etc.
For single-configuration generators (like "Unix Makefiles") you can generate and build a specific configuration (e.g. "RelWithDebInfo") using:

```shell
mkdir build_RelWithDebInfo
cd build_RelWithDebInfo
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake --build . --config RelWithDebInfo
cmake -S . -B build_RelWithDebInfo -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
cmake --build build_RelWithDebInfo --config RelWithDebInfo
```

For multi-configuration generators (like "Visual Studio 17 2022") the same is achieved using:

```shell
mkdir build
cd build
cmake ..
cmake --build . --config RelWithDebInfo
cmake -S . -B build
cmake --build build --config RelWithDebInfo
```

### Visual Studio
Expand Down Expand Up @@ -182,47 +174,48 @@ For debugging create a launch.json file in the .vscode folder with the following
The PCRE dll is needed to build the CLI. It can be downloaded here:
http://software-download.name/pcre-library-windows/

### GNU make
### GNU compilers

#### GNU make

Simple, unoptimized build (no dependencies):

```shell
make
```

You can use `CXXOPTS` and `LDOPTS` to append to the existing `CXXFLAGS` and `LDFLAGS` instead of overriding them.

The recommended release build is:

```shell
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2 -DNDEBUG"
```

Flags:
#### g++ (for experts)

1. `MATCHCOMPILER=yes`
Python is used to optimise cppcheck. The Token::Match patterns are converted into C++ code at compile time.
If you just want to build Cppcheck without dependencies then you can use this command:

2. `FILESDIR=/usr/share/cppcheck`
Specify folder where cppcheck files are installed (addons, cfg, platform)
```shell
g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 -Iexternals/picojson -Ilib -Ifrontend frontend/*.cpp cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/tinyxml2.cpp
```

3. `HAVE_RULES=yes`
Enable rules (PCRE is required if this is used)
#### Flags

4. `CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"`
Enables most compiler optimizations, disables cppcheck-internal debugging code and enables basic compiler warnings.
- `MATCHCOMPILER=yes`
Several `Token` matching patterns are converted into more efficient C++ code at compile time (requires Python to be installed).

### g++ (for experts)
- `FILESDIR=/usr/share/cppcheck`
Specifies the folder where cppcheck files (addons, cfg, platform) are installed to.

If you just want to build Cppcheck without dependencies then you can use this command:
- `HAVE_RULES=yes`
Enables rules (requires PCRE to be installed).

```shell
g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 -Iexternals/picojson -Ilib cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/*.cpp
```

If you want to use `--rule` and `--rule-file` then dependencies are needed:
- `CXXOPTS="-O2 -DNDEBUG"`
Enables most compiler optimizations and disables assertions.

```shell
g++ -o cppcheck -std=c++11 -lpcre -DHAVE_RULES -Ilib -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml2 cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml2/*.cpp
```
- `HAVE_BOOST=yes`
Enables usage of more efficient container from Boost (requires Boost to be installed).

### MinGW

Expand Down
4 changes: 2 additions & 2 deletions readmeja.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ make
推奨するリリースビルド方法:

```shell
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2 -DNDEBUG"
```

フラグ:
Expand All @@ -86,7 +86,7 @@ cppcheckの設定ファイル(addon や cfg や platform)を置くディレク
3. `HAVE_RULES=yes`
ルール機能の有効化 (ルール機能には PCRE が必要です)設定です。

4. `CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function"`
4. `CXXOPTS="-O2 -DNDEBUG"`
ほとんどのコンパイラの最適化オプション、cppcheckの内部デバッグコードの無効化、基本的なコンパイラ警告の有効化

### g++ (エキスパート向け)
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Deprecations:

Other:
- Removed deprecated support for builds with Qt5.
- Added make variables `CXXOPTS` and `LDOPTS` to extend existing `CXXFLAGS` and `LDFLAGS`.
-
2 changes: 1 addition & 1 deletion test/scripts/testrunner-single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -n "$1" ]; then
testrunner_bin=$1
else
make -s -C "$SCRIPT_DIR/../.." -j"$(nproc)" testrunner # CXXFLAGS="-g -O2 -w -DHAVE_BOOST"
make -s -C "$SCRIPT_DIR/../.." -j"$(nproc)" testrunner # CXXOPTS="-g -O2 -w -DHAVE_BOOST"
testrunner_bin=$SCRIPT_DIR/../../testrunner
fi

Expand Down
4 changes: 2 additions & 2 deletions tools/bisect/bisect_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def build_cppcheck(bisect_path):
# TODO: older versions do not build because of include changes in libstdc++ - check compiler version and try to use an earlier one
# TODO: make jobs configurable
# TODO: use "make install"?
# TODO: allow CXXFLAGS overrides to workaround compiling issues in older versions
# TODO: use CXXOPTS overrides to workaround compiling issues in older versions
print('building {}'.format(commit_hash))
subprocess.check_call(['make', '-C', bisect_repo_dir, '-j6', 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -w -pipe', '-s'])
subprocess.check_call(['make', '-C', bisect_repo_dir, '-j6', 'MATCHCOMPILER=yes', 'CXXOPTS=-O2 -w -pipe', '-s'])

# TODO: remove folder if installation failed
print('installing {}'.format(commit_hash))
Expand Down
2 changes: 1 addition & 1 deletion tools/compare-valueflow-options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Compare results and timings of different valueflow options
# Example usage:
# cd ~/cppcheck && make CXXFLAGS=-O2 MATCHCOMPILER=yes
# cd ~/cppcheck && make CXXOPTS=-O2 MATCHCOMPILER=yes
# python3 compare-valueflow-options.py --cppcheck-path=~/cppcheck --packages-path=~/daca2-packages

import donate_cpu_lib as lib
Expand Down
3 changes: 3 additions & 0 deletions tools/dmake/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ int main(int argc, char **argv)
<< " $(error invalid HAVE_RULES value '$(HAVE_RULES)')\n"
<< "endif\n\n";

fout << "override CXXFLAGS += $(CXXOPTS)\n";
fout << "override LDFLAGS += $(LDOPTS)\n\n";

makeConditionalVariable(fout, "PREFIX", "/usr");
makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2");
makeConditionalVariable(fout, "INCLUDE_FOR_FE", "-Ilib");
Expand Down
4 changes: 2 additions & 2 deletions tools/donate_cpu_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes)
CLIENT_VERSION = "1.3.67"
CLIENT_VERSION = "1.3.68"

# Timeout for analysis with Cppcheck in seconds
CPPCHECK_TIMEOUT = 30 * 60
Expand Down Expand Up @@ -217,7 +217,7 @@ def compile_cppcheck(cppcheck_path):
# TODO: processes still exhaust all threads of the system
subprocess.check_call([__make_cmd, '-t:cli', os.path.join(cppcheck_path, 'cppcheck.sln'), '/property:Configuration=Release;Platform=x64'], cwd=cppcheck_path, env=build_env)
else:
build_cmd = [__make_cmd, __jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g -w']
build_cmd = [__make_cmd, __jobs, 'MATCHCOMPILER=yes', 'CXXOPTS=-O2 -g -w']
build_env = os.environ
if __make_cmd == 'mingw32-make':
# TODO: MinGW will always link even if no changes are present
Expand Down
Loading