diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml index a8c27b17224..fa7cfb1cfe5 100644 --- a/.github/workflows/CI-mingw.yml +++ b/.github/workflows/CI-mingw.yml @@ -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 diff --git a/.github/workflows/CI-unixish-docker.yml b/.github/workflows/CI-unixish-docker.yml index f8a74b4d8f7..04b8d372948 100644 --- a/.github/workflows/CI-unixish-docker.yml +++ b/.github/workflows/CI-unixish-docker.yml @@ -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: | diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 9b720b95b4a..426cca90c4a 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -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: | @@ -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: | diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3c0c8e1d1df..3b41862ba93 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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: | diff --git a/.github/workflows/cppcheck-premium.yml b/.github/workflows/cppcheck-premium.yml index 87aa920193e..546858e5de3 100644 --- a/.github/workflows/cppcheck-premium.yml +++ b/.github/workflows/cppcheck-premium.yml @@ -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 diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index 3394604d155..3e97904c2ec 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -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: @@ -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: | diff --git a/.github/workflows/selfcheck.yml b/.github/workflows/selfcheck.yml index 69aab78db07..434fe579f91 100644 --- a/.github/workflows/selfcheck.yml +++ b/.github/workflows/selfcheck.yml @@ -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 diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml index 7fd16382802..04a5e0cef2a 100644 --- a/.github/workflows/valgrind.yml +++ b/.github/workflows/valgrind.yml @@ -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: | diff --git a/Makefile b/Makefile index 9ba42bb6bb1..e3fff8d2ac2 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/createrelease b/createrelease index f9ed0e6a2bc..b17ce52acc0 100755 --- a/createrelease +++ b/createrelease @@ -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) @@ -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 diff --git a/generate_coverage_report b/generate_coverage_report index df29b8ff5c6..3f12cea7e0f 100755 --- a/generate_coverage_report +++ b/generate_coverage_report @@ -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 ./ diff --git a/readme.md b/readme.md index 41ad4010925..b397b3f3826 100644 --- a/readme.md +++ b/readme.md @@ -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. @@ -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. @@ -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 @@ -182,7 +174,9 @@ 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): @@ -190,39 +184,38 @@ Simple, unoptimized build (no dependencies): 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 diff --git a/readmeja.md b/readmeja.md index e731873ba3e..6d9dae60c95 100644 --- a/readmeja.md +++ b/readmeja.md @@ -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" ``` フラグ: @@ -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++ (エキスパート向け) diff --git a/releasenotes.txt b/releasenotes.txt index f1bfa642c56..9cdf8ceb1df 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -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`. - diff --git a/test/scripts/testrunner-single.sh b/test/scripts/testrunner-single.sh index 072779a2730..2e449b0f430 100755 --- a/test/scripts/testrunner-single.sh +++ b/test/scripts/testrunner-single.sh @@ -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 diff --git a/tools/bisect/bisect_common.py b/tools/bisect/bisect_common.py index 9b296ad0c17..d1cb3824b51 100644 --- a/tools/bisect/bisect_common.py +++ b/tools/bisect/bisect_common.py @@ -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)) diff --git a/tools/compare-valueflow-options.py b/tools/compare-valueflow-options.py index b6a31d701de..11b7cf87d42 100755 --- a/tools/compare-valueflow-options.py +++ b/tools/compare-valueflow-options.py @@ -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 diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index e5748ebf389..df6fc2e4e49 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -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"); diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 04f9daf16b2..ac54486b886 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -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 @@ -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