Skip to content

Commit 2221216

Browse files
committed
cppflags
1 parent 74efb99 commit 2221216

8 files changed

Lines changed: 38 additions & 26 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jobs:
213213
- name: Build with TEST_MATHLIB_VALUE
214214
run: |
215215
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
216-
make -j$(nproc) CXXOPTS="-Werror -DTEST_MATHLIB_VALUE" all
216+
make -j$(nproc) CXXOPTS="-Werror" CPPOPTS="-DTEST_MATHLIB_VALUE" all
217217
218218
- name: Test with TEST_MATHLIB_VALUE
219219
run: |
@@ -570,7 +570,7 @@ jobs:
570570
run: |
571571
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
572572
# compile with verification and ast matchers
573-
make -j$(nproc) -s CPPFLAGS="-DCHECK_INTERNAL" CXXOPTS="-Werror -g -O2 -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
573+
make -j$(nproc) -s CXXOPTS="-Werror -g -O2" CPPOPTS="-DCHECK_INTERNAL -DHAVE_BOOST" MATCHCOMPILER=yes VERIFY=1
574574
575575
- name: CMake
576576
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="-Werror -O2 -DHAVE_BOOST -gdwarf-4 -mllvm -inline-deferral" MATCHCOMPILER=yes
59+
make -j$(nproc) -s CXXOPTS="-Werror -O2 -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="-Werror -O1 -g -DHAVE_BOOST" make -j$(nproc) HAVE_RULES=yes MATCHCOMPILER=yes
44+
CXXOPTS="-Werror -O1 -g" 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="-Werror -O1 -g -DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
49+
CXXOPTS="-Werror -O1 -g" CPPOPTS="-DHAVE_BOOST" make -j$(nproc) testrunner HAVE_RULES=yes MATCHCOMPILER=yes
5050
5151
- name: Run valgrind
5252
run: |

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ ifeq (clang++, $(findstring clang++,$(CXX)))
132132
CPPCHK_GLIBCXX_DEBUG=
133133
endif
134134
ifndef CXXFLAGS
135-
CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-sign-compare -Wno-multichar -Woverloaded-virtual -Wno-dollar-in-identifier-extension $(CPPCHK_GLIBCXX_DEBUG) -g
135+
CXXFLAGS=-pedantic -Wall -Wextra -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-sign-compare -Wno-multichar -Woverloaded-virtual -Wno-dollar-in-identifier-extension -g
136136
endif
137137

138+
override CPPFLAGS += $(CPPCHK_GLIBCXX_DEBUG)
139+
138140
ifeq (g++, $(findstring g++,$(CXX)))
139141
override CXXFLAGS += -pipe
140142
endif
@@ -144,7 +146,8 @@ ifeq ($(HAVE_RULES),yes)
144146
ifeq ($(PCRE_CONFIG),)
145147
$(error Did not find pcre-config)
146148
endif
147-
override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)
149+
override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)
150+
override CPPFLAGS += -DHAVE_RULES
148151
ifdef LIBS
149152
LIBS += $(shell $(PCRE_CONFIG) --libs)
150153
else
@@ -155,6 +158,7 @@ else ifneq ($(HAVE_RULES),)
155158
endif
156159

157160
override CXXFLAGS += $(CXXOPTS)
161+
override CPPFLAGS += $(CPPOPTS)
158162
override LDFLAGS += $(LDOPTS)
159163

160164
ifndef PREFIX
@@ -355,12 +359,12 @@ TESTOBJ = test/fixture.o \
355359
###### Targets
356360

357361
cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)
358-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
362+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
359363

360364
all: cppcheck testrunner
361365

362366
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)
367+
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
364368

365369
test: all
366370
./testrunner

oss-fuzz/Makefile

Lines changed: 4 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,7 @@ 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+
CXXFLAGS=-std=c++11 -g -w $(INCS)
3535

3636
LIBOBJ = $(libcppdir)/valueflow.o \
3737
$(libcppdir)/tokenize.o \
@@ -106,10 +106,10 @@ EXTOBJ = simplecpp.o \
106106
tinyxml2.o
107107

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

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

