Skip to content

Commit

Permalink
makefile: clean up pch rules (CleverRaven#42600)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei8l authored Aug 4, 2020
1 parent d3e4f33 commit 09e2591
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Xcode/
/build-dir/

# precompiled headers
/pch/pch.hpp.gch
/pch/pch.hpp.pch
/tests/pch/pch.hpp.gch
/tests/pch/pch.hpp.pch
/pch/main-pch.hpp.gch
/pch/main-pch.hpp.pch
/tests/pch/tests-pch.hpp.gch
/tests/pch/tests-pch.hpp.pch
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,20 @@ endif

ifeq ($(PCH), 1)
PCHFLAGS = -Ipch -Winvalid-pch
PCH_H = pch/pch.hpp
PCH_H = pch/main-pch.hpp

ifeq ($(CLANG), 0)
PCHFLAGS += -fpch-preprocess -include pch.hpp
PCH_P = pch/pch.hpp.gch
PCHFLAGS += -fpch-preprocess -include main-pch.hpp
PCH_P = $(PCH_H).gch
else
PCH_P = pch/pch.hpp.pch
PCH_P = $(PCH_H).pch
PCHFLAGS += -include-pch $(PCH_P)

# FIXME: dirty hack ahead
# ccache won't wort with clang unless it supports -fno-pch-timestamp
ifeq ($(CCACHE), 1)
CLANGVER := $(shell echo 'int main(void){return 0;}'|$(CXX) -Xclang -fno-pch-timestamp -x c++ -o $(ODIR)/__bla__.o - 2>&1)
ifneq ($(.SHELLSTATUS), 0)
CLANGVER := $(shell echo 'int main(void){return 0;}'|$(CXX) -Xclang -fno-pch-timestamp -x c++ -o _clang_ver.o -c - 2>&1 || echo fail)
ifneq ($(CLANGVER),)
PCHFLAGS = ""
PCH_H = ""
PCH_P = ""
Expand Down Expand Up @@ -1118,7 +1118,7 @@ ifdef LANGUAGES
endif
$(BINDIST_CMD)

export ODIR _OBJS LDFLAGS CXX W32FLAGS DEFINES CXXFLAGS TARGETSYSTEM CLANG PCH
export ODIR _OBJS LDFLAGS CXX W32FLAGS DEFINES CXXFLAGS TARGETSYSTEM CLANG PCH PCHFLAGS

ctags: $(ASTYLE_SOURCES)
ctags $^
Expand Down
File renamed without changes.
38 changes: 10 additions & 28 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,14 @@ ifndef CLANG
endif

ifeq ($(PCH), 1)
PCHFLAGS = -Ipch -Winvalid-pch -DCATA_CATCH_PCH
PCH_H = pch/pch.hpp
ifeq ($(CLANG), 0)
PCH_P = pch/pch.hpp.gch
PCHFLAGS += -fpch-preprocess -include pch.hpp
else
PCH_P = pch/pch.hpp.pch
PCHFLAGS += -include-pch $(PCH_P)
CXXFLAGS += -Wno-unused-macros

# FIXME: dirty hack ahead
# ccache won't wort with clang unless it supports -fno-pch-timestamp
ifeq ($(CCACHE), 1)
CLANGVER := $(shell echo 'int main(void){return 0;}'|$(CXX) -Xclang -fno-pch-timestamp -x c++ -o $(ODIR)/__bla__.o - 2>&1)
ifneq ($(.SHELLSTATUS), 0)
$(warning your clang version does not support -fno-pch-timestamp: $(CLANGVER) ($(.SHELLSTATUS)))
undefine PCHFLAGS
undefine PCH_H
undefine PCH_P
PCH = 0
else
CXXFLAGS += -Xclang -fno-pch-timestamp
endif
endif

endif
PCHFLAGS += -DCATA_CATCH_PCH
PCH_H = pch/tests-pch.hpp
ifeq ($(CLANG), 0)
PCH_P = $(PCH_H).gch
else
PCH_P = $(PCH_H).pch
CXXFLAGS += -Wno-unused-macros
endif
endif

ifeq ($(TARGETSYSTEM), WINDOWS)
Expand All @@ -69,7 +51,7 @@ endif
tests: $(TEST_TARGET)

$(TEST_TARGET): $(OBJS) $(CATA_LIB)
+$(CXX) $(W32FLAGS) -o $@ $(DEFINES) $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(PCHFLAGS) $(LDFLAGS)
+$(CXX) $(W32FLAGS) -o $@ $(DEFINES) $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(LDFLAGS)

$(PCH_P): $(PCH_H)
-$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -Wno-non-virtual-dtor -Wno-unused-macros -I. -c $(PCH_H) -o $(PCH_P)
Expand All @@ -87,7 +69,7 @@ clean:
$(shell mkdir -p $(ODIR))

$(ODIR)/%.o: %.cpp $(PCH_P)
$(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) $(PCHFLAGS) -c $< -o $@
$(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) $(subst main-pch,tests-pch,$(PCHFLAGS)) -c $< -o $@

.PHONY: clean check tests precompile_header

Expand Down
1 change: 1 addition & 0 deletions tests/pch/pch.hpp → tests/pch/tests-pch.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#include "../pch/main-pch.hpp"
#define CATCH_CONFIG_ALL_PARTS
#include "catch/catch.hpp"
2 changes: 1 addition & 1 deletion update-pch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
suffix=`date|md5sum|awk '{print $1}'`
tpchr=/tmp/_pchr_$suffix.hpp
tpch=/tmp/_pch_$suffix.hpp
pch=pch/pch.hpp
pch=pch/main-pch.hpp

grep '#include <' -R src|grep -v 'NOPCH'|awk -F '[: ]' '{print $2 " " $3}' > $tpchr
grep -v '\.h' $tpchr|sort|uniq >> $tpch
Expand Down

0 comments on commit 09e2591

Please sign in to comment.