Skip to content

Commit 81aae29

Browse files
committed
fixed #14066 - reworked usage of CPPFLAGS in Makefile
- added make variables `CPPOPTS` to extend existing `CPPFLAGS` - `CPPFLAGS` are not longer being passed to the linker command for `cppcheck` and `testrunner` - added missing handling of `CXXOPTS` and `LDOPTS` for `oss-fuzz`
1 parent 2ee39fe commit 81aae29

File tree

9 files changed

+49
-27
lines changed

9 files changed

+49
-27
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ jobs:
253253
- name: Build with TEST_MATHLIB_VALUE
254254
run: |
255255
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
256-
make -j$(nproc) CPPFLAGS=-DTEST_MATHLIB_VALUE all
256+
make -j$(nproc) CPPOPTS=-DTEST_MATHLIB_VALUE all
257257
258258
- name: Test with TEST_MATHLIB_VALUE
259259
run: |
260-
make -j$(nproc) CPPFLAGS=-DTEST_MATHLIB_VALUE check
260+
make -j$(nproc) CPPOPTS=-DTEST_MATHLIB_VALUE check
261261
262262
check_nonneg:
263263

@@ -611,7 +611,7 @@ jobs:
611611
run: |
612612
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
613613
# compile with verification and ast matchers
614-
make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXOPTS="-g -O2 -w -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
614+
make -j$(nproc) -s CXXOPTS="-g -O2 -w" CPPOPTS="-DCHECK_INTERNAL -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
615615
616616
- name: CMake
617617
run: |

.github/workflows/selfcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
5757
# valgrind cannot handle DWARF 5 yet so force version 4
5858
# work around performance regression with -inline-deferral
59-
make -j$(nproc) -s CXXOPTS="-O2 -w -DHAVE_BOOST -gdwarf-4 -mllvm -inline-deferral" MATCHCOMPILER=yes
59+
make -j$(nproc) -s CXXOPTS="-O2 -w -gdwarf-4" CPPOPTS="-DHAVE_BOOST -mllvm -inline-deferral" MATCHCOMPILER=yes
6060
env:
6161
CC: clang-14
6262
CXX: clang++-14

.github/workflows/valgrind.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
- name: Build cppcheck
4242
run: |
4343
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
44-
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes
44+
CXXOPTS="-O1 -g -w" CPPOPTS="-DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes
4545
4646
- name: Build test
4747
run: |
4848
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
49-
CXXOPTS="-O1 -g -w -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
49+
CXXOPTS="-O1 -g -w" CPPOPTS="-DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
5050
5151
- name: Run valgrind
5252
run: |

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ ifeq ($(HAVE_RULES),yes)
144144
ifeq ($(PCRE_CONFIG),)
145145
$(error Did not find pcre-config)
146146
endif
147-
override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)
147+
override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)
148+
override CPPFLAGS += -DHAVE_RULES
148149
ifdef LIBS
149150
LIBS += $(shell $(PCRE_CONFIG) --libs)
150151
else
@@ -155,6 +156,7 @@ else ifneq ($(HAVE_RULES),)
155156
endif
156157

157158
override CXXFLAGS += $(CXXOPTS)
159+
override CPPFLAGS += $(CPPOPTS)
158160
override LDFLAGS += $(LDOPTS)
159161

160162
ifndef PREFIX
@@ -355,12 +357,12 @@ TESTOBJ = test/fixture.o \
355357
###### Targets
356358

357359
cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)
358-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
360+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
359361

360362
all: cppcheck testrunner
361363

362364
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
363-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
365+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
364366

365367
test: all
366368
./testrunner

oss-fuzz/Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is generated by dmake, do not edit.
22

3-
# 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
3+
# 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
44

55
MATCHCOMPILER=yes
66
ifndef MATCHCOMPILER
@@ -31,7 +31,13 @@ else
3131
endif
3232

3333
INCS=-I../lib -isystem../externals/simplecpp -isystem../externals/tinyxml2 -isystem../externals/picojson
34-
CPPFLAGS=-std=c++11 -g -w $(INCS)
34+
35+
override CXXFLAGS+=-std=c++11 -g -w
36+
override CPPFLAGS+=$(INCS)
37+
38+
override CXXFLAGS += $(CXXOPTS)
39+
override CPPFLAGS += $(CPPOPTS)
40+
override LDFLAGS += $(LDOPTS)
3541

3642
LIBOBJ = $(libcppdir)/valueflow.o \
3743
$(libcppdir)/tokenize.o \
@@ -106,10 +112,10 @@ EXTOBJ = simplecpp.o \
106112
tinyxml2.o
107113

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

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

114120
translate: translate.o type2.o
115121
${CXX} -std=c++11 -g ${CXXFLAGS} -o $@ type2.cpp translate.cpp