114114
translate: translate.o type2.o
115115
${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
-

tools/dmake/dmake.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,23 +351,23 @@ 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 << "CXXFLAGS=-std=c++11 -g -w $(INCS)\n";
361361
fout << '\n';
362362
fout << "LIBOBJ = " << objfiles(libfiles_prio) << "\n";
363363
fout << '\n';
364364
fout << "EXTOBJ = " << objfiles(extfiles) << "\n";
365365
fout << '\n';
366366
fout << "oss-fuzz-client: $(EXTOBJ) $(LIBOBJ) main.o type2.o\n";
367-
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
367+
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^ ${LIB_FUZZING_ENGINE}\n";
368368
fout << '\n';
369369
fout << "no-fuzz: $(EXTOBJ) $(LIBOBJ) main_nofuzz.o type2.o\n";
370-
fout << "\t${CXX} $(CPPFLAGS) ${CXXFLAGS} -o $@ $^\n";
370+
fout << "\t${CXX} ${CXXFLAGS} -o $@ $^\n";
371371
fout << '\n';
372372
fout << "translate: translate.o type2.o\n";
373373
fout << "\t${CXX} -std=c++11 -g ${CXXFLAGS} -o $@ type2.cpp translate.cpp\n";
@@ -708,7 +708,8 @@ int main(int argc, char **argv)
708708

709709
// Makefile settings..
710710
if (release) {
711-
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-multichar");
711+
makeConditionalVariable(fout, "CXXFLAGS", "-O2 -Wall -Wno-sign-compare -Wno-multichar");
712+
fout << "override CPPFLAGS += -DNDEBUG\n\n";
712713
} else {
713714
makeConditionalVariable(fout, "CXXFLAGS",
714715
"-pedantic "
@@ -726,8 +727,8 @@ int main(int argc, char **argv)
726727
"-Wno-multichar "
727728
"-Woverloaded-virtual "
728729
"-Wno-dollar-in-identifier-extension " // occurs in testrunner only
729-
"$(CPPCHK_GLIBCXX_DEBUG) "
730730
"-g");
731+
fout << "override CPPFLAGS += $(CPPCHK_GLIBCXX_DEBUG)\n\n";
731732
}
732733

733734
fout << "ifeq (g++, $(findstring g++,$(CXX)))\n"
@@ -741,7 +742,8 @@ int main(int argc, char **argv)
741742
<< " ifeq ($(PCRE_CONFIG),)\n"
742743
<< " $(error Did not find pcre-config)\n"
743744
<< " endif\n"
744-
<< " override CXXFLAGS += -DHAVE_RULES $(shell $(PCRE_CONFIG) --cflags)\n"
745+
<< " override CXXFLAGS += $(shell $(PCRE_CONFIG) --cflags)\n"
746+
<< " override CPPFLAGS += -DHAVE_RULES\n"
745747
<< " ifdef LIBS\n"
746748
<< " LIBS += $(shell $(PCRE_CONFIG) --libs)\n"
747749
<< " else\n"
@@ -752,6 +754,7 @@ int main(int argc, char **argv)
752754
<< "endif\n\n";
753755

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

757760
makeConditionalVariable(fout, "PREFIX", "/usr");
@@ -776,7 +779,7 @@ int main(int argc, char **argv)
776779
fout << ".PHONY: run-dmake tags\n\n";
777780
fout << "\n###### Targets\n\n";
778781
fout << "cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)\n";
779-
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
782+
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
780783
fout << "all:\tcppcheck testrunner\n\n";
781784
std::string testrunner_clifiles_o;
782785
for (const std::string &clifile: clifiles) {
@@ -787,7 +790,7 @@ int main(int argc, char **argv)
787790
testrunner_clifiles_o += o;
788791
}
789792
fout << "testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) $(FEOBJ)" << testrunner_clifiles_o << "\n";
790-
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
793+
fout << "\t$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n";
791794
fout << "test:\tall\n";
792795
fout << "\t./testrunner\n\n";
793796
fout << "check:\tall\n";

0 commit comments

Comments
 (0)