makefile: clean up pch rules (#42600)

This commit is contained in:
andrei 2020-08-05 01:40:04 +03:00 committed by GitHub
parent d3e4f33aeb
commit 09e2591364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 40 deletions

8
.gitignore vendored
View File

@ -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

View File

@ -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 = ""
@ -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 $^

View File

@ -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)
@ -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)
@ -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

View File

@ -1,2 +1,3 @@
#include "../pch/main-pch.hpp"
#define CATCH_CONFIG_ALL_PARTS
#include "catch/catch.hpp"

View File

@ -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