1 ###############################################################################
3 # @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
4 # Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org
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
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
:=
31 # Unit test source files
32 ALLSRC
:= $(SRC
) $(wildcard .
/*.c
)
33 ALLCPPSRC
:= $(wildcard .
/*.
cpp) $(GTEST_DIR
)/src
/gtest_main.
cc
34 ALLSRCBASE
:= $(notdir $(basename $(ALLSRC
) $(ALLCPPSRC
)))
35 ALLOBJ
:= $(addprefix $(OUTDIR
)/, $(addsuffix .o
, $(ALLSRCBASE
)))
37 $(foreach src
,$(ALLSRC
),$(eval
$(call COMPILE_C_TEMPLATE
,$(src
))))
38 $(foreach src
,$(ALLCPPSRC
),$(eval
$(call COMPILE_CXX_TEMPLATE
,$(src
))))
40 # Specific extensions to CPPFLAGS only for the google test library
41 $(OUTDIR
)/gtest-all.o
: CPPFLAGS
+= -I
$(GTEST_DIR
)
43 $(eval
$(call COMPILE_CXX_TEMPLATE
, $(GTEST_DIR
)/src
/gtest-all.
cc))
44 $(eval
$(call LINK_CXX_TEMPLATE
,$(OUTDIR
)/$(TARGET
).elf
,$(ALLOBJ
) $(OUTDIR
)/gtest-all.o
))
46 # Flags passed to the preprocessor
47 CPPFLAGS
+= -I
$(GTEST_DIR
)/include
49 # Flags passed to the C++ compiler
50 CXXFLAGS
+= -g
-Wall
-Wextra
52 # Flags passed to the C compiler
53 CONLYFLAGS
+= -std
=gnu99
55 # UNIT_TEST allows to for example to have optional test fixture code enabled or private code exposed in application modules.
57 CPPFLAGS
+= -DUNIT_TEST
59 # Common compiler flags
61 CFLAGS
+= -Wall
-Werror
62 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
64 # Google Test needs the pthread library
68 elf
: $(OUTDIR
)/$(TARGET
).elf
71 xml
: $(OUTDIR
)/test-reports
/$(TARGET
).xml
73 $(OUTDIR
)/test-reports
/$(TARGET
).xml
: $(OUTDIR
)/$(TARGET
).elf
74 $(V0
) @echo
" TEST XML $(MSG_EXTRA) $(call toprel, $@)"
75 $(V1
) $< --gtest_output
=xml
:$@
> /dev
/null
78 run
: $(OUTDIR
)/$(TARGET
).elf
79 $(V0
) @echo
" TEST RUN $(MSG_EXTRA) $(call toprel, $<)"