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
6 changes: 3 additions & 3 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ jobs:
- name: Build with TEST_MATHLIB_VALUE
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make -j$(nproc) CPPFLAGS=-DTEST_MATHLIB_VALUE all
make -j$(nproc) CPPOPTS=-DTEST_MATHLIB_VALUE all

- name: Test with TEST_MATHLIB_VALUE
run: |
make -j$(nproc) CPPFLAGS=-DTEST_MATHLIB_VALUE check
make -j$(nproc) CPPOPTS=-DTEST_MATHLIB_VALUE check

check_nonneg:

Expand Down Expand Up @@ -611,7 +611,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" CXXOPTS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
make -j$(nproc) -s CXXOPTS="-g -O2 -w" CPPOPTS="-DCHECK_INTERNAL -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1

- name: CMake
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 CXXOPTS="-O2 -w -DHAVE_BOOST -gdwarf-4 -mllvm -inline-deferral" MATCHCOMPILER=yes
make -j$(nproc) -s CXXOPTS="-O2 -w -gdwarf-4" CPPOPTS="-DHAVE_BOOST -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"
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes
CXXOPTS="-O1 -g -w" CPPOPTS="-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"
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
CXXOPTS="-O1 -g -w" CPPOPTS="-DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes

- name: Run valgrind
run: |
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ ifeq ($(HAVE_RULES),yes)
ifeq ($(PCRE_CONFIG),)
$(error Did not find pcre-config)
endif
override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)
override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)
override CPPFLAGS += -DHAVE_RULES
ifdef LIBS
LIBS += $(shell $(PCRE_CONFIG) --libs)
else
Expand All @@ -155,6 +156,7 @@ else ifneq ($(HAVE_RULES),)
endif

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

ifndef PREFIX
Expand Down Expand Up @@ -355,12 +357,12 @@ TESTOBJ = test/fixture.o \
###### Targets

cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)

all: cppcheck testrunner

testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) $(FEOBJ) cli/cmdlineparser.o cli/cppcheckexecutor.o cli/executor.o cli/filelister.o cli/processexecutor.o cli/sehwrapper.o cli/signalhandler.o cli/singleexecutor.o cli/stacktrace.o cli/threadexecutor.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)

test: all
./testrunner
Expand Down
14 changes: 10 additions & 4 deletions oss-fuzz/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dmake, do not edit.

# make CXX=clang++ MATCHCOMPILER=yes CXXFLAGS="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -DHAVE_BOOST" LIB_FUZZING_ENGINE="-fsanitize=fuzzer" oss-fuzz-client
# make CXX=clang++ MATCHCOMPILER=yes CXXOPTS="-O1 -fno-omit-frame-pointer -gline-tables-only -fsanitize=address -fsanitize-address-use-after-scope" CPPOPTS="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DHAVE_BOOST" LIB_FUZZING_ENGINE="-fsanitize=fuzzer" oss-fuzz-client

MATCHCOMPILER=yes
ifndef MATCHCOMPILER
Expand Down Expand Up @@ -31,7 +31,13 @@ else
endif

INCS=-I../lib -isystem../externals/simplecpp -isystem../externals/tinyxml2 -isystem../externals/picojson
CPPFLAGS=-std=c++11 -g -w $(INCS)

override CXXFLAGS+=-std=c++11 -g -w
override CPPFLAGS+=$(INCS)

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

LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/tokenize.o \
Expand Down Expand Up @@ -106,10 +112,10 @@ EXTOBJ = simplecpp.o \
tinyxml2.o

oss-fuzz-client: $(EXTOBJ) $(LIBOBJ) main.o type2.o
${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}
${CXX} ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}

