From 25e962203154ebbed0685011357aaf1f99c2de83 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Tue, 16 Dec 2025 21:58:42 +0100
Subject: [PATCH] Makefile: add functionality to determine cmocka version
cmocka 2.0.0 introduces a couple of changes that require version-dependent
code to be used. Add macros to determine the cmocka version. If the version
can't be determined, assume 1.1.0.
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Makefile.inc | 2 +-
create-config.mk | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
@@ -82,7 +82,7 @@ OPTFLAGS := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
WARNFLAGS := -Werror -Wall -Wextra -Wformat=2 $(WFORMATOVERFLOW) -Werror=implicit-int \
-Werror=implicit-function-declaration -Werror=format-security \
$(WNOCLOBBERED) -Werror=cast-qual $(ERROR_DISCARDED_QUALIFIERS) $(W_URCU_TYPE_LIMITS)
-CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) \
+CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_CMOCKA_VERSION) \
-DBIN_DIR=\"$(bindir)\" -DMULTIPATH_DIR=\"$(plugindir)\" \
-DRUNTIME_DIR=\"$(runtimedir)\" \
-DCONFIG_DIR=\"$(configdir)\" -DEXTRAVERSION=\"$(EXTRAVERSION)\" -MMD -MP
@@ -73,6 +73,10 @@ TEST_URCU_TYPE_LIMITS = $(shell \
$(CC) -c -Werror=type-limits -o /dev/null -xc - 2>/dev/null \
|| echo -Wno-type-limits )
+CMOCKA_VERSION = $(shell \
+ ($(PKGCONFIG) --modversion cmocka 2>/dev/null || echo "1.1.0" ) | \
+ awk -F. '{ printf("-DCMOCKA_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+
DEFINES :=
ifneq ($(call check_func,dm_task_no_flush,$(devmapper_incdir)/libdevmapper.h),0)
@@ -169,6 +173,7 @@ $(TOPDIR)/config.mk: $(multipathdir)/autoconfig.h
@echo creating $@
@echo "FPIN_SUPPORT := $(FPIN_SUPPORT)" >$@
@echo "FORTIFY_OPT := $(FORTIFY_OPT)" >>$@
+ @echo "D_CMOCKA_VERSION := $(call CMOCKA_VERSION)" >>$@
@echo "SYSTEMD := $(SYSTEMD)" >>$@
@echo "ANA_SUPPORT := $(ANA_SUPPORT)" >>$@
@echo "STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector)" >>$@
--
2.33.0