diff --git a/tests/Makefile.common b/tests/Makefile.common index 74a3c5a7a9..a8bb19c4f1 100644 --- a/tests/Makefile.common +++ b/tests/Makefile.common @@ -157,11 +157,14 @@ $($(1)-sysobjs): $(testobj)/$(1)/%.o: $$$$*.c $$($(1)-config-file) # Link against Cmocka if not disabled ifeq ($(strip $(filter-out 0 n no,$($(1)-no_test_framework))),) +ifneq ($(USE_SYSTEM_CMOCKA),) $($(1)-objs): TEST_CFLAGS += -I$(cmockasrc)/include -$($(1)-bin): TEST_LDFLAGS += -L$(cmockaobj)/src -lcmocka -Wl,-rpath=$(cmockaobj)/src +$($(1)-bin): TEST_LDFLAGS += -L$(cmockaobj)/src -Wl,-rpath=$(cmockaobj)/src $($(1)-bin): TEST_CFLAGS += -I$(cmockasrc)/include $($(1)-bin): $(CMOCKA_LIB) endif +$($(1)-bin): TEST_LDFLAGS += -lcmocka +endif $($(1)-bin): $($(1)-objs) $($(1)-sysobjs) $(HOSTCC) $$^ $($(1)-cflags) $$(TEST_LDFLAGS) -o $$@ diff --git a/tests/Makefile.mk b/tests/Makefile.mk index f838f8336b..f3f122dd38 100644 --- a/tests/Makefile.mk +++ b/tests/Makefile.mk @@ -24,6 +24,15 @@ TEST_CFLAGS += --coverage TEST_LDFLAGS += --coverage endif +# Use system cmoka in default, or build from 3rdparty source code if requested +USE_SYSTEM_CMOCKA ?= 1 +ifeq ($(USE_SYSTEM_CMOCKA),1) +ifeq ($(shell $(HOSTPKG_CONFIG) --exists cmocka || echo 1),1) +$(warning No system cmocka, build from 3rdparty instead...) +USE_SYSTEM_CMOCKA=0 +endif +endif + stages := decompressor bootblock romstage smm verstage stages += ramstage rmodule postcar libagesa @@ -186,6 +195,7 @@ help-unit-tests help:: @echo '*** coreboot unit-tests targets ***' @echo ' Use "COV=1 make [target]" to enable code coverage for unit tests' @echo ' Use "GDB_DEBUG=1 make [target]" to build with debug symbols' + @echo ' Use "USE_SYSTEM_CMOCKA=0 make [target]" to build Cmocka from source' @echo ' unit-tests - Run all unit-tests from tests/' @echo ' clean-unit-tests - Remove unit-tests build artifacts' @echo ' list-unit-tests - List all unit-tests'