readme.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ Simple, unoptimized build (no dependencies):
184184
make
185185
```
186186

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

189189
The recommended release build is:
190190

191191
```shell
192-
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2 -DNDEBUG"
192+
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2" CPPOPTS="-DNDEBUG"
193193
```
194194

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

214-
- `CXXOPTS="-O2 -DNDEBUG"`
215-
Enables most compiler optimizations and disables assertions.
214+
- `CXXOPTS="-O2"`
215+
Enables most compiler optimizations.
216+
217+
- `CPPOPTS="-DNDEBUG"`
218+
Disables assertions.
216219

217220
- `HAVE_BOOST=yes`
218221
Enables usage of more efficient container from Boost (requires Boost to be installed).

releasenotes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ Deprecations:
1818
Other:
1919
- Removed deprecated support for builds with Qt5.
2020
- Added make variables `CXXOPTS` and `LDOPTS` to extend existing `CXXFLAGS` and `LDFLAGS`.
21+
- Added make variables `CPPOPTS` to extend existing `CPPFLAGS`.
22+
- `CPPFLAGS` are not longer being passed to the linker command for `cppcheck` and `testrunner`.
2123
-

test/scripts/testrunner-single.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55
if [ -n "$1" ]; then
66
testrunner_bin=$1
77
else
8-
make -s -C "$SCRIPT_DIR/../.." -j"$(nproc)" testrunner # CXXOPTS="-g -O2 -w -DHAVE_BOOST"
8+
make -s -C "$SCRIPT_DIR/../.." -j"$(nproc)" testrunner # CXXOPTS="-g -O2 -w" CPPOPTS="-DHAVE_BOOST"
99
testrunner_bin=$SCRIPT_DIR/../../testrunner
1010
fi
1111

tools/dmake/dmake.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,23 +351,29 @@ static void write_ossfuzz_makefile(std::vector<std::string> libfiles_prio, std::
351351

352352
fout << "# This file is generated by dmake, do not edit.\n";
353353
fout << '\n';
354-
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";
354+
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";
355355
fout << '\n';
356356
fout << "MATCHCOMPILER=yes\n"; // always need to enable the matchcompiler so the library files are being copied
357357
makeMatchcompiler(fout, "../", "--read-dir ../lib");
358358

359359
fout << "INCS=-I../lib -isystem../externals/simplecpp -isystem../externals/tinyxml2 -isystem../externals/picojson\n";
360-
fout << "CPPFLAGS=-std=c++11 -g -w $(INCS)\n";
360+
fout << '\n';
361+
fout << "override CXXFLAGS+=-std=c++11 -g -w\n";
362+
fout << "override CPPFLAGS+=$(INCS)\n";
363+
fout << '\n';
364+
fout << "override CXXFLAGS += $(CXXOPTS)\n";
365+
fout << "override CPPFLAGS += $(CPPOPTS)\n";
366+
fout << "override LDFLAGS += $(LDOPTS)\n";
361367
fout << '\n';
362368
fout << "LIBOBJ = " << objfiles(libfiles_prio) << "\n";
363369
fout << '\n';
364370
fout << "EXTOBJ = " << objfiles(extfiles) << "\n";
365371
fout << '\n';
366372
fout << "oss-fuzz-client: $(EXTOBJ) $(LIBOBJ) main.o type2.o\n";
367-
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
373+
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
368374
fout << '\n';
369375
fout << "no-fuzz: $(EXTOBJ) $(LIBOBJ) main_nofuzz.o type2.o\n";
370-
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^\n";
376+
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^\n";
371377
fout << '\n';
372378
fout << "translate: translate.o type2.o\n";
373379
fout << "\t${CXX} -std=c++11 -g ${CXXFLAGS} -o $@ type2.cpp translate.cpp\n";
@@ -708,7 +714,8 @@ int main(int argc, char **argv)
708714

709715
// Makefile settings..
710716
if (release) {
711-
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar");
717+
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -Wall -Wno-sign-compare -Wno-multichar");
718+
fout << "override CPPFLAGS += -DNDEBUG\n\n";
712719
} else {
713720
makeConditionalVariable(fout, "CXXFLAGS",
714721
"-pedantic "
@@ -725,8 +732,8 @@ int main(int argc, char **argv)
725732
"-Wno-sign-compare "
726733
"-Wno-multichar "
727734
"-Woverloaded-virtual "
728-
//"$(CPPCHK_GLIBCXX_DEBUG) " // TODO: when using CXXOPTS this would always be set - need to handle this differently
729735
"-g");
736+
//fout << "override CPPFLAGS += $(CPPCHK_GLIBCXX_DEBUG)\n\n"; // TODO: when using CXXOPTS this would always be set - need to handle this differently
730737
}
731738

732739
fout << "ifeq (g++, $(findstring g++,$(CXX)))\n"
@@ -740,7 +747,8 @@ int main(int argc, char **argv)
740747
<< " ifeq ($(PCRE_CONFIG),)\n"
741748
<< " $(error Did not find pcre-config)\n"
742749
<< " endif\n"
743-
<< " override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)\n"
750+
<< " override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)\n"
751+
<< " override CPPFLAGS += -DHAVE_RULES\n"
744752
<< " ifdef LIBS\n"
745753
<< " LIBS += $(shell $(PCRE_CONFIG) --libs)\n"
746754
<< " else\n"
@@ -751,6 +759,7 @@ int main(int argc, char **argv)
751759
<< "endif\n\n";
752760

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

756765
makeConditionalVariable(fout, "PREFIX", "/usr");
@@ -775,7 +784,7 @@ int main(int argc, char **argv)
775784
fout << ".PHONY: run-dmake tags\n\n";
776785
fout << "\n###### Targets\n\n";
777786
fout << "cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)\n";
778-
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
787+
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
779788
fout << "all:\tcppcheck testrunner\n\n";
780789
std::string testrunner_clifiles_o;
781790
for (const std::string &clifile: clifiles) {
@@ -786,7 +795,7 @@ int main(int argc, char **argv)
786795
testrunner_clifiles_o += o;
787796
}
788797
fout << "testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) $(FEOBJ)" << testrunner_clifiles_o << "\n";
789-
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
798+
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
790799
fout << "test:\tall\n";
791800
fout << "\t./testrunner\n\n";
792801
fout << "check:\tall\n";

0 commit comments

Comments
 (0)