no-fuzz: $(EXTOBJ) $(LIBOBJ) main_nofuzz.o type2.o
${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^
${CXX} ${CXXFLAGS} -o $@ $^

translate: translate.o type2.o
${CXX} -std=c++11 -g ${CXXFLAGS} -o $@ type2.cpp translate.cpp
Expand Down
11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ Simple, unoptimized build (no dependencies):
make
```

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

The recommended release build is:

```shell
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2 -DNDEBUG"
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2" CPPOPTS="-DNDEBUG"
```

#### g++ (for experts)
Expand All @@ -211,8 +211,11 @@ g++ -o cppcheck -std=c++11 -Iexternals -Iexternals/simplecpp -Iexternals/tinyxml
- `HAVE_RULES=yes`
Enables rules (requires PCRE to be installed).

- `CXXOPTS="-O2 -DNDEBUG"`
Enables most compiler optimizations and disables assertions.
- `CXXOPTS="-O2"`
Enables most compiler optimizations.

- `CPPOPTS="-DNDEBUG"`
Disables assertions.

- `HAVE_BOOST=yes`
Enables usage of more efficient container from Boost (requires Boost to be installed).
Expand Down
2 changes: 2 additions & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ Deprecations:
Other:
- Removed deprecated support for builds with Qt5.
- Added make variables `CXXOPTS` and `LDOPTS` to extend existing `CXXFLAGS` and `LDFLAGS`.
- Added make variables `CPPOPTS` to extend existing `CPPFLAGS`.
- `CPPFLAGS` are not longer being passed to the linker command for `cppcheck` and `testrunner`.
-
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 # CXXOPTS="-g -O2 -w -DHAVE_BOOST"
make -s -C "$SCRIPT_DIR/../.." -j"$(nproc)" testrunner # CXXOPTS="-g -O2 -w" CPPOPTS="-DHAVE_BOOST"
testrunner_bin=$SCRIPT_DIR/../../testrunner
fi

Expand Down
27 changes: 18 additions & 9 deletions tools/dmake/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,29 @@ static void write_ossfuzz_makefile(std::vector<std::string> libfiles_prio, std::

fout << "# This file is generated by dmake, do not edit.\n";
fout << '\n';
fout << "# make CXX=clang++ MATCHCOMPILER=yes CXXFLAGS=\"-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -DHAVE_BOOST\" LIB_FUZZING_ENGINE=\"-fsanitize=fuzzer\" oss-fuzz-client\n";
fout << "# make CXX=clang++ MATCHCOMPILER=yes CXXOPTS=\"-O1 -fno-omit-frame-pointer -gline-tables-only -fsanitize=address -fsanitize-address-use-after-scope\" CPPOPTS=\"-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DHAVE_BOOST\" LIB_FUZZING_ENGINE=\"-fsanitize=fuzzer\" oss-fuzz-client\n";
fout << '\n';
fout << "MATCHCOMPILER=yes\n"; // always need to enable the matchcompiler so the library files are being copied
makeMatchcompiler(fout, "../", "--read-dir ../lib");

fout << "INCS=-I../lib -isystem../externals/simplecpp -isystem../externals/tinyxml2 -isystem../externals/picojson\n";
fout << "CPPFLAGS=-std=c++11 -g -w $(INCS)\n";
fout << '\n';
fout << "override CXXFLAGS+=-std=c++11 -g -w\n";
fout << "override CPPFLAGS+=$(INCS)\n";
fout << '\n';
fout << "override CXXFLAGS += $(CXXOPTS)\n";
fout << "override CPPFLAGS += $(CPPOPTS)\n";
fout << "override LDFLAGS += $(LDOPTS)\n";
fout << '\n';
fout << "LIBOBJ = " << objfiles(libfiles_prio) << "\n";
fout << '\n';
fout << "EXTOBJ = " << objfiles(extfiles) << "\n";
fout << '\n';
fout << "oss-fuzz-client: $(EXTOBJ) $(LIBOBJ) main.o type2.o\n";
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
fout << '\n';
fout << "no-fuzz: $(EXTOBJ) $(LIBOBJ) main_nofuzz.o type2.o\n";
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^\n";
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^\n";
fout << '\n';
fout << "translate: translate.o type2.o\n";
fout << "\t${CXX} -std=c++11 -g ${CXXFLAGS} -o $@ type2.cpp translate.cpp\n";
Expand Down Expand Up @@ -708,7 +714,8 @@ int main(int argc, char **argv)

// Makefile settings..
if (release) {
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar");
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -Wall -Wno-sign-compare -Wno-multichar");
fout << "override CPPFLAGS += -DNDEBUG\n\n";
} else {
makeConditionalVariable(fout, "CXXFLAGS",
"-pedantic "
Expand All @@ -725,8 +732,8 @@ int main(int argc, char **argv)
"-Wno-sign-compare "
"-Wno-multichar "
"-Woverloaded-virtual "
//"$(CPPCHK_GLIBCXX_DEBUG) " // TODO: when using CXXOPTS this would always be set - need to handle this differently
"-g");
//fout << "override CPPFLAGS += $(CPPCHK_GLIBCXX_DEBUG)\n\n"; // TODO: when using CXXOPTS this would always be set - need to handle this differently
}

fout << "ifeq (g++, $(findstring g++,$(CXX)))\n"
Expand All @@ -740,7 +747,8 @@ int main(int argc, char **argv)
<< " ifeq ($(PCRE_CONFIG),)\n"
<< " $(error Did not find pcre-config)\n"
<< " endif\n"
<< " override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)\n"
<< " override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)\n"
<< " override CPPFLAGS += -DHAVE_RULES\n"
<< " ifdef LIBS\n"
<< " LIBS += $(shell $(PCRE_CONFIG) --libs)\n"
<< " else\n"
Expand All @@ -751,6 +759,7 @@ int main(int argc, char **argv)
<< "endif\n\n";

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

makeConditionalVariable(fout, "PREFIX", "/usr");
Expand All @@ -775,7 +784,7 @@ int main(int argc, char **argv)
fout << ".PHONY: run-dmake tags\n\n";
fout << "\n###### Targets\n\n";
fout << "cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)\n";
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "all:\tcppcheck testrunner\n\n";
std::string testrunner_clifiles_o;
for (const std::string &clifile: clifiles) {
Expand All @@ -786,7 +795,7 @@ int main(int argc, char **argv)
testrunner_clifiles_o += o;
}
fout << "testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) $(FEOBJ)" << testrunner_clifiles_o << "\n";
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
fout << "test:\tall\n";
fout << "\t./testrunner\n\n";
fout << "check:\tall\n";
Expand Down