1 # A sample Makefile for building Google Test and using it in user
2 # tests. Please tweak it to suit your environment and project. You
3 # may want to move it to your project's root directory.
7 # make [all] - makes everything.
8 # make TARGET - makes the given target.
9 # make clean - removes all files generated by make.
12 # Where to find user code.
16 # specify which files that are included in the test in addition to the unittest file.
17 # variables available:
22 alignsensor_unittest_SRC
:= \
23 $(USER_DIR
)/sensors
/boardalignment.c \
24 $(USER_DIR
)/common
/maths.c
27 altitude_hold_unittest_SRC
:= \
28 $(USER_DIR
)/flight
/altitude.c
31 arming_prevention_unittest_SRC
:= \
32 $(USER_DIR
)/fc/fc_core.c \
33 $(USER_DIR
)/fc/rc_controls.c \
34 $(USER_DIR
)/fc/rc_modes.c \
35 $(USER_DIR
)/fc/runtime_config.c \
36 $(USER_DIR
)/common
/bitarray.c
38 atomic_unittest_SRC
= \
39 $(USER_DIR
)/build
/atomic.c \
40 $(TEST_DIR
)/atomic_unittest_c.c
42 baro_bmp085_unittest_SRC
:= \
43 $(USER_DIR
)/drivers
/barometer
/barometer_bmp085.c \
44 $(USER_DIR
)/drivers
/io.c
47 baro_bmp280_unittest_SRC
:= \
48 $(USER_DIR
)/drivers
/barometer
/barometer_bmp280.c
50 baro_bmp280_unittest_DEFINES
:= \
55 baro_ms5611_unittest_SRC
:= \
56 $(USER_DIR
)/drivers
/barometer
/barometer_ms5611.c
58 baro_ms5611_unittest_DEFINES
:= \
63 battery_unittest_SRC
:= \
64 $(USER_DIR
)/sensors
/battery.c \
65 $(USER_DIR
)/common
/maths.c
68 blackbox_unittest_SRC
:= \
69 $(USER_DIR
)/blackbox
/blackbox.c \
70 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
71 $(USER_DIR
)/blackbox
/blackbox_io.c \
72 $(USER_DIR
)/common
/encoding.c \
73 $(USER_DIR
)/common
/printf.c \
74 $(USER_DIR
)/common
/maths.c \
75 $(USER_DIR
)/common
/typeconversion.c \
76 $(USER_DIR
)/drivers
/gyro_sync.c
78 blackbox_encoding_unittest_SRC
:= \
79 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
80 $(USER_DIR
)/common
/encoding.c \
81 $(USER_DIR
)/common
/printf.c \
82 $(USER_DIR
)/common
/typeconversion.c
85 $(USER_DIR
)/fc/cli.c \
86 $(USER_DIR
)/config
/feature.c \
87 $(USER_DIR
)/config
/parameter_group.c \
88 $(USER_DIR
)/common
/typeconversion.c
90 cli_unittest_DEFINES
:= \
92 SystemCoreClock
=1000000 \
96 $(USER_DIR
)/cms
/cms.c \
97 $(USER_DIR
)/common
/typeconversion.c \
98 $(USER_DIR
)/drivers
/display.c
101 common_filter_unittest_SRC
:= \
102 $(USER_DIR
)/common
/filter.c
105 encoding_unittest_SRC
:= \
106 $(USER_DIR
)/common
/encoding.c
109 flight_failsafe_unittest_SRC
:= \
110 $(USER_DIR
)/common
/bitarray.c \
111 $(USER_DIR
)/fc/rc_modes.c \
112 $(USER_DIR
)/fc/runtime_config.c \
113 $(USER_DIR
)/flight
/failsafe.c
116 flight_imu_unittest_SRC
:= \
117 $(USER_DIR
)/common
/bitarray.c \
118 $(USER_DIR
)/common
/maths.c \
119 $(USER_DIR
)/config
/feature.c \
120 $(USER_DIR
)/fc/rc_modes.c \
121 $(USER_DIR
)/flight
/altitude.c \
122 $(USER_DIR
)/flight
/imu.c
125 flight_mixer_unittest
:= \
126 $(USER_DIR
)/flight
/mixer.c \
127 $(USER_DIR
)/flight
/servos.c \
128 $(USER_DIR
)/common
/maths.c
131 gps_conversion_unittest_SRC
:= \
132 $(USER_DIR
)/common
/gps_conversion.c
135 io_serial_unittest_SRC
:= \
136 $(USER_DIR
)/io
/serial.c \
137 $(USER_DIR
)/drivers
/serial_pinconfig.c
140 ledstrip_unittest_SRC
:= \
141 $(USER_DIR
)/common
/bitarray.c \
142 $(USER_DIR
)/fc/rc_modes.c \
143 $(USER_DIR
)/io
/ledstrip.c
146 maths_unittest_SRC
:= \
147 $(USER_DIR
)/common
/maths.c
150 osd_unittest_SRC
:= \
151 $(USER_DIR
)/io
/osd.c \
152 $(USER_DIR
)/common
/typeconversion.c \
153 $(USER_DIR
)/drivers
/display.c \
154 $(USER_DIR
)/common
/maths.c \
155 $(USER_DIR
)/common
/printf.c \
156 $(USER_DIR
)/fc/runtime_config.c
158 osd_unittest_DEFINES
:= \
162 parameter_groups_unittest_SRC
:= \
163 $(USER_DIR
)/config
/parameter_group.c
166 rc_controls_unittest_SRC
:= \
167 $(USER_DIR
)/fc/rc_controls.c \
168 $(USER_DIR
)/config
/parameter_group.c \
169 $(USER_DIR
)/common
/bitarray.c \
170 $(USER_DIR
)/common
/maths.c \
171 $(USER_DIR
)/fc/rc_adjustments.c \
172 $(USER_DIR
)/fc/rc_modes.c \
175 rx_crsf_unittest_SRC
:= \
176 $(USER_DIR
)/rx
/crsf.c \
177 $(USER_DIR
)/common
/crc.c \
178 $(USER_DIR
)/common
/printf.c \
179 $(USER_DIR
)/common
/typeconversion.c \
180 $(USER_DIR
)/common
/streambuf.c \
181 $(USER_DIR
)/drivers
/serial.c
184 rx_ibus_unittest_SRC
:= \
185 $(USER_DIR
)/rx
/ibus.c
188 rx_ranges_unittest_SRC
:= \
189 $(USER_DIR
)/common
/bitarray.c \
190 $(USER_DIR
)/common
/maths.c \
191 $(USER_DIR
)/fc/rc_modes.c \
195 rx_rx_unittest_SRC
:= \
196 $(USER_DIR
)/rx
/rx.c \
197 $(USER_DIR
)/fc/rc_modes.c \
198 $(USER_DIR
)/common
/bitarray.c \
199 $(USER_DIR
)/common
/maths.c \
200 $(USER_DIR
)/config
/feature.c
203 scheduler_unittest_SRC
:= \
204 $(USER_DIR
)/scheduler
/scheduler.c \
205 $(USER_DIR
)/common
/crc.c \
206 $(USER_DIR
)/common
/streambuf.c
209 telemetry_crsf_unittest_SRC
:= \
210 $(USER_DIR
)/rx
/crsf.c \
211 $(USER_DIR
)/telemetry
/crsf.c \
212 $(USER_DIR
)/common
/crc.c \
213 $(USER_DIR
)/common
/maths.c \
214 $(USER_DIR
)/common
/streambuf.c \
215 $(USER_DIR
)/common
/gps_conversion.c \
216 $(USER_DIR
)/common
/printf.c \
217 $(USER_DIR
)/common
/typeconversion.c \
218 $(USER_DIR
)/fc/runtime_config.c
220 telemetry_crsf_unittest_DEFINES
:= \
224 __REVISION__
="revision"
227 telemetry_crsf_msp_unittest_SRC
:= \
228 $(USER_DIR
)/rx
/crsf.c \
229 $(USER_DIR
)/common
/crc.c \
230 $(USER_DIR
)/common
/streambuf.c \
231 $(USER_DIR
)/common
/printf.c \
232 $(USER_DIR
)/common
/streambuf.c \
233 $(USER_DIR
)/drivers
/serial.c \
234 $(USER_DIR
)/common
/typeconversion.c \
235 $(USER_DIR
)/telemetry
/crsf.c \
236 $(USER_DIR
)/common
/gps_conversion.c \
237 $(USER_DIR
)/telemetry
/msp_shared.c \
238 $(USER_DIR
)/fc/runtime_config.c
240 telemetry_crsf_msp_unittest_DEFINES
:= \
241 USE_MSP_OVER_TELEMETRY
244 telemetry_hott_unittest_SRC
:= \
245 $(USER_DIR
)/telemetry
/hott.c \
246 $(USER_DIR
)/common
/gps_conversion.c
249 telemetry_ibus_unittest_SRC
:= \
250 $(USER_DIR
)/telemetry
/ibus_shared.c \
251 $(USER_DIR
)/telemetry
/ibus.c
254 transponder_ir_unittest_SRC
:= \
255 $(USER_DIR
)/drivers
/transponder_ir_ilap.c \
256 $(USER_DIR
)/drivers
/transponder_ir_arcitimer.c
259 type_conversion_unittest_SRC
:= \
260 $(USER_DIR
)/common
/typeconversion.c
263 ws2811_unittest_SRC
:= \
264 $(USER_DIR
)/drivers
/light_ws2811strip.c
266 rcsplit_unittest_SRC
:= \
267 $(USER_DIR
)/common
/bitarray.c \
268 $(USER_DIR
)/fc/rc_modes.c \
269 $(USER_DIR
)/io
/rcsplit.c
271 rcsplit_unitest_DEFINES
:= \
275 huffman_unittest_SRC
:= \
276 $(USER_DIR
)/common
/huffman.c \
277 $(USER_DIR
)/common
/huffman_table.c
279 huffman_unittest_DEFINES
:= \
282 ringbuffer_unittest_SRC
:= \
283 $(USER_DIR
)/common
/ringbuffer.c
285 # Please tweak the following variable definitions as needed by your
286 # project, except GTEST_HEADERS, which you can use in your own targets
287 # but shouldn't modify.
289 # Points to the root of Google Test, relative to where this file is.
290 # Remember to tweak this if you move this file.
291 GTEST_DIR
= ..
/..
/lib
/test/gtest
295 USER_INCLUDE_DIR
= $(USER_DIR
)
297 OBJECT_DIR
= ..
/..
/obj
/test
300 UNAME
:= $(shell uname
-s
)
302 # Use clang/clang++ by default
317 -isystem
$(GTEST_DIR
)/inc \
320 ifneq ($(UNAME
), Darwin
)
321 COMMON_FLAGS
+= -pthread
324 # Flags passed to the C compiler.
325 C_FLAGS
= $(COMMON_FLAGS
) \
328 # Flags passed to the C++ compiler.
329 CXX_FLAGS
= $(COMMON_FLAGS
) \
332 # Compiler flags for coverage instrumentation
333 COVERAGE_FLAGS
:= --coverage
335 C_FLAGS
+= $(COVERAGE_FLAGS
)
336 CXX_FLAGS
+= $(COVERAGE_FLAGS
)
338 # Set up the parameter group linker flags according to OS
339 ifeq ($(UNAME
), Darwin
)
340 PG_FLAGS
= -Wl
,-map
,$(OBJECT_DIR
)/$@.map
342 PG_FLAGS
= -Wl
,-T
,$(TEST_DIR
)/parameter_group.
ld -Wl
,-Map
,$(OBJECT_DIR
)/$@.map
345 # Gather up all of the tests.
346 TEST_SRC
= $(sort $(wildcard $(TEST_DIR
)/*.
cc))
347 TESTS
= $(TEST_SRC
:$(TEST_DIR
)/%.
cc=%)
349 # All Google Test headers. Usually you shouldn't change this
351 GTEST_HEADERS
= $(GTEST_DIR
)/inc
/gtest
/*.h
353 ## V : Set verbosity level based on the V= parameter
356 include ..
/..
/make
/build_verbosity.mk
358 # House-keeping build targets.
360 ## test : Build and run the Unit Tests (default goal)
361 test: $(TESTS
:%=test_
%)
363 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
364 junittest
: EXEC_OPTS
= "--gtest_output=xml:$<_results.xml"
365 junittest
: $(TESTS
:%=test_
%)
369 ## help : print this help message and exit
370 ## what : print this help message and exit
371 ## usage : print this help message and exit
372 help what usage
: Makefile
374 @echo
"Makefile for Unit Tests"
377 @echo
" make [goal] "
379 @echo
"Valid goals are:"
381 @sed
-n
's/^## //p' $<
383 @echo
"Any of the Unit Test programs can be used as goals to build:"
384 @
$(foreach test, $(TESTS
), echo
" $(OBJECT_DIR)/$(test)/$(test)";)
386 @echo
"Any of the Unit Test programs can be used as goals to build and run:"
387 @
$(foreach test, $(TESTS
), echo
" test_$(test)";)
389 ## clean : Cleanup the UnitTest binaries.
394 # Builds gtest.a and gtest_main.a.
396 # Usually you shouldn't tweak such internal variables, indicated by a
398 GTEST_SRCS_
= $(GTEST_DIR
)/src
/*.
cc $(GTEST_DIR
)/inc
/gtest
/*.h
$(GTEST_HEADERS
)
400 # For simplicity and to avoid depending on Google Test's
401 # implementation details, the dependencies specified below are
402 # conservative and not optimized. This is fine as Google Test
403 # compiles fast and for ordinary users its source rarely changes.
404 $(OBJECT_DIR
)/gtest-all.o
: $(GTEST_SRCS_
)
405 @echo
"compiling $@" "$(STDOUT)"
407 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -Wno-missing-field-initializers
-Wno-unused-const-variable
-c \
408 $(GTEST_DIR
)/src
/gtest-all.
cc -o
$@
410 $(OBJECT_DIR
)/gtest_main.o
: $(GTEST_SRCS_
)
411 @echo
"compiling $@" "$(STDOUT)"
413 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -c \
414 $(GTEST_DIR
)/src
/gtest_main.
cc -o
$@
416 $(OBJECT_DIR
)/gtest.a
: $(OBJECT_DIR
)/gtest-all.o
417 @echo
"linking $@" "$(STDOUT)"
418 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
420 $(OBJECT_DIR
)/gtest_main.a
: $(OBJECT_DIR
)/gtest-all.o
$(OBJECT_DIR
)/gtest_main.o
421 @echo
"linking $@" "$(STDOUT)"
422 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
424 -include $(OBJECT_DIR
)/gtest-all.d \
425 $(OBJECT_DIR
)/gtest_main.d
428 # includes in test dir must override includes in user dir
429 TEST_INCLUDE_DIRS
:= $(TEST_DIR
) \
432 TEST_CFLAGS
= $(addprefix -I
,$(TEST_INCLUDE_DIRS
))
437 # canned recipe for all test builds
438 # param $1 = testname
439 define test-specific-stuff
441 $$1_OBJS = $$(patsubst $$(TEST_DIR
)%,$$(OBJECT_DIR
)/$1%, $$(patsubst $$(USER_DIR
)%,$$(OBJECT_DIR
)/$1%,$$($1_SRC:=.o
)))
443 # $$(info $1 -v-v-------)
444 # $$(info $1_SRC: $($1_SRC))
445 # $$(info $1_OBJS: $$($$1_OBJS))
446 # $$(info $1 -^-^-------)
449 #include generated dependencies
450 -include $$($$1_OBJS:.o
=.d
)
451 -include $(OBJECT_DIR
)/$1/$1.d
454 $(OBJECT_DIR
)/$1/%.c.o
: $(USER_DIR
)/%.c
455 @echo
"compiling $$<" "$(STDOUT)"
456 $(V1
) mkdir
-p
$$(dir $$@
)
457 $(V1
) $(CC
) $(C_FLAGS
) $(TEST_CFLAGS
) \
458 $(foreach def
,$($1_DEFINES),-D
$(def
)) \
461 $(OBJECT_DIR
)/$1/%.c.o
: $(TEST_DIR
)/%.c
462 @echo
"compiling test c file: $$<" "$(STDOUT)"
463 $(V1
) mkdir
-p
$$(dir $$@
)
464 $(V1
) $(CC
) $(C_FLAGS
) $(TEST_CFLAGS
) \
465 $(foreach def
,$($1_DEFINES),-D
$(def
)) \
468 $(OBJECT_DIR
)/$1/$1.o
: $(TEST_DIR
)/$1.
cc
469 @echo
"compiling $$<" "$(STDOUT)"
470 $(V1
) mkdir
-p
$$(dir $$@
)
471 $(V1
) $(CXX
) $(CXX_FLAGS
) $(TEST_CFLAGS
) \
472 $(foreach def
,$($1_DEFINES),-D
$(def
)) \
476 $(OBJECT_DIR
)/$1/$1 : $$($$1_OBJS) \
477 $(OBJECT_DIR
)/$1/$1.o \
478 $(OBJECT_DIR
)/gtest_main.a
480 @echo
"linking $$@" "$(STDOUT)"
481 $(V1
) mkdir
-p
$(dir $$@
)
482 $(V1
) $(CXX
) $(CXX_FLAGS
) $(PG_FLAGS
) -lBlocksRuntime
$$^
-o
$$@
484 test_
$1: $(OBJECT_DIR
)/$1/$1
485 $(V1
) $$< $$(EXEC_OPTS
) "$(STDOUT)" && echo
"running $$@: PASS"
489 #apply the canned recipe above to all tests
490 $(eval
$(foreach test,$(TESTS
),$(call test-specific-stuff
,$(test))))