1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-04 12:24:11 +01:00
LibrePilot/flight/make/unittest.mk

83 lines
2.8 KiB
Makefile
Raw Normal View History

###############################################################################
# @file unittest.mk
# @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
2013-05-03 14:14:29 +02:00
# Copyright (c) 2013, The OpenPilot Team, http://www.openpilot.org
# @addtogroup
# @{
# @addtogroup
# @{
# @brief Makefile template for unit tests
###############################################################################
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2013-05-03 14:14:29 +02:00
# Use native toolchain and disable THUMB mode for unit tests
override ARM_SDK_PREFIX :=
override THUMB :=
GTEST_SRC_DIR := $(GTEST_DIR)/src
2013-05-03 14:14:29 +02:00
# Unit test source files
ALLSRC := $(SRC) $(wildcard ./*.c)
ALLCPPSRC := $(wildcard ./*.cpp) $(GTEST_SRC_DIR)/gtest_main.cc
2013-05-03 14:14:29 +02:00
ALLSRCBASE := $(notdir $(basename $(ALLSRC) $(ALLCPPSRC)))
ALLOBJ := $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE)))
$(foreach src,$(ALLSRC),$(eval $(call COMPILE_C_TEMPLATE,$(src))))
$(foreach src,$(ALLCPPSRC),$(eval $(call COMPILE_CXX_TEMPLATE,$(src))))
# Specific extensions to CPPFLAGS only for the google test library
$(OUTDIR)/gtest-all.o: CPPFLAGS += -I$(GTEST_SRC_DIR)/..
$(eval $(call COMPILE_CXX_TEMPLATE, $(GTEST_SRC_DIR)/gtest-all.cc))
$(eval $(call LINK_CXX_TEMPLATE,$(OUTDIR)/$(TARGET).elf,$(ALLOBJ) $(OUTDIR)/gtest-all.o))
2013-05-03 14:14:29 +02:00
# Flags passed to the preprocessor
CPPFLAGS += -I$(GTEST_DIR)/include
# Flags passed to the C++ compiler
CXXFLAGS += -g -Wall -Wextra -Wno-missing-field-initializers
2013-05-03 14:14:29 +02:00
# Flags passed to the C compiler
CONLYFLAGS += -std=gnu99
2014-09-03 21:14:54 +02:00
# UNIT_TEST allows to for example to have optional test fixture code enabled or private code exposed in application modules.
CFLAGS += -DUNIT_TEST
CPPFLAGS += -DUNIT_TEST
2013-05-03 14:14:29 +02:00
# Common compiler flags
CFLAGS += -O0 -g
CFLAGS += -Wall -Werror
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
# Google Test needs the pthread library
LDFLAGS += -lpthread
.PHONY: elf
elf: $(OUTDIR)/$(TARGET).elf
.PHONY: xml
xml: $(OUTDIR)/test-reports/$(TARGET).xml
$(OUTDIR)/test-reports/$(TARGET).xml: $(OUTDIR)/$(TARGET).elf
$(V0) @echo " TEST XML $(MSG_EXTRA) $(call toprel, $@)"
$(V1) $< --gtest_output=xml:$@ > /dev/null
.PHONY: run
run: $(OUTDIR)/$(TARGET).elf
$(V0) @echo " TEST RUN $(MSG_EXTRA) $(call toprel, $<)"
$(V1) $<