update credits
[librepilot.git] / flight / make / unittest.mk
blob861d3ebf1799fc017d77deb929eaf802893230d6
1 ###############################################################################
2 # @file unittest.mk
3 # @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
4 # Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org
5 # @addtogroup
6 # @{
7 # @addtogroup
8 # @{
9 # @brief Makefile template for unit tests
10 ###############################################################################
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with this program; if not, write to the Free Software Foundation, Inc.,
24 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 # Use native toolchain and disable THUMB mode for unit tests
28 override ARM_SDK_PREFIX :=
29 override THUMB :=
31 GTEST_SRC_DIR := $(GTEST_DIR)/src
33 # Unit test source files
34 ALLSRC := $(SRC) $(wildcard ./*.c)
35 ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_SRC_DIR)/gtest_main.cc
36 ALLSRCBASE := $(notdir $(basename $(ALLSRC) $(ALLCPPSRC)))
37 ALLOBJ := $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE)))
39 $(foreach src,$(ALLSRC),$(eval $(call COMPILE_C_TEMPLATE,$(src))))
40 $(foreach src,$(ALLCPPSRC),$(eval $(call COMPILE_CXX_TEMPLATE,$(src))))
42 # Specific extensions to CPPFLAGS only for the google test library
43 $(OUTDIR)/gtest-all.o: CPPFLAGS += -I$(GTEST_SRC_DIR)/..
45 $(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_SRC_DIR)/gtest-all.cc))
46 $(eval $(call LINK_CXX_TEMPLATE,$(OUTDIR)/$(TARGET).elf,$(ALLOBJ) $(OUTDIR)/gtest-all.o))
48 # Flags passed to the preprocessor
49 CPPFLAGS += -I$(GTEST_DIR)/include
51 # Flags passed to the C++ compiler
52 CXXFLAGS += -g -Wall -Wextra -Wno-missing-field-initializers
54 # Flags passed to the C compiler
55 CONLYFLAGS += -std=gnu99
57 # UNIT_TEST allows to for example to have optional test fixture code enabled or private code exposed in application modules.
58 CFLAGS += -DUNIT_TEST
59 CPPFLAGS += -DUNIT_TEST
61 # Common compiler flags
62 CFLAGS += -O0 -g
63 CFLAGS += -Wall -Werror
64 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
66 # Google Test needs the pthread library
67 LDFLAGS += -lpthread
69 .PHONY: elf
70 elf: $(OUTDIR)/$(TARGET).elf
72 .PHONY: xml
73 xml: $(OUTDIR)/test-reports/$(TARGET).xml
75 $(OUTDIR)/test-reports/$(TARGET).xml: $(OUTDIR)/$(TARGET).elf
76 $(V0) @echo " TEST XML $(MSG_EXTRA) $(call toprel, $@)"
77 $(V1) $< --gtest_output=xml:$@ > /dev/null
79 .PHONY: run
80 run: $(OUTDIR)/$(TARGET).elf
81 $(V0) @echo " TEST RUN $(MSG_EXTRA) $(call toprel, $<)"
82 $(V1) $<