diff --git a/.gitignore b/.gitignore index e5a0613ca1770..df84991f444d1 100644 --- a/.gitignore +++ b/.gitignore @@ -191,3 +191,9 @@ Xcode/ /.flatpak-builder/ /repo/ /build-dir/ + +# precompiled headers +/pch/pch.hpp.gch +/pch/pch.hpp.pch +/tests/pch/pch.hpp.gch +/tests/pch/pch.hpp.pch diff --git a/.travis.yml b/.travis.yml index 1407fad2adce4..92e212b793b95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,6 +65,12 @@ jobs: packages: ["clang-3.8"] sources: [*apt_sources] + env: CLANG=clang++ NATIVE=osx OSX_MIN=10.13 TILES=1 SOUND=1 BREWGETTEXT=1 + name: "Xcode 10.1 Make build with Tiles and sound (macOS)" + os: osx + osx_image: xcode10.1 + compiler: clang + # Then build different configurations and targets in parallel. - stage: "Main Compilers" env: COMPILER=g++ MODS=--mods=magiclysm LOCALIZE=0 @@ -118,12 +124,6 @@ jobs: directories: - $HOME/.ccache - - env: CLANG=clang++ NATIVE=osx OSX_MIN=10.13 TILES=1 SOUND=1 BREWGETTEXT=1 - name: "Xcode 10.1 Make build with Tiles and sound (macOS)" - os: osx - osx_image: xcode10.1 - compiler: clang - # Finally check the compiler variants - stage: compilers # GCC 5.4 is default on Xenial diff --git a/Makefile b/Makefile index a9763177ea4f8..160e3068a75ca 100644 --- a/Makefile +++ b/Makefile @@ -172,6 +172,10 @@ ifndef RUNTESTS RUNTESTS = 1 endif +ifndef PCH + PCH = 1 +endif + # Auto-detect MSYS2 ifdef MSYSTEM MSYS2 = 1 @@ -233,6 +237,12 @@ ifneq ($(findstring BSD,$(OS)),) BSD = 1 endif +ifeq ($(PCH), 1) + CCACHEBIN = CCACHE_SLOPPINESS=pch_defines,time_macros ccache +else + CCACHEBIN = ccache +endif + # This sets CXX and so must be up here ifneq ($(CLANG), 0) # Allow setting specific CLANG version @@ -249,8 +259,8 @@ ifneq ($(CLANG), 0) LDFLAGS += -stdlib=libc++ endif ifeq ($(CCACHE), 1) - CXX = CCACHE_CPP2=1 ccache $(CROSS)$(CLANGCMD) - LD = CCACHE_CPP2=1 ccache $(CROSS)$(CLANGCMD) + CXX = CCACHE_CPP2=1 $(CCACHEBIN) $(CROSS)$(CLANGCMD) + LD = CCACHE_CPP2=1 $(CCACHEBIN) $(CROSS)$(CLANGCMD) else CXX = $(CROSS)$(CLANGCMD) LD = $(CROSS)$(CLANGCMD) @@ -267,8 +277,8 @@ else # Appears that the default value of $LD is unsuitable on most systems OS_LINKER := $(CXX) ifeq ($(CCACHE), 1) - CXX = ccache $(CROSS)$(OS_COMPILER) - LD = ccache $(CROSS)$(OS_LINKER) + CXX = $(CCACHEBIN) $(CROSS)$(OS_COMPILER) + LD = $(CCACHEBIN) $(CROSS)$(OS_LINKER) else CXX = $(CROSS)$(OS_COMPILER) LD = $(CROSS)$(OS_LINKER) @@ -385,6 +395,35 @@ ifeq ($(CYGWIN),1) WARNINGS += -Wimplicit-fallthrough=0 endif +ifeq ($(PCH), 1) + PCHFLAGS = -Ipch -Winvalid-pch + PCH_H = pch/pch.hpp + + ifeq ($(CLANG), 0) + PCHFLAGS += -fpch-preprocess -include pch.hpp + PCH_P = pch/pch.hpp.gch + else + PCH_P = pch/pch.hpp.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) + PCHFLAGS = "" + PCH_H = "" + PCH_P = "" + PCH = 0 + $(warning your clang version does not support -fno-pch-timestamp: $(CLANGVER) ($(.SHELLSTATUS))) + else + CXXFLAGS += -Xclang -fno-pch-timestamp + endif + endif + + endif +endif + CXXFLAGS += $(WARNINGS) $(DEBUG) $(DEBUGSYMS) $(PROFILE) $(OTHERS) -MMD -MP TOOL_CXXFLAGS = -DCATA_IN_TOOL @@ -852,6 +891,9 @@ ifeq ($(RELEASE), 1) endif endif +$(PCH_P): $(PCH_H) + -$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -c $(PCH_H) -o $(PCH_P) + $(BUILD_PREFIX)$(TARGET_NAME).a: $(OBJS) $(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS)) @@ -866,8 +908,8 @@ version: # Unconditionally create the object dir on every invocation. $(shell mkdir -p $(ODIR)) -$(ODIR)/%.o: $(SRC_DIR)/%.cpp - $(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) -c $< -o $@ +$(ODIR)/%.o: $(SRC_DIR)/%.cpp $(PCH_P) + $(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) $(PCHFLAGS) -c $< -o $@ $(ODIR)/%.o: $(SRC_DIR)/%.rc $(RC) $(RFLAGS) $< -o $@ @@ -892,6 +934,7 @@ clean: clean-tests rm -rf *$(BINDIST_DIR) *cataclysmdda-*.tar.gz *cataclysmdda-*.zip rm -f $(SRC_DIR)/version.h rm -f $(CHKJSON_BIN) + rm -f pch/pch.hpp.{gch,pch} distclean: rm -rf *$(BINDIST_DIR) @@ -1075,7 +1118,7 @@ ifdef LANGUAGES endif $(BINDIST_CMD) -export ODIR _OBJS LDFLAGS CXX W32FLAGS DEFINES CXXFLAGS TARGETSYSTEM +export ODIR _OBJS LDFLAGS CXX W32FLAGS DEFINES CXXFLAGS TARGETSYSTEM CLANG PCH ctags: $(ASTYLE_SOURCES) ctags $^ diff --git a/pch/pch.hpp b/pch/pch.hpp new file mode 100644 index 0000000000000..0aa757f958987 --- /dev/null +++ b/pch/pch.hpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/src/translations.cpp b/src/translations.cpp index 24575297b2554..f9b858033a717 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -728,3 +728,8 @@ bool localized_comparator::operator()( const std::wstring &l, const std::wstring return std::locale()( l, r ); #endif } + +// silence -Wunused-macro +#ifdef __STRICT_ANSI__ +#undef __STRICT_ANSI__ +#endif diff --git a/tests/Makefile b/tests/Makefile index ee605aaed32e0..1d87c3921b0a1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -23,6 +23,43 @@ LDFLAGS += -L. CXXFLAGS += -I../src -Wno-unused-variable -Wno-sign-compare -Wno-unknown-pragmas -Wno-parentheses -MMD -MP CXXFLAGS += -Wall -Wextra +ifndef PCH + PCH = 1 +endif + +ifndef CLANG + CLANG = 0 +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 +endif + ifeq ($(TARGETSYSTEM), WINDOWS) TEST_TARGET = $(BUILD_PREFIX)cata_test.exe else @@ -31,11 +68,11 @@ endif tests: $(TEST_TARGET) -$(TEST_TARGET): $(OBJS) $(CATA_LIB) precompile_header - +$(CXX) $(W32FLAGS) -o $@ $(DEFINES) $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(LDFLAGS) +$(TEST_TARGET): $(OBJS) $(CATA_LIB) + +$(CXX) $(W32FLAGS) -o $@ $(DEFINES) $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(PCHFLAGS) $(LDFLAGS) -precompile_header: - -$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -Wno-non-virtual-dtor -Wno-unused-macros -DCATCH_CONFIG_ENABLE_PAIR_STRINGMAKER -c catch/catch.hpp -o catch/catch.hpp.gch +$(PCH_P): $(PCH_H) + -$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -Wno-non-virtual-dtor -Wno-unused-macros -I. -c $(PCH_H) -o $(PCH_P) # Iterate over all the individual tests. check: $(TEST_TARGET) @@ -44,12 +81,13 @@ check: $(TEST_TARGET) clean: rm -rf *obj *objwin rm -f *cata_test + rm -f pch/pch.hpp.{gch,pch} #Unconditionally create object directory on invocation. $(shell mkdir -p $(ODIR)) -$(ODIR)/%.o: %.cpp - $(CXX) $(CPPFLAGS) $(DEFINES) -DCATCH_CONFIG_ENABLE_PAIR_STRINGMAKER $(CXXFLAGS) -c $< -o $@ +$(ODIR)/%.o: %.cpp $(PCH_P) + $(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) $(PCHFLAGS) -c $< -o $@ .PHONY: clean check tests precompile_header diff --git a/tests/algo_test.cpp b/tests/algo_test.cpp index 779367d2a0f4e..73a7d42919d30 100644 --- a/tests/algo_test.cpp +++ b/tests/algo_test.cpp @@ -1,7 +1,5 @@ #pragma GCC diagnostic ignored "-Wunused-macros" -#ifndef CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER #define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER -#endif #include "catch/catch.hpp" #include diff --git a/tests/item_test.cpp b/tests/item_test.cpp index b019ae2caed6d..256eaf6c5a8c3 100644 --- a/tests/item_test.cpp +++ b/tests/item_test.cpp @@ -12,6 +12,7 @@ #include "math_defines.h" #include "monstergenerator.h" #include "ret_val.h" +#include "math_defines.h" #include "units.h" #include "value_ptr.h" diff --git a/tests/pch/pch.hpp b/tests/pch/pch.hpp new file mode 100644 index 0000000000000..de135ad03ed66 --- /dev/null +++ b/tests/pch/pch.hpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_ALL_PARTS +#include "catch/catch.hpp" diff --git a/tests/test_main.cpp b/tests/test_main.cpp index e016ae77deb70..ac113176d5ba4 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -12,6 +12,10 @@ #endif // __GLIBCXX__ #endif // _GLIBCXX_DEBUG +#ifdef CATA_CATCH_PCH +#undef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define CATCH_CONFIG_IMPL_ONLY +#endif #define CATCH_CONFIG_RUNNER #include #include diff --git a/update-pch.sh b/update-pch.sh new file mode 100755 index 0000000000000..18b4429838764 --- /dev/null +++ b/update-pch.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +suffix=`date|md5sum|awk '{print $1}'` +tpchr=/tmp/_pchr_$suffix.hpp +tpch=/tmp/_pch_$suffix.hpp +pch=pch/pch.hpp + +grep '#include <' -R src|grep -v 'NOPCH'|awk -F '[: ]' '{print $2 " " $3}' > $tpchr +grep -v '\.h' $tpchr|sort|uniq >> $tpch + +if [[ `diff $tpch $pch` != '' ]]; then + diff $pch $tpch + cp $tpch $pch + echo pch **updated** +else + echo pch up to date +fi + +rm $tpch $tpchr