summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xorg-macros.m4.in66
1 files changed, 66 insertions, 0 deletions
diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
index e157cfd..98c96cd 100644
--- a/xorg-macros.m4.in
+++ b/xorg-macros.m4.in
@@ -960,6 +960,10 @@ AC_MSG_RESULT([$build_specs])
# Test cases may or may not use Automake "Support for test suites"
# They may or may not use the software utility library GLib
#
+# When used in conjunction with XORG_WITH_GLIB, use both AM_CONDITIONAL
+# ENABLE_UNIT_TESTS and HAVE_GLIB. Not all unit tests may use glib.
+# The variable enable_unit_tests is used by other macros in this file.
+#
# Interface to module:
# ENABLE_UNIT_TESTS: used in makefiles to conditionally build tests
# enable_unit_tests: used in configure.ac for additional configuration
@@ -968,6 +972,7 @@ AC_MSG_RESULT([$build_specs])
# parm1: specify the default value, yes or no.
#
AC_DEFUN([XORG_ENABLE_UNIT_TESTS],[
+AC_BEFORE([$0], [XORG_WITH_GLIB])
m4_define([_defopt], m4_default([$1], [auto]))
AC_ARG_ENABLE(unit-tests, AS_HELP_STRING([--enable-unit-tests],
[Enable building unit test cases (default: ]_defopt[)]),
@@ -978,6 +983,67 @@ AC_MSG_CHECKING([whether to build unit test cases])
AC_MSG_RESULT([$enable_unit_tests])
]) # XORG_ENABLE_UNIT_TESTS
+# XORG_WITH_GLIB([MIN-VERSION], [DEFAULT])
+# ----------------------------------------
+# Minimum version: 1.13.0
+#
+# GLib is a library which provides advanced data structures and functions.
+# This macro enables a module to test for the presence of Glib.
+#
+# When used with ENABLE_UNIT_TESTS, it is assumed GLib is used for unit testing.
+# Otherwise the value of $enable_unit_tests is blank.
+#
+# Interface to module:
+# HAVE_GLIB: used in makefiles to conditionally build targets
+# with_glib: used in configure.ac to know if GLib has been found
+# --with-glib: 'yes' user instructs the module to use glib
+# 'no' user instructs the module not to use glib
+#
+AC_DEFUN([XORG_WITH_GLIB],[
+AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+m4_define([_defopt], m4_default([$2], [auto]))
+AC_ARG_WITH(glib, AS_HELP_STRING([--with-glib],
+ [Use GLib library for unit testing (default: ]_defopt[)]),
+ [with_glib=$withval], [with_glib=]_defopt)
+m4_undefine([_defopt])
+
+have_glib=no
+# Do not probe GLib if user explicitly disabled unit testing
+if test "x$enable_unit_tests" != x"no"; then
+ # Do not probe GLib if user explicitly disabled it
+ if test "x$with_glib" != x"no"; then
+ m4_ifval(
+ [$1],
+ [PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $1], [have_glib=yes], [have_glib=no])],
+ [PKG_CHECK_MODULES([GLIB], [glib-2.0], [have_glib=yes], [have_glib=no])]
+ )
+ fi
+fi
+
+# Not having GLib when unit testing has been explicitly requested is an error
+if test "x$enable_unit_tests" = x"yes"; then
+ if test "x$have_glib" = x"no"; then
+ AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
+ fi
+fi
+
+# Having unit testing disabled when GLib has been explicitly requested is an error
+if test "x$enable_unit_tests" = x"no"; then
+ if test "x$with_glib" = x"yes"; then
+ AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
+ fi
+fi
+
+# Not having GLib when it has been explicitly requested is an error
+if test "x$with_glib" = x"yes"; then
+ if test "x$have_glib" = x"no"; then
+ AC_MSG_ERROR([--with-glib=yes specified but glib-2.0 not found])
+ fi
+fi
+
+AM_CONDITIONAL([HAVE_GLIB], [test "$have_glib" = yes])
+]) # XORG_WITH_GLIB
+
# XORG_CHECK_MALLOC_ZERO
# ----------------------
# Minimum version: 1.0.0