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
= ..
/..
/obj
/test
18 TARGET_DIR
= $(USER_DIR
)/target
20 include $(ROOT
)/make
/system-id.mk
21 include $(ROOT
)/make
/targets_list.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
38 arming_prevention_unittest_SRC
:= \
39 $(USER_DIR
)/fc/core.c \
40 $(USER_DIR
)/fc/dispatch.c \
41 $(USER_DIR
)/fc/rc_controls.c \
42 $(USER_DIR
)/fc/rc_modes.c \
43 $(USER_DIR
)/fc/runtime_config.c \
44 $(USER_DIR
)/flight
/gps_rescue.c \
45 $(USER_DIR
)/common
/bitarray.c
47 arming_prevention_unittest_DEFINES
:= \
50 atomic_unittest_SRC
:= \
51 $(USER_DIR
)/build
/atomic.c \
52 $(TEST_DIR
)/atomic_unittest_c.c
54 baro_bmp085_unittest_SRC
:= \
55 $(USER_DIR
)/drivers
/barometer
/barometer_bmp085.c
57 baro_bmp085_unittest_DEFINES
:= \
60 baro_bmp280_unittest_SRC
:= \
61 $(USER_DIR
)/drivers
/barometer
/barometer_bmp280.c
63 baro_bmp280_unittest_DEFINES
:= \
67 baro_bmp388_unittest_SRC
:= \
68 $(USER_DIR
)/common
/maths.c \
69 $(USER_DIR
)/drivers
/barometer
/barometer_bmp388.c
71 baro_bmp388_unittest_DEFINES
:= \
76 baro_ms5611_unittest_SRC
:= \
77 $(USER_DIR
)/drivers
/barometer
/barometer_ms5611.c
79 baro_ms5611_unittest_DEFINES
:= \
83 # This test is disabled due to build errors.
84 # Its source code is archived in unit/battery_unittest.cc.txt
86 #battery_unittest_SRC := \
87 # $(USER_DIR)/sensors/battery.c \
88 # $(USER_DIR)/common/maths.c
91 blackbox_unittest_SRC
:= \
92 $(USER_DIR
)/blackbox
/blackbox.c \
93 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
94 $(USER_DIR
)/blackbox
/blackbox_io.c \
95 $(USER_DIR
)/common
/encoding.c \
96 $(USER_DIR
)/common
/printf.c \
97 $(USER_DIR
)/common
/maths.c \
98 $(USER_DIR
)/common
/typeconversion.c \
99 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c
101 blackbox_encoding_unittest_SRC
:= \
102 $(USER_DIR
)/blackbox
/blackbox_encoding.c \
103 $(USER_DIR
)/common
/encoding.c \
104 $(USER_DIR
)/common
/printf.c \
105 $(USER_DIR
)/common
/typeconversion.c
107 cli_unittest_SRC
:= \
108 $(USER_DIR
)/cli
/cli.c \
109 $(USER_DIR
)/common
/crc.c \
110 $(USER_DIR
)/common
/printf.c \
111 $(USER_DIR
)/common
/streambuf.c \
112 $(USER_DIR
)/config
/feature.c \
113 $(USER_DIR
)/pg
/pg.c \
114 $(USER_DIR
)/common
/typeconversion.c
116 cli_unittest_DEFINES
:= \
119 SystemCoreClock
=1000000
121 cms_unittest_SRC
:= \
122 $(USER_DIR
)/cms
/cms.c \
123 $(USER_DIR
)/cms
/cms_menu_saveexit.c \
124 $(USER_DIR
)/common
/typeconversion.c \
125 $(USER_DIR
)/drivers
/display.c
128 common_filter_unittest_SRC
:= \
129 $(USER_DIR
)/common
/filter.c \
130 $(USER_DIR
)/common
/maths.c
133 encoding_unittest_SRC
:= \
134 $(USER_DIR
)/common
/encoding.c
137 flight_failsafe_unittest_SRC
:= \
138 $(USER_DIR
)/common
/bitarray.c \
139 $(USER_DIR
)/fc/rc_modes.c \
140 $(USER_DIR
)/fc/runtime_config.c \
141 $(USER_DIR
)/flight
/failsafe.c
143 flight_failsafe_unittest_DEFINES
:= \
147 flight_imu_unittest_SRC
:= \
148 $(USER_DIR
)/common
/bitarray.c \
149 $(USER_DIR
)/common
/maths.c \
150 $(USER_DIR
)/config
/feature.c \
151 $(USER_DIR
)/fc/rc_modes.c \
152 $(USER_DIR
)/flight
/position.c \
153 $(USER_DIR
)/flight
/imu.c
156 flight_mixer_unittest
:= \
157 $(USER_DIR
)/flight
/mixer.c \
158 $(USER_DIR
)/flight
/servos.c \
159 $(USER_DIR
)/common
/maths.c
162 gps_conversion_unittest_SRC
:= \
163 $(USER_DIR
)/common
/gps_conversion.c
166 io_serial_unittest_SRC
:= \
167 $(USER_DIR
)/io
/serial.c \
168 $(USER_DIR
)/drivers
/serial_pinconfig.c
171 ledstrip_unittest_SRC
:= \
172 $(USER_DIR
)/common
/bitarray.c \
173 $(USER_DIR
)/fc/rc_modes.c \
174 $(USER_DIR
)/io
/ledstrip.c
176 ledstrip_unittest_DEFINES
:= \
180 maths_unittest_SRC
:= \
181 $(USER_DIR
)/common
/maths.c
184 motor_output_unittest_SRC
:= \
185 $(USER_DIR
)/drivers
/dshot.c
188 osd_unittest_SRC
:= \
189 $(USER_DIR
)/osd
/osd.c \
190 $(USER_DIR
)/osd
/osd_elements.c \
191 $(USER_DIR
)/osd
/osd_warnings.c \
192 $(USER_DIR
)/common
/typeconversion.c \
193 $(USER_DIR
)/drivers
/display.c \
194 $(USER_DIR
)/common
/maths.c \
195 $(USER_DIR
)/common
/printf.c \
196 $(USER_DIR
)/common
/time.c \
197 $(USER_DIR
)/common
/filter.c \
198 $(USER_DIR
)/fc/runtime_config.c
200 osd_unittest_DEFINES
:= \
206 link_quality_unittest_SRC
:= \
207 $(USER_DIR
)/osd
/osd.c \
208 $(USER_DIR
)/osd
/osd_elements.c \
209 $(USER_DIR
)/osd
/osd_warnings.c \
210 $(USER_DIR
)/common
/typeconversion.c \
211 $(USER_DIR
)/drivers
/display.c \
212 $(USER_DIR
)/drivers
/serial.c \
213 $(USER_DIR
)/common
/crc.c \
214 $(USER_DIR
)/common
/maths.c \
215 $(USER_DIR
)/common
/printf.c \
216 $(USER_DIR
)/common
/streambuf.c \
217 $(USER_DIR
)/common
/time.c \
218 $(USER_DIR
)/fc/runtime_config.c \
219 $(USER_DIR
)/common
/bitarray.c \
220 $(USER_DIR
)/fc/rc_modes.c \
221 $(USER_DIR
)/rx
/rx.c \
222 $(USER_DIR
)/pg
/pg.c \
223 $(USER_DIR
)/rx
/crsf.c \
226 link_quality_unittest_DEFINES
:= \
228 USE_CRSF_LINK_STATISTICS
= \
229 USE_RX_LINK_QUALITY_INFO
=
232 $(USER_DIR
)/common
/crc.c \
233 $(USER_DIR
)/common
/streambuf.c \
237 rc_controls_unittest_SRC
:= \
238 $(USER_DIR
)/fc/rc_controls.c \
239 $(USER_DIR
)/pg
/pg.c \
240 $(USER_DIR
)/common
/bitarray.c \
241 $(USER_DIR
)/common
/crc.c \
242 $(USER_DIR
)/common
/maths.c \
243 $(USER_DIR
)/common
/streambuf.c \
244 $(USER_DIR
)/fc/rc_adjustments.c \
245 $(USER_DIR
)/fc/rc_modes.c
248 rx_crsf_unittest_SRC
:= \
249 $(USER_DIR
)/rx
/crsf.c \
250 $(USER_DIR
)/common
/crc.c \
251 $(USER_DIR
)/common
/printf.c \
252 $(USER_DIR
)/common
/typeconversion.c \
253 $(USER_DIR
)/common
/streambuf.c \
254 $(USER_DIR
)/drivers
/serial.c
257 rx_ibus_unittest_SRC
:= \
258 $(USER_DIR
)/rx
/ibus.c
261 rx_ranges_unittest_SRC
:= \
262 $(USER_DIR
)/common
/bitarray.c \
263 $(USER_DIR
)/common
/crc.c \
264 $(USER_DIR
)/common
/maths.c \
265 $(USER_DIR
)/common
/streambuf.c \
266 $(USER_DIR
)/fc/rc_modes.c \
267 $(USER_DIR
)/rx
/rx.c \
268 $(USER_DIR
)/pg
/pg.c \
272 rx_rx_unittest_SRC
:= \
273 $(USER_DIR
)/rx
/rx.c \
274 $(USER_DIR
)/fc/rc_modes.c \
275 $(USER_DIR
)/common
/bitarray.c \
276 $(USER_DIR
)/common
/maths.c \
277 $(USER_DIR
)/config
/feature.c \
280 rx_sumd_unittest_SRC
:= \
281 $(USER_DIR
)/common
/crc.c \
282 $(USER_DIR
)/common
/streambuf.c \
283 $(USER_DIR
)/rx
/sumd.c
285 scheduler_unittest_SRC
:= \
286 $(USER_DIR
)/scheduler
/scheduler.c \
287 $(USER_DIR
)/common
/crc.c \
288 $(USER_DIR
)/common
/streambuf.c
290 scheduler_unittest_DEFINES
:= \
293 sensor_gyro_unittest_SRC
:= \
294 $(USER_DIR
)/sensors
/gyro.c \
295 $(USER_DIR
)/sensors
/gyro_init.c \
296 $(USER_DIR
)/sensors
/boardalignment.c \
297 $(USER_DIR
)/common
/filter.c \
298 $(USER_DIR
)/common
/crc.c \
299 $(USER_DIR
)/common
/maths.c \
300 $(USER_DIR
)/common
/streambuf.c \
301 $(USER_DIR
)/common
/sensor_alignment.c \
302 $(USER_DIR
)/drivers
/accgyro
/accgyro_fake.c \
303 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
304 $(USER_DIR
)/pg
/pg.c \
305 $(USER_DIR
)/pg
/gyrodev.c
307 telemetry_crsf_unittest_SRC
:= \
308 $(USER_DIR
)/rx
/crsf.c \
309 $(USER_DIR
)/telemetry
/crsf.c \
310 $(USER_DIR
)/common
/crc.c \
311 $(USER_DIR
)/common
/maths.c \
312 $(USER_DIR
)/common
/streambuf.c \
313 $(USER_DIR
)/common
/gps_conversion.c \
314 $(USER_DIR
)/common
/printf.c \
315 $(USER_DIR
)/common
/typeconversion.c \
316 $(USER_DIR
)/fc/runtime_config.c
318 telemetry_crsf_unittest_DEFINES
:= \
321 __REVISION__
="revision"
324 telemetry_crsf_msp_unittest_SRC
:= \
325 $(USER_DIR
)/rx
/crsf.c \
326 $(USER_DIR
)/build
/atomic.c \
327 $(USER_DIR
)/common
/crc.c \
328 $(USER_DIR
)/common
/streambuf.c \
329 $(USER_DIR
)/common
/printf.c \
330 $(USER_DIR
)/common
/streambuf.c \
331 $(USER_DIR
)/drivers
/serial.c \
332 $(USER_DIR
)/common
/typeconversion.c \
333 $(USER_DIR
)/telemetry
/crsf.c \
334 $(USER_DIR
)/common
/gps_conversion.c \
335 $(USER_DIR
)/telemetry
/msp_shared.c \
336 $(USER_DIR
)/fc/runtime_config.c
338 telemetry_crsf_msp_unittest_DEFINES
:= \
339 USE_MSP_OVER_TELEMETRY
=
342 telemetry_hott_unittest_SRC
:= \
343 $(USER_DIR
)/telemetry
/hott.c \
344 $(USER_DIR
)/common
/gps_conversion.c
347 telemetry_ibus_unittest_SRC
:= \
348 $(USER_DIR
)/telemetry
/ibus_shared.c \
349 $(USER_DIR
)/telemetry
/ibus.c
351 timer_definition_unittest_EXPAND
:= yes
353 # SITL is a simulator with empty timerHardware and many hearders in target.c.
354 timer_definition_unittest_BLACKLIST
:= SITL
356 timer_definition_unittest_SRC
= \
357 $(TARGET_DIR
)/$(call get_base_target
,$1)/target.c
359 timer_definition_unittest_DEFINES
= \
361 BASE_TARGET
=$(call get_base_target
,$1)
363 timer_definition_unittest_INCLUDE_DIRS
= \
364 $(TEST_DIR
)/timer_definition_unittest.
include \
365 $(TARGET_DIR
)/$(call get_base_target
,$1)
367 transponder_ir_unittest_SRC
:= \
368 $(USER_DIR
)/drivers
/transponder_ir_ilap.c \
369 $(USER_DIR
)/drivers
/transponder_ir_arcitimer.c
371 ws2811_unittest_SRC
:= \
372 $(USER_DIR
)/drivers
/light_ws2811strip.c
374 huffman_unittest_SRC
:= \
375 $(USER_DIR
)/common
/huffman.c \
376 $(USER_DIR
)/common
/huffman_table.c
378 huffman_unittest_DEFINES
:= \
381 rcdevice_unittest_SRC
:= \
382 $(USER_DIR
)/common
/crc.c \
383 $(USER_DIR
)/common
/bitarray.c \
384 $(USER_DIR
)/fc/rc_modes.c \
385 $(USER_DIR
)/io
/rcdevice.c \
386 $(USER_DIR
)/io
/rcdevice_cam.c \
387 $(USER_DIR
)/pg
/pg.c \
389 pid_unittest_SRC
:= \
390 $(USER_DIR
)/common
/crc.c \
391 $(USER_DIR
)/common
/filter.c \
392 $(USER_DIR
)/common
/maths.c \
393 $(USER_DIR
)/common
/streambuf.c \
394 $(USER_DIR
)/drivers
/accgyro
/gyro_sync.c \
395 $(USER_DIR
)/fc/controlrate_profile.c \
396 $(USER_DIR
)/fc/runtime_config.c \
397 $(USER_DIR
)/flight
/pid.c \
398 $(USER_DIR
)/flight
/pid_init.c \
401 pid_unittest_DEFINES
:= \
403 USE_RC_SMOOTHING_FILTER
= \
404 USE_ABSOLUTE_CONTROL
= \
405 USE_LAUNCH_CONTROL
= \
408 rcdevice_unittest_DEFINES
:= \
411 vtx_unittest_SRC
:= \
412 $(USER_DIR
)/fc/core.c \
413 $(USER_DIR
)/fc/dispatch.c \
414 $(USER_DIR
)/fc/rc_controls.c \
415 $(USER_DIR
)/fc/rc_modes.c \
416 $(USER_DIR
)/fc/runtime_config.c \
417 $(USER_DIR
)/drivers
/vtx_common.c \
418 $(USER_DIR
)/drivers
/vtx_table.c \
419 $(USER_DIR
)/io
/vtx_control.c \
420 $(USER_DIR
)/io
/vtx.c \
421 $(USER_DIR
)/common
/bitarray.c
423 vtx_unittest_DEFINES
:= \
428 rx_spi_spektrum_unittest_SRC
:= \
429 $(USER_DIR
)/rx
/cyrf6936_spektrum.c
431 rx_spi_spektrum_unittest_DEFINES
:= \
435 rx_spi_expresslrs_unittest_SRC
:= \
436 $(USER_DIR
)/pg
/rx_spi_expresslrs.c \
437 $(USER_DIR
)/rx
/expresslrs_common.c \
438 $(USER_DIR
)/rx
/expresslrs.c \
439 $(USER_DIR
)/build
/atomic.c \
441 rx_spi_expresslrs_unittest_DEFINES
:= \
447 rx_spi_expresslrs_telemetry_unittest_SRC
:= \
448 $(USER_DIR
)/rx
/crsf.c \
449 $(USER_DIR
)/telemetry
/crsf.c \
450 $(USER_DIR
)/common
/crc.c \
451 $(USER_DIR
)/common
/maths.c \
452 $(USER_DIR
)/common
/streambuf.c \
453 $(USER_DIR
)/common
/gps_conversion.c \
454 $(USER_DIR
)/common
/printf.c \
455 $(USER_DIR
)/common
/typeconversion.c \
456 $(USER_DIR
)/rx
/expresslrs_telemetry.c \
457 $(USER_DIR
)/build
/atomic.c \
458 $(USER_DIR
)/telemetry
/msp_shared.c \
460 rx_spi_expresslrs_telemetry_unittest_DEFINES
:= \
463 USE_MSP_OVER_TELEMETRY
= \
465 # Please tweak the following variable definitions as needed by your
466 # project, except GTEST_HEADERS, which you can use in your own targets
467 # but shouldn't modify.
469 # Points to the root of Google Test, relative to where this file is.
470 # Remember to tweak this if you move this file.
471 GTEST_DIR
= ..
/..
/lib
/test/gtest
473 # Use clang/clang++ by default
477 ifeq ($(shell which
$(CC
) 2>/dev
/null
),)
478 $(info Falling back to
'clang'.
)
486 # These flags are needed for clang > 10 (linux / MacOS) to make test work:
487 # -Wno-c99-extensions
495 -Wno-error
=unused-command-line-argument \
499 -isystem
$(GTEST_DIR
)/inc \
501 -Wno-c99-extensions \
505 CC_VERSION
= $(shell $(CC
) -dumpversion
)
506 CXX_VERSION
= $(shell $(CXX
) -dumpversion
)
508 ifeq ($(shell $(CC
) -v
2>&1 | grep
-q
"clang version" && echo
"clang"),clang
)
510 # Please revisit versions when new clang version arrive. Supported versions: { Linux / OSX: 7 - 14 }
511 # Travis reports CC_VERSION of 4.2.1
512 CC_VERSION_MAJOR
:= $(firstword $(subst .
, ,$(CC_VERSION
)))
513 CC_VERSION_CHECK_MIN
:= 7
514 CC_VERSION_CHECK_MAX
:= 14
516 # Added flags for clang 11 - 13 are not backwards compatible
517 ifeq ($(shell expr
$(CC_VERSION_MAJOR
) \
> 10 \
& $(CC_VERSION_MAJOR
) \
< 14), 1)
520 -Wno-void-pointer-to-int-cast
523 ifeq ($(shell expr
$(CC_VERSION_MAJOR
) \
< $(CC_VERSION_CHECK_MIN
) \|
$(CC_VERSION_MAJOR
) \
> $(CC_VERSION_CHECK_MAX
)),1)
524 $(error
$(CC
) $(CC_VERSION
) is not supported. The officially supported version of clang is
'clang-12'. 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
).
)
527 COMMON_FLAGS
+= -fblocks
529 ifneq ($(OSFAMILY
), macosx
)
530 LDFLAGS
+= -lBlocksRuntime
535 $(info CC version
: $(shell $(CC
) --version
))
536 $(info CXX version
: $(shell $(CXX
) --version
))
540 ifeq ($(OSFAMILY
), macosx
)
549 COMMON_FLAGS
+= -pthread
552 # Flags passed to the C compiler.
553 C_FLAGS
= $(COMMON_FLAGS
) \
556 # Flags passed to the C++ compiler.
557 CXX_FLAGS
= $(COMMON_FLAGS
) \
560 # Compiler flags for coverage instrumentation
562 COVERAGE_FLAGS
:= --coverage
565 C_FLAGS
+= $(COVERAGE_FLAGS
)
566 CXX_FLAGS
+= $(COVERAGE_FLAGS
)
568 C_FLAGS
+= -D_GNU_SOURCE
570 # Set up the parameter group linker flags according to OS
571 ifeq ($(OSFAMILY
), macosx
)
572 LDFLAGS
+= -Wl
,-map
,$(OBJECT_DIR
)/$@.map
574 LDFLAGS
+= -Wl
,-T
,$(TEST_DIR
)/pg.
ld -Wl
,-Map
,$(OBJECT_DIR
)/$@.map
577 # Gather up all of the tests.
578 TEST_SRCS
= $(sort $(wildcard $(TEST_DIR
)/*.
cc))
579 TEST_BASENAMES
= $(TEST_SRCS
:$(TEST_DIR
)/%.
cc=%)
580 TESTS_TARGET_SPECIFIC
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),$(test)))
581 TESTS_TARGET_SPECIFIC_EXPANDED
= $(foreach test,$(TESTS_TARGET_SPECIFIC
),$(foreach \
582 target
,$(filter-out $($(test)_BLACKLIST
),$(VALID_TARGETS
)),$(test).
$(target
)))
584 TESTS
= $(foreach test,$(TEST_BASENAMES
),$(if
$($(test)_EXPAND
),,$(test)))
585 TESTS_ALL
= $(TESTS
) $(TESTS_TARGET_SPECIFIC_EXPANDED
)
586 TESTS_REPRESENTATIVE
= $(TESTS
) $(foreach test,$(TESTS_TARGET_SPECIFIC
), \
587 $(test).
$(word 1,$(filter-out $($(test)_BLACKLIST
),$(VALID_TARGETS
))))
589 # All Google Test headers. Usually you shouldn't change this
591 GTEST_HEADERS
= $(GTEST_DIR
)/inc
/gtest
/*.h
593 ## V : Set verbosity level based on the V= parameter
596 include ..
/..
/make
/build_verbosity.mk
598 # House-keeping build targets.
600 ## test : Build and run the non target specific Unit Tests (default goal)
601 test: $(TESTS
:%=test_
%)
603 ## test-all : Build and run all Unit Tests
604 test-all
: $(TESTS_ALL
:%=test_
%)
606 ## test-representative : Build and run a representative subset of the Unit Tests (i.e. run every expanded test only for the first target)
607 test-representative
: $(TESTS_REPRESENTATIVE
:%=test_
%)
609 ## junittest : Build and run the Unit Tests, producing Junit XML result files."
610 junittest
: EXEC_OPTS
= "--gtest_output=xml:$<_results.xml"
611 junittest
: $(TESTS
:%=test_
%)
615 ## help : print this help message and exit
616 ## what : print this help message and exit
617 ## usage : print this help message and exit
618 help what usage
: Makefile
620 @echo
"Makefile for Unit Tests"
623 @echo
" make [goal] "
625 @echo
"Valid goals are:"
627 @sed
-n
's/^## //p' $<
629 @echo
"Any of the Unit Test programs can be used as goals to build:"
630 @
$(foreach test, $(TESTS
), echo
" $(OBJECT_DIR)/$(test)/$(test)";)
632 @echo
"Any of the Unit Test programs (except for target specific unit tests) can be used as goals to build and run:"
633 @
$(foreach test, $(TESTS
), echo
" test_$(test)";)
636 @echo
"C compiler: $(CC): $(CC_VERSION)"
637 @echo
"C++ compiler: $(CXX): $(CXX_VERSION)"
639 ## clean : Cleanup the UnitTest binaries.
644 # Builds gtest.a and gtest_main.a.
646 # Usually you shouldn't tweak such internal variables, indicated by a
648 GTEST_SRCS_
= $(GTEST_DIR
)/src
/*.
cc $(GTEST_DIR
)/inc
/gtest
/*.h
$(GTEST_HEADERS
)
650 # For simplicity and to avoid depending on Google Test's
651 # implementation details, the dependencies specified below are
652 # conservative and not optimized. This is fine as Google Test
653 # compiles fast and for ordinary users its source rarely changes.
654 $(OBJECT_DIR
)/gtest-all.o
: $(GTEST_SRCS_
)
655 @echo
"compiling $@" "$(STDOUT)"
657 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -Wno-missing-field-initializers
-Wno-unused-const-variable
-c \
658 $(GTEST_DIR
)/src
/gtest-all.
cc -o
$@
660 $(OBJECT_DIR
)/gtest_main.o
: $(GTEST_SRCS_
)
661 @echo
"compiling $@" "$(STDOUT)"
663 $(V1
) $(CXX
) $(CXX_FLAGS
) -I
$(GTEST_DIR
) -c \
664 $(GTEST_DIR
)/src
/gtest_main.
cc -o
$@
666 $(OBJECT_DIR
)/gtest.a
: $(OBJECT_DIR
)/gtest-all.o
667 @echo
"linking $@" "$(STDOUT)"
668 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
670 $(OBJECT_DIR
)/gtest_main.a
: $(OBJECT_DIR
)/gtest-all.o
$(OBJECT_DIR
)/gtest_main.o
671 @echo
"linking $@" "$(STDOUT)"
672 $(V1
) $(AR
) $(ARFLAGS
) $@
$^
674 -include $(OBJECT_DIR
)/gtest-all.d \
675 $(OBJECT_DIR
)/gtest_main.d
678 # includes in test dir must override includes in user dir, unless the user
679 # specifies a list of endorsed directories in ${target}_INCLUDE_DIRS.
680 test_include_dirs
= $1 $(TEST_DIR
) $(USER_DIR
)
681 test_cflags
= $(addprefix -I
,$(call test_include_dirs
,$1))
684 # target name extractor
685 # param $1 = expanded test name in the form of test.target
686 target
= $(1:$(basename $1).
%=%)
688 # canned recipe for all test builds
690 # variable expansion rules of thumb (number of $'s):
691 # * parameters: one $, e.g. $1
692 # * statically accessed variables set elsewhere: one $, e.g. $(C_FLAGS)
693 # * dynamically accessed variables set elsewhere: one $, e.g. $($1_SRC)
694 # * make functions accessing only the above: one $, e.g. $(basename $1)
695 # * dynamically set and accessed variables: two $, e.g. $$($1_OBJS)
696 # * make functions accessing dynamically set variables: two $,
697 # e.g. $$(call test_cflags,$$($1_INCLUDE_DIRS))
699 # param $1 = plain test name for global tests, test.target for per-target tests
700 define test-specific-stuff
702 ifeq ($1,$(basename $1))
703 # standard global test
704 $1_OBJS = $(patsubst \
705 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$(patsubst \
706 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$($1_SRC:=.o
)))
708 # test executed for each target, $1 has the form of test.target
709 $1_SRC = $(addsuffix .o
,$(call
$(basename $1)_SRC
,$(call target
,$1)))
710 $1_OBJS = $$(patsubst \
711 $(TEST_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
712 $(USER_DIR
)/%,$(OBJECT_DIR
)/$1/%,$$(patsubst \
713 $(TARGET_DIR
)/$(call get_base_target
,$(call target
,$1))/%,$(OBJECT_DIR
)/$1/%,$$($1_SRC))))
714 $1_DEFINES = $(call
$(basename $1)_DEFINES
,$(call target
,$1))
715 $1_INCLUDE_DIRS = $(call
$(basename $1)_INCLUDE_DIRS
,$(call target
,$1))
718 # $$(info $1 -v-v-------)
719 # $$(info $1_SRC: $$($1_SRC))
720 # $$(info $1_OBJS: $$($1_OBJS))
721 # $$(info $1 -^-^-------)
723 # include generated dependencies
724 -include $$($1_OBJS:.o
=.d
)
725 -include $(OBJECT_DIR
)/$1/$(basename $1).d
727 $(OBJECT_DIR
)/$1/%.c.o
: $(USER_DIR
)/%.c
728 @echo
"compiling $$<" "$(STDOUT)"
729 $(V1
) mkdir
-p
$$(dir $$@
)
730 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
731 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
734 $(OBJECT_DIR
)/$1/%.c.o
: $(TEST_DIR
)/%.c
735 @echo
"compiling test c file: $$<" "$(STDOUT)"
736 $(V1
) mkdir
-p
$$(dir $$@
)
737 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
738 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
741 ifneq ($1,$(basename $1))
742 # per-target tests may compile files from the target directory
743 $(OBJECT_DIR
)/$1/%.c.o
: $(TARGET_DIR
)/$(call get_base_target
,$(call target
,$1))/%.c
744 @echo
"compiling target c file: $$<" "$(STDOUT)"
745 $(V1
) mkdir
-p
$$(dir $$@
)
746 $(V1
) $(CC
) $(C_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
747 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
751 $(OBJECT_DIR
)/$1/$(basename $1).o
: $(TEST_DIR
)/$(basename $1).
cc
752 @echo
"compiling $$<" "$(STDOUT)"
753 $(V1
) mkdir
-p
$$(dir $$@
)
754 $(V1
) $(CXX
) $(CXX_FLAGS
) $$(call test_cflags
,$$($1_INCLUDE_DIRS)) \
755 $$(foreach def
,$$($1_DEFINES),-D
$$(def
)) \
758 $(OBJECT_DIR
)/$1/$(basename $1): $$($1_OBJS) \
759 $(OBJECT_DIR
)/$1/$(basename $1).o \
760 $(OBJECT_DIR
)/gtest_main.a
762 @echo
"linking $$@" "$(STDOUT)"
763 $(V1
) mkdir
-p
$(dir $$@
)
764 $(V1
) $(CXX
) $(CXX_FLAGS
) $(LDFLAGS
) $$^
-o
$$@
766 test_
$1: $(OBJECT_DIR
)/$1/$(basename $1)
767 $(V1
) $$< $$(EXEC_OPTS
) "$(STDOUT)" && echo
"running $$@: PASS"
772 ifeq ($(MAKECMDGOALS
),test-all
)
773 $(eval
$(foreach test,$(TESTS_ALL
),$(call test-specific-stuff
,$(test))))
775 ifeq ($(MAKECMDGOALS
),test-representative
)
776 $(eval
$(foreach test,$(TESTS_REPRESENTATIVE
),$(call test-specific-stuff
,$(test))))
778 $(eval
$(foreach test,$(TESTS
),$(call test-specific-stuff
,$(test))))
782 $(foreach test,$(TESTS_ALL
),$(if
$($(basename $(test))_SRC
),,$(error \
783 Test
'unit/$(basename $(test)).cc' has no
'$(basename $(test))_SRC' variable defined
)))
784 $(foreach var
,$(filter-out TARGET_SRC
,$(filter %_SRC
,$(.VARIABLES
))),$(if
$(filter $(var
:_SRC
=)%,$(TESTS_ALL
)),,$(error \
785 Variable
'$(var)' has no
'unit/$(var:_SRC=).cc' test)))
789 @echo
========== BASE TARGETS
==========
790 @echo
$(BASE_TARGETS
)
791 @echo
========== ALT TARGETS
==========
793 @echo
========== VALID_TARGETS
==========
794 @echo
$(VALID_TARGETS
)
795 @echo
========== BASE
/ALT PAIRS
==========
796 @echo
$(BASE_ALT_PAIRS
)
797 @echo
========== ALT
/BASE MAPPING
==========
798 @echo
$(foreach target
,$(ALT_TARGETS
),$(target
)\
>$(call get_base_target
,$(target
)))
799 @echo
========== ALT
/BASE FULL MAPPING
==========
800 @echo
$(foreach target
,$(VALID_TARGETS
),$(target
)\
>$(call get_base_target
,$(target
)))