1# Make any tests, and possibly run them.
2# A selection of variables are exported from the master Makefile.
3
4# As each test will have a main function we need to handle this file by file.
5# We're using the fairly typical convention that any file ending in _test.cpp
6# is a test executable.
7SOURCES = $(wildcard *.cpp)
8OBJS = $(sort $(SOURCES:%.cpp=$(ODIR)/%.o))
9
10CATA_LIB=../$(BUILD_PREFIX)cataclysm.a
11
12# If you invoke this makefile directly and the parent directory was
13# built with BUILD_PREFIX set, you must set it for this invocation as well.
14ODIR ?= obj
15
16LDFLAGS += -lpthread -L.
17
18# Enabling benchmarks
19DEFINES += -DCATCH_CONFIG_ENABLE_BENCHMARKING
20
21# Allow use of any header files from cataclysm.
22# Catch sections throw unused variable warnings.
23# Add no-sign-compare to fix MXE issue when compiling
24# Catch also uses "#pragma gcc diagnostic", which is not recognized on some supported compilers.
25# Clang and mingw are warning about Catch macros around perfectly normal boolean operations.
26CXXFLAGS += -I../src -Wno-unused-variable -Wno-sign-compare -Wno-unknown-pragmas -Wno-parentheses -MMD -MP
27CXXFLAGS += -Wall -Wextra
28
29ifndef PCH
30  PCH = 1
31endif
32
33ifndef CLANG
34  CLANG = 0
35endif
36
37ifeq ($(PCH), 1)
38PCHFLAGS += -DCATA_CATCH_PCH
39PCH_H = pch/tests-pch.hpp
40ifeq ($(CLANG), 0)
41PCH_P = $(PCH_H).gch
42else
43PCH_P = $(PCH_H).pch
44CXXFLAGS += -Wno-unused-macros
45endif
46endif
47
48ifeq ($(TARGETSYSTEM), WINDOWS)
49  TEST_TARGET = $(BUILD_PREFIX)cata_test.exe
50else
51  TEST_TARGET = $(BUILD_PREFIX)cata_test
52endif
53
54tests: $(TEST_TARGET)
55
56$(TEST_TARGET): $(OBJS) $(CATA_LIB)
57	+$(CXX) $(W32FLAGS) -o $@ $(DEFINES) $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(LDFLAGS)
58
59$(PCH_P): $(PCH_H)
60	-$(CXX) $(CPPFLAGS) $(DEFINES) $(subst -Werror,,$(CXXFLAGS)) -Wno-non-virtual-dtor -Wno-unused-macros -I. -c $(PCH_H) -o $(PCH_P)
61
62TEST_BATCHES = "crafting_skill_gain" "[slow]\ ~crafting_skill_gain" "~[slow]\ ~[.]"
63
64$(TEST_BATCHES): $(TEST_TARGET)
65	cd .. && tests/$(TEST_TARGET) --min-duration 0.2 --rng-seed time $@
66
67check: $(TEST_TARGET) $(TEST_BATCHES)
68
69check-single: $(TEST_TARGET)
70	cd .. && tests/$(TEST_TARGET) --min-duration 0.2 --rng-seed time
71
72clean:
73	rm -rf *obj *objwin
74	rm -f *cata_test
75	rm -f pch/*pch.hpp.gch
76	rm -f pch/*pch.hpp.pch
77	rm -f pch/*pch.hpp.d
78
79#Unconditionally create object directory on invocation.
80$(shell mkdir -p $(ODIR))
81
82# Adding ../tests/ so that the directory appears in __FILE__ for log messages
83$(ODIR)/%.o: %.cpp $(PCH_P)
84	$(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) $(subst main-pch,tests-pch,$(PCHFLAGS)) -c ../tests/$< -o $@
85
86.PHONY: clean check check-single tests precompile_header
87
88.SECONDARY: $(OBJS)
89
90-include ${OBJS:.o=.d}
91