Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42535 #25

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
57 changes: 50 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ ifndef RUNTESTS
RUNTESTS = 1
endif

ifndef PCH
PCH = 1
endif

# Auto-detect MSYS2
ifdef MSYSTEM
MSYS2 = 1
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand All @@ -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 $@
Expand All @@ -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)
Expand Down Expand Up @@ -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 $^
Expand Down
55 changes: 55 additions & 0 deletions pch/pch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <chrono>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <system_error>
#include <tuple>
#include <typeinfo>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
5 changes: 5 additions & 0 deletions src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 44 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions tests/algo_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <algorithm>
Expand Down
1 change: 1 addition & 0 deletions tests/item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions tests/pch/pch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CATCH_CONFIG_ALL_PARTS
#include "catch/catch.hpp"
4 changes: 4 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <cassert>
Expand Down
19 changes: 19 additions & 0 deletions update-pch.sh
Original file line number Diff line number Diff line change
@@ -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