1 # A sample Makefile for building Google Test and using it in user
2 # A sample Makefile for building Google Test and using it in user
3 # tests. Please tweak it to suit your environment and project. You
4 # may want to move it to your project's root directory.
8 # make [all] - makes everything.
9 # make TARGET - makes the given target.
10 # make clean - removes all files generated by make.
13 # Where to find user code.
17 OBJECT_DIR
= $(ROOT
)/obj
/test
18 TARGET_DIR
= $(USER_DIR
)/target
19 MAKE_SCRIPT_DIR
:= $(ROOT
)/mk
21 include $(MAKE_SCRIPT_DIR
)/system-id.mk
23 VPATH
:= $(VPATH
):$(USER_DIR
):$(TEST_DIR
)
25 # specify which files that are included in the test in addition to the unittest file.
26 # variables available:
29 # <test_name>_INCLUDE_DIRS
30 # <test_name>_EXPAND (run for each target, call the above with target as $1)
31 # <test_name>_BLACKLIST (targets to exclude from an expanded test's run)
33 alignsensor_unittest_SRC
:= \
34 $(USER_DIR
)/sensors
/boardalignment.c \
35 $(USER_DIR
)/common
/sensor_alignment.c \
36 $(USER_DIR
)/common
/maths.c \
37 $(USER_DIR
)/common
/vector.c
39 althold_unittest_SRC
:= \
40 $(USER_DIR
)/flight
/alt_hold_multirotor.c \
41 $(USER_DIR
)/flight
/autopilot_multirotor.c \
42 $(USER_DIR
)/common
/maths.c \
43 $(USER_DIR
)/common
/vector.c \
44 $(USER_DIR
)/common
/filter.c \
47 althold_unittest_DEFINES
:= \
50 arming_prevention_unittest_SRC
:= \
51 $(USER_DIR
)/common
/bitarray.c \
52 $(USER_DIR
)/common
/filter.c \
53 $(USER_DIR
)/common
/vector.c \
54 $(USER_DIR
)/fc/core.c \
55 $(USER_DIR
)/fc/dispatch.c \
56 $(USER_DIR
)/fc/rc_controls.c \
57 $(USER_DIR
)/fc/rc_modes.c \
58 $(USER_DIR
)/fc/runtime_config.c \
59 $(USER_DIR
)/flight
/autopilot_multirotor.c \
60 $(USER_DIR
)/flight
/gps_rescue_multirotor.c
62 arming_prevention_unittest_DEFINES
:= \
65 atomic_unittest_SRC
:= \
66 $(USER_DIR
)/build
/atomic.c \
67 $(TEST_DIR
)/atomic_unittest_c.c
69 baro_bmp085_unittest_SRC
:= \
70 $(USER_DIR
)/drivers
/barometer
/barometer_bmp085.c
72 baro_bmp085_unittest_DEFINES
:= \
75 baro_bmp280_unittest_SRC
:= \
76 $(USER_DIR
)/drivers
/barometer
/barometer_bmp280.c
78 baro_bmp280_unittest_DEFINES
:= \
82 baro_bmp388_unittest_SRC
:= \
83 $(USER_DIR
)/common
/maths.c \
84 $(USER_DIR
)/drivers
/barometer
/barometer_bmp388.c
86 baro_bmp388_unittest_DEFINES
:= \
91 baro_ms5611_unittest_SRC
:= \
92 $(USER_DIR
)/drivers
/barometer
/barometer_ms5611.c
94 baro_ms5611_unittest_DEFINES
:= \
98 # This test is disabled due to build errors.
99 # Its source code is archived in unit/battery_unittest.cc.txt
101 #battery_unittest_SRC := \
102 # $(USER_DIR)/sensors/battery.c \
103 # $(USER_DIR)/common/maths.c
106 blackbox_unittest_SRC
:= \
107 $(USER_DIR
)/blackbox
/blackbox.c \
108 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
109 $(USER_DIR
)/blackbox
/blackbox_io.c \
110 $(USER_DIR
)/common
/encoding.c \
111 $(USER_DIR
)/common
/printf.c \
112 $(USER_DIR
)/common
/maths.c \
113 $(USER_DIR
)/common
/typeconversion.c \
114 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
117 blackbox_encoding_unittest_SRC
:= \
118 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
119 $(USER_DIR
)/common
/encoding.c \
120 $(USER_DIR
)/common
/printf.c \
121 $(USER_DIR
)/common
/typeconversion.c
123 cli_unittest_SRC
:= \
124 $(USER_DIR
)/cli
/cli.c \
125 $(USER_DIR
)/common
/crc.c \
126 $(USER_DIR
)/common
/printf.c \
127 $(USER_DIR
)/common
/streambuf.c \
128 $(USER_DIR
)/common
/maths.c \
129 $(USER_DIR
)/common
/gps_conversion.c \
130 $(USER_DIR
)/config
/feature.c \
131 $(USER_DIR
)/io
/gps.c \
132 $(USER_DIR
)/io
/serial_resource.c \
133 $(USER_DIR
)/pg
/pg.c \
134 $(USER_DIR
)/fc/runtime_config.c \
135 $(USER_DIR
)/drivers
/serial.c \
136 $(USER_DIR
)/drivers
/serial_impl.c \
137 $(USER_DIR
)/common
/typeconversion.c
139 cli_unittest_DEFINES
:= \
142 SystemCoreClock
=1000000
144 cms_unittest_SRC
:= \
145 $(USER_DIR
)/cms
/cms.c \
146 $(USER_DIR
)/cms
/cms_menu_saveexit.c \
147 $(USER_DIR
)/common
/typeconversion.c \
148 $(USER_DIR
)/drivers
/display.c
151 common_filter_unittest_SRC
:= \
152 $(USER_DIR
)/common
/filter.c \
153 $(USER_DIR
)/common
/maths.c
156 encoding_unittest_SRC
:= \
157 $(USER_DIR
)/common
/encoding.c
160 flight_failsafe_unittest_SRC
:= \
161 $(USER_DIR
)/common
/bitarray.c \
162 $(USER_DIR
)/fc/rc_modes.c \
163 $(USER_DIR
)/fc/runtime_config.c \
164 $(USER_DIR
)/flight
/failsafe.c
166 flight_failsafe_unittest_DEFINES
:= \
170 flight_imu_unittest_SRC
:= \
171 $(USER_DIR
)/common
/bitarray.c \
172 $(USER_DIR
)/common
/maths.c \
173 $(USER_DIR
)/common
/vector.c \
174 $(USER_DIR
)/common
/filter.c \
175 $(USER_DIR
)/config
/feature.c \
176 $(USER_DIR
)/fc/rc_modes.c \
177 $(USER_DIR
)/flight
/position.c \
178 $(USER_DIR
)/flight
/imu.c
181 flight_mixer_unittest
:= \
182 $(USER_DIR
)/flight
/mixer.c \
183 $(USER_DIR
)/flight
/servos.c \
184 $(USER_DIR
)/common
/maths.c
187 gps_conversion_unittest_SRC
:= \
188 $(USER_DIR
)/common
/gps_conversion.c
191 io_serial_unittest_SRC
:= \
192 $(USER_DIR
)/io
/serial.c \
193 $(USER_DIR
)/io
/serial_resource.c
196 ledstrip_unittest_SRC
:= \
197 $(USER_DIR
)/common
/bitarray.c \
198 $(USER_DIR
)/fc/rc_modes.c \
199 $(USER_DIR
)/io
/ledstrip.c
201 ledstrip_unittest_DEFINES
:= \
205 maths_unittest_SRC
:= \
206 $(USER_DIR
)/common
/maths.c \
207 $(USER_DIR
)/common
/vector.c
210 motor_output_unittest_SRC
:= \
211 $(USER_DIR
)/build
/atomic.c \
212 $(USER_DIR
)/drivers
/dshot.c
214 motor_output_unittest_DEFINES
:= \
217 osd_unittest_SRC
:= \
218 $(USER_DIR
)/osd
/osd.c \
219 $(USER_DIR
)/osd
/osd_elements.c \
220 $(USER_DIR
)/osd
/osd_warnings.c \
221 $(USER_DIR
)/common
/filter.c \
222 $(USER_DIR
)/common
/maths.c \
223 $(USER_DIR
)/common
/printf.c \
224 $(USER_DIR
)/common
/time.c \
225 $(USER_DIR
)/common
/typeconversion.c \
226 $(USER_DIR
)/common
/vector.c \
227 $(USER_DIR
)/drivers
/display.c \
228 $(USER_DIR
)/fc/runtime_config.c
230 osd_unittest_DEFINES
:= \
236 link_quality_unittest_SRC
:= \
237 $(USER_DIR
)/osd
/osd.c \
238 $(USER_DIR
)/osd
/osd_elements.c \
239 $(USER_DIR
)/osd
/osd_warnings.c \
240 $(USER_DIR
)/common
/bitarray.c \
241 $(USER_DIR
)/common
/crc.c \
242 $(USER_DIR
)/common
/maths.c \
243 $(USER_DIR
)/common
/printf.c \
244 $(USER_DIR
)/common
/streambuf.c \
245 $(USER_DIR
)/common
/time.c \
246 $(USER_DIR
)/common
/typeconversion.c \
247 $(USER_DIR
)/common
/vector.c \
248 $(USER_DIR
)/drivers
/display.c \
249 $(USER_DIR
)/drivers
/serial.c \
250 $(USER_DIR
)/drivers
/serial_impl.c \
251 $(USER_DIR
)/fc/rc_modes.c \
252 $(USER_DIR
)/fc/runtime_config.c \
253 $(USER_DIR
)/pg
/pg.c \
254 $(USER_DIR
)/pg
/rx.c \
255 $(USER_DIR
)/rx
/rx.c \
256 $(USER_DIR
)/rx
/crsf.c
258 link_quality_unittest_DEFINES
:= \
260 USE_CRSF_LINK_STATISTICS
= \
261 USE_RX_LINK_QUALITY_INFO
=
264 $(USER_DIR
)/common
/crc.c \
265 $(USER_DIR
)/common
/streambuf.c \
269 rc_controls_unittest_SRC
:= \
270 $(USER_DIR
)/fc/rc_controls.c \
271 $(USER_DIR
)/pg
/pg.c \
272 $(USER_DIR
)/common
/bitarray.c \
273 $(USER_DIR
)/common
/crc.c \
274 $(USER_DIR
)/common
/maths.c \
275 $(USER_DIR
)/common
/streambuf.c \
276 $(USER_DIR
)/fc/rc_adjustments.c \
277 $(USER_DIR
)/fc/rc_modes.c
280 rx_crsf_unittest_SRC
:= \
281 $(USER_DIR
)/rx
/crsf.c \
282 $(USER_DIR
)/common
/crc.c \
283 $(USER_DIR
)/common
/printf.c \
284 $(USER_DIR
)/common
/typeconversion.c \
285 $(USER_DIR
)/common
/streambuf.c \
286 $(USER_DIR
)/drivers
/serial.c \
287 $(USER_DIR
)/drivers
/serial_impl.c
290 rx_ibus_unittest_SRC
:= \
291 $(USER_DIR
)/rx
/ibus.c
294 rx_ranges_unittest_SRC
:= \
295 $(USER_DIR
)/common
/bitarray.c \
296 $(USER_DIR
)/common
/crc.c \
297 $(USER_DIR
)/common
/maths.c \
298 $(USER_DIR
)/common
/streambuf.c \
299 $(USER_DIR
)/fc/rc_modes.c \
300 $(USER_DIR
)/rx
/rx.c \
301 $(USER_DIR
)/pg
/pg.c \
305 rx_rx_unittest_SRC
:= \
306 $(USER_DIR
)/rx
/rx.c \
307 $(USER_DIR
)/fc/rc_modes.c \
308 $(USER_DIR
)/common
/bitarray.c \
309 $(USER_DIR
)/common
/maths.c \
310 $(USER_DIR
)/config
/feature.c \
313 rx_sumd_unittest_SRC
:= \
314 $(USER_DIR
)/common
/crc.c \
315 $(USER_DIR
)/common
/streambuf.c \
316 $(USER_DIR
)/rx
/sumd.c
318 scheduler_unittest_SRC
:= \
319 $(USER_DIR
)/scheduler
/scheduler.c \
320 $(USER_DIR
)/common
/crc.c \
321 $(USER_DIR
)/common
/streambuf.c \
322 $(TEST_DIR
)/scheduler_stubs.c
324 scheduler_unittest_DEFINES
:= \
327 sensor_gyro_unittest_SRC
:= \
328 $(USER_DIR
)/sensors
/gyro.c \
329 $(USER_DIR
)/sensors
/gyro_init.c \
330 $(USER_DIR
)/sensors
/boardalignment.c \
331 $(USER_DIR
)/common
/crc.c \
332 $(USER_DIR
)/common
/filter.c \
333 $(USER_DIR
)/common
/maths.c \
334 $(USER_DIR
)/common
/streambuf.c \
335 $(USER_DIR
)/common
/sensor_alignment.c \
336 $(USER_DIR
)/common
/vector.c \
337 $(USER_DIR
)/drivers
/accgyro
/accgyro_virtual.c \
338 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
339 $(USER_DIR
)/pg
/pg.c \
340 $(USER_DIR
)/pg
/gyrodev.c
342 telemetry_crsf_unittest_SRC
:= \
343 $(USER_DIR
)/rx
/crsf.c \
344 $(USER_DIR
)/telemetry
/crsf.c \
345 $(USER_DIR
)/common
/crc.c \
346 $(USER_DIR
)/common
/maths.c \
347 $(USER_DIR
)/common
/streambuf.c \
348 $(USER_DIR
)/common
/gps_conversion.c \
349 $(USER_DIR
)/common
/printf.c \
350 $(USER_DIR
)/common
/typeconversion.c \
351 $(USER_DIR
)/fc/runtime_config.c
353 telemetry_crsf_unittest_DEFINES
:= \
356 __REVISION__
="revision"
359 telemetry_crsf_msp_unittest_SRC
:= \
360 $(USER_DIR
)/rx
/crsf.c \
361 $(USER_DIR
)/build
/atomic.c \
362 $(USER_DIR
)/common
/crc.c \
363 $(USER_DIR
)/common
/streambuf.c \
364 $(USER_DIR
)/common
/printf.c \
365 $(USER_DIR
)/common
/streambuf.c \
366 $(USER_DIR
)/drivers
/serial.c \
367 $(USER_DIR
)/drivers
/serial_impl.c \
368 $(USER_DIR
)/common
/typeconversion.c \
369 $(USER_DIR
)/telemetry
/crsf.c \
370 $(USER_DIR
)/common
/gps_conversion.c \
371 $(USER_DIR
)/telemetry
/msp_shared.c \
372 $(USER_DIR
)/fc/runtime_config.c
374 telemetry_crsf_msp_unittest_DEFINES
:= \
375 USE_MSP_OVER_TELEMETRY
=
378 telemetry_hott_unittest_SRC
:= \
379 $(USER_DIR
)/telemetry
/hott.c \
380 $(USER_DIR
)/io
/serial_resource.c \
381 $(USER_DIR
)/common
/gps_conversion.c
384 telemetry_ibus_unittest_SRC
:= \
385 $(USER_DIR
)/telemetry
/ibus_shared.c \
386 $(USER_DIR
)/telemetry
/ibus.c
388 transponder_ir_unittest_SRC
:= \
389 $(USER_DIR
)/drivers
/transponder_ir_ilap.c \
390 $(USER_DIR
)/drivers
/transponder_ir_arcitimer.c
392 ws2811_unittest_SRC
:= \
393 $(USER_DIR
)/drivers
/light_ws2811strip.c
395 huffman_unittest_SRC
:= \
396 $(USER_DIR
)/common
/huffman.c \
397 $(USER_DIR
)/common
/huffman_table.c
399 huffman_unittest_DEFINES
:= \
402 rcdevice_unittest_SRC
:= \
403 $(USER_DIR
)/common
/crc.c \
404 $(USER_DIR
)/common
/bitarray.c \
405 $(USER_DIR
)/fc/rc_modes.c \
406 $(USER_DIR
)/io
/rcdevice.c \
407 $(USER_DIR
)/io
/rcdevice_cam.c \
408 $(USER_DIR
)/pg
/pg.c \
410 pid_unittest_SRC
:= \
411 $(USER_DIR
)/common
/crc.c \
412 $(USER_DIR
)/common
/filter.c \
413 $(USER_DIR
)/common
/maths.c \
414 $(USER_DIR
)/common
/pwl.c \
415 $(USER_DIR
)/common
/streambuf.c \
416 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
417 $(USER_DIR
)/fc/controlrate_profile.c \
418 $(USER_DIR
)/fc/runtime_config.c \
419 $(USER_DIR
)/flight
/pid.c \
420 $(USER_DIR
)/flight
/pid_init.c \
423 pid_unittest_DEFINES
:= \
425 USE_RC_SMOOTHING_FILTER
= \
426 USE_ABSOLUTE_CONTROL
= \
427 USE_LAUNCH_CONTROL
= \
431 rcdevice_unittest_DEFINES
:= \
434 vtx_unittest_SRC
:= \
435 $(USER_DIR
)/fc/core.c \
436 $(USER_DIR
)/fc/dispatch.c \
437 $(USER_DIR
)/fc/rc_controls.c \
438 $(USER_DIR
)/fc/rc_modes.c \
439 $(USER_DIR
)/fc/runtime_config.c \
440 $(USER_DIR
)/drivers
/vtx_common.c \
441 $(USER_DIR
)/drivers
/vtx_table.c \
442 $(USER_DIR
)/io
/vtx_control.c \
443 $(USER_DIR
)/io
/vtx.c \
444 $(USER_DIR
)/common
/bitarray.c
446 vtx_unittest_DEFINES
:= \
451 rx_spi_spektrum_unittest_SRC
:= \
452 $(USER_DIR
)/rx
/cyrf6936_spektrum.c
454 rx_spi_spektrum_unittest_DEFINES
:= \
458 rx_spi_expresslrs_unittest_SRC
:= \
459 $(USER_DIR
)/pg
/rx_spi_expresslrs.c \
460 $(USER_DIR
)/rx
/expresslrs_common.c \
461 $(USER_DIR
)/rx
/expresslrs.c \
462 $(USER_DIR
)/build
/atomic.c \
464 rx_spi_expresslrs_unittest_DEFINES
:= \
470 rx_spi_expresslrs_telemetry_unittest_SRC
:= \
471 $(USER_DIR
)/rx
/crsf.c \
472 $(USER_DIR
)/telemetry
/crsf.c \
473 $(USER_DIR
)/common
/crc.c \
474 $(USER_DIR
)/common
/maths.c \
475 $(USER_DIR
)/common
/streambuf.c \
476 $(USER_DIR
)/common
/gps_conversion.c \
477 $(USER_DIR
)/common
/printf.c \
478 $(USER_DIR
)/common
/typeconversion.c \
479 $(USER_DIR
)/rx
/expresslrs_telemetry.c \
480 $(USER_DIR
)/build
/atomic.c \
481 $(USER_DIR
)/telemetry
/msp_shared.c \
483 rx_spi_expresslrs_telemetry_unittest_DEFINES
:= \
486 USE_MSP_OVER_TELEMETRY
= \
488 vtx_msp_unittest_SRC
:= \
489 $(USER_DIR
)/common
/crc.c \
490 $(USER_DIR
)/common
/streambuf.c \
491 $(USER_DIR
)/fc/runtime_config.c \
492 $(USER_DIR
)/drivers
/vtx_common.c \
493 $(USER_DIR
)/drivers
/vtx_table.c \
494 $(USER_DIR
)/pg
/vtx_table.c \
495 $(USER_DIR
)/io
/vtx_control.c \
496 $(USER_DIR
)/io
/vtx.c \
497 $(USER_DIR
)/io
/vtx_msp.c \
499 vtx_msp_unittest_DEFINES
:= \
505 pwl_unittest_SRC
:= \
506 $(USER_DIR
)/common
/pwl.c
508 # Please tweak the following variable definitions as needed by your
509 # project, except GTEST_HEADERS, which you can use in your own targets
510 # but shouldn't modify.
512 # Points to the root of Google Test, relative to where this file is.
513 # Remember to tweak this if you move this file.
514 GTEST_DIR
= ..
/..
/lib
/test/gtest
516 # Use clang/clang++ by default
520 ifeq ($(and
$(shell which
$(CC
) 2>/dev
/null
), $(shell which
$(CXX
) 2>/dev
/null
)),)
521 $(info Falling back to
'clang')
533 -isystem
$(GTEST_DIR
)/inc \
537 CC_VERSION
= $(shell $(CC
) -dumpversion
)
538 CXX_VERSION
= $(shell $(CXX
) -dumpversion
)
540 ifeq ($(shell $(CC
) -v
2>&1 | grep
-q
"clang version" && echo
"clang"),clang
)
542 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 18 }
543 CC_VERSION_MAJOR
:= $(firstword $(subst .
, ,$(CC_VERSION
)))
544 CC_VERSION_CHECK_MIN
:= 7
545 CC_VERSION_CHECK_MAX
:= 18
547 # c99-designator is fine, code is not expected to be clean C++
548 COMMON_FLAGS
+= -Wno-c99-designator
550 # no warning expected on clang
551 COMMON_FLAGS
+= -Werror
553 ifeq ($(shell expr
$(CC_VERSION_MAJOR
) \
< $(CC_VERSION_CHECK_MIN
) \|
$(CC_VERSION_MAJOR
) \
> $(CC_VERSION_CHECK_MAX
)),1)
554 $(error
$(CC
) $(CC_VERSION
) is not supported. The officially supported version of clang is
'clang-18'. If this is not found
, 'clang' is used
as a fallback. The version of the compiler must be between
$(CC_VERSION_CHECK_MIN
) and
$(CC_VERSION_CHECK_MAX
).
)
557 COMMON_FLAGS
+= -fblocks
559 ifneq ($(OSFAMILY
), macosx
)
560 LDFLAGS
+= -lBlocksRuntime
564 else ifeq ($(shell $(CC
) -v
2>&1 | grep
-q
"gcc version" && echo
"gcc"),gcc
)
566 $(warning warning
: gcc
/g
++ support is experimental. For normal testing
, clang is recommended
)
568 # no -Werror, allow warning for gcc now
569 COMMON_FLAGS
+= -Wno-missing-field-initializers
571 endif # is clang / gcc
573 $(info CC version
: $(shell $(CC
) --version
))
574 $(info CXX version
: $(shell $(CXX
) --version
))
578 ifeq ($(OSFAMILY
), macosx
)
587 COMMON_FLAGS
+= -pthread
590 # Flags passed to the C compiler.
591 C_FLAGS
= $(COMMON_FLAGS
) \
594 # Flags passed to the C++ compiler.
595 CXX_FLAGS
= $(COMMON_FLAGS
) \
598 # Compiler flags for coverage instrumentation
600 COVERAGE_FLAGS
:= --coverage
603 C_FLAGS
+= $(COVERAGE_FLAGS
)
604 CXX_FLAGS
+= $(COVERAGE_FLAGS
)
606 C_FLAGS
+= -D_GNU_SOURCE
608 # Set up the parameter group linker flags according to OS
609 ifeq ($(OSFAMILY
), macosx
)
610 LDFLAGS
+= -Wl
,-map
,$(OBJECT_DIR
)/$@.map
612 LDFLAGS
+= -Wl
,-T
,$(TEST_DIR
)/pg.
ld -Wl
,-Map
,$(OBJECT_DIR
)/$@.map
615 # Gather up all of the tests.
616 TEST_SRCS
= $(sort $(wildcard $(TEST_DIR
)/*.
cc))
617 TEST_BASENAMES
= $(TEST_SRCS
:$(TEST_DIR
)/%.
cc=%)
618 TESTS_TARGET_SPECIFIC
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),$(test)))
620 TESTS
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),,$(test)))
623 # All Google Test headers. Usually you shouldn't change this
625 GTEST_HEADERS
= $(GTEST_DIR
)/inc
/gtest
/*.h
627 ## V : Set verbosity level based on the V= parameter
630 include $(MAKE_SCRIPT_DIR
)/build_verbosity.mk
632 # House-keeping build targets.
634 ## test : Build and run the non target specific Unit Tests (default goal)
635 test: $(TESTS
:%=test_
%)
637 ## test-all : Build and run all Unit Tests
638 test-all
: $(TESTS_ALL
:%=test_
%)
640 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
641 test-representative
: $(TESTS_REPRESENTATIVE
:%=test_
%)
643 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
644 junittest
: EXEC_OPTS
= "--gtest_output=xml:$<_results.xml"
645 junittest
: $(TESTS
:%=test_
%)
649 ## help : print this help message and exit
650 ## what : print this help message and exit
651 ## usage : print this help message and exit
652 help what usage
: Makefile
654 @echo
"Makefile for Unit Tests"
657 @echo
" make [goal] "
659 @echo
"Valid goals are:"
661 @sed
-n
's/^## //p' $<
663 @echo
"Any of the Unit Test programs can be used as goals to build:"
664 @
$(foreach test, $(TESTS
), echo
" $(OBJECT_DIR)/$(test)/$(test)";)
666 @echo
"Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
667 @
$(foreach test, $(TESTS
), echo
" test_$(test)";)
670 @echo
"C compiler: $(CC): $(CC_VERSION)"
671 @echo
"C++ compiler: $(CXX): $(CXX_VERSION)"
673 ## clean : Cleanup the UnitTest binaries.
678 # Builds gtest.a and gtest_main.a.
680 # Usually you shouldn't tweak such internal variables, indicated by a
682 GTEST_SRCS_
= $(GTEST_DIR
)/src
/*.
cc $(GTEST_DIR
)/inc
/gtest
/*.h
$(GTEST_HEADERS
)
684 # For simplicity and to avoid depending on Google Test's
685 # implementation details, the dependencies specified below are
686 # conservative and not optimized. This is fine as Google Test
687 # compiles fast and for ordinary users its source rarely changes.
688 $(OBJECT_DIR
)/gtest-all.o
: $(GTEST_SRCS_
)
689 @echo
"compiling $@" "$(STDOUT)"
691 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -Wno-missing-field-initializers
-Wno-unused-const-variable
-c \
692 $(GTEST_DIR
)/src
/gtest-all.
cc -o
$@
694 $(OBJECT_DIR
)/gtest_main.o
: $(GTEST_SRCS_
)
695 @echo
"compiling $@" "$(STDOUT)"
697 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -c \
698 $(GTEST_DIR
)/src
/gtest_main.
cc -o
$@
700 $(OBJECT_DIR
)/gtest.a
: $(OBJECT_DIR
)/gtest-all.o
701 @echo
"linking $@" "$(STDOUT)"
702 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
704 $(OBJECT_DIR
)/gtest_main.a
: $(OBJECT_DIR
)/gtest-all.o
$(OBJECT_DIR
)/gtest_main.o
705 @echo
"linking $@" "$(STDOUT)"
706 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
708 -include $(OBJECT_DIR
)/gtest-all.d \
709 $(OBJECT_DIR
)/gtest_main.d
712 # includes in test dir must override includes in user dir, unless the user
713 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
714 test_include_dirs
= $1 $(TEST_DIR
) $(USER_DIR
)
715 test_cflags
= $(addprefix -I
,$(call test_include_dirs
,$1))
718 # target name extractor
719 # param $1 = expanded test name in the form of test.target
720 target
= $(1:$(basename $1).
%=%)
722 # canned recipe for all test builds
724 # variable expansion rules of thumb (number of $'s):
725 # * parameters: one $, e.g. $1
726 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
727 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
728 # * make functions accessing only the above: one $, e.g. $(basename $1)
729 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
730 # * make functions accessing dynamically set variables: two $,
731 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
733 # param $1 = plain test name for global tests, test.target for per-target tests
734 define test-specific-stuff
736 ifeq ($1,$(basename $1))
737 # standard global test
738 $1_OBJS = $(patsubst \
739 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$(patsubst \
740 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$($1_SRC:=.o
)))
742 # test executed for each target, $1 has the form of test.target
743 $1_SRC = $(addsuffix .o
,$(call
$(basename $1)_SRC
,$(call target
,$1)))
744 $1_OBJS = $$(patsubst \
745 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
746 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
747 $(TARGET_DIR
)/$(TARGET
)/%,$(OBJECT_DIR
)/$1/%,$$($1_SRC))))
748 $1_DEFINES = $(call
$(basename $1)_DEFINES
,$(call target
,$1))
749 $1_INCLUDE_DIRS = $(call
$(basename $1)_INCLUDE_DIRS
,$(call target
,$1))
752 # $$(info $1 -v-v-------)
753 # $$(info $1_SRC: $$($1_SRC))
754 # $$(info $1_OBJS: $$($1_OBJS))
755 # $$(info $1 -^-^-------)
757 # include generated dependencies
758 -include $$($1_OBJS:.o
=.d
)
759 -include $(OBJECT_DIR
)/$1/$(basename $1).d
761 $(OBJECT_DIR
)/$1/%.c.o
: $(USER_DIR
)/%.c
762 @echo
"compiling $$<" "$(STDOUT)"
763 $(V1
) mkdir
-p
$$(dir $$@
)
764 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
765 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
768 $(OBJECT_DIR
)/$1/%.c.o
: $(TEST_DIR
)/%.c
769 @echo
"compiling test c file: $$<" "$(STDOUT)"
770 $(V1
) mkdir
-p
$$(dir $$@
)
771 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
772 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
775 ifneq ($1,$(basename $1))
776 # per-target tests may compile files from the target directory
777 $(OBJECT_DIR
)/$1/%.c.o
: $(TARGET_DIR
)/$(TARGET
)/%.c
778 @echo
"compiling target c file: $$<" "$(STDOUT)"
779 $(V1
) mkdir
-p
$$(dir $$@
)
780 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
781 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
785 $(OBJECT_DIR
)/$1/$(basename $1).o
: $(TEST_DIR
)/$(basename $1).
cc
786 @echo
"compiling $$<" "$(STDOUT)"
787 $(V1
) mkdir
-p
$$(dir $$@
)
788 $(V1
) $(CXX
) $(CXX_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
789 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
792 $(OBJECT_DIR
)/$1/$(basename $1): $$($1_OBJS) \
793 $(OBJECT_DIR
)/$1/$(basename $1).o \
794 $(OBJECT_DIR
)/gtest_main.a
796 @echo
"linking $$@" "$(STDOUT)"
797 $(V1
) mkdir
-p
$(dir $$@
)
798 $(V1
) $(CXX
) $(CXX_FLAGS
) $(LDFLAGS
) $$^
-o
$$@
800 test_
$1: $(OBJECT_DIR
)/$1/$(basename $1)
801 $(V1
) $$< $$(EXEC_OPTS
) "$(STDOUT)" && echo
"running $$@: PASS"
806 ifeq ($(MAKECMDGOALS
),test-all
)
807 $(eval
$(foreach test,$(TESTS_ALL
),$(call test-specific-stuff
,$(test))))
809 ifeq ($(MAKECMDGOALS
),test-representative
)
810 $(eval
$(foreach test,$(TESTS_REPRESENTATIVE
),$(call test-specific-stuff
,$(test))))
812 $(eval
$(foreach test,$(TESTS
),$(call test-specific-stuff
,$(test))))
816 $(foreach test,$(TESTS_ALL
),$(if
$($(basename $(test))_SRC
),,$(error \
817 Test
'unit/$(basename $(test)).cc' has no
'$(basename $(test))_SRC' variable defined
)))