* m4/oln-with-lib.m4 (_OLN_WITH_LIB): Make all arguments
mandatory.
(OLN_WITH_LIB_PKG_CONFIG, _OLN_WITH_LIB_PKG_CONFIG): New macros.
* configure.ac: Use OLN_WITH_LIB_PKG_CONFIG to handle Magick++
---
ChangeLog | 9 +++++
configure.ac | 44 +-----------------------
m4/oln-with-lib.m4 | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 105 insertions(+), 44 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e62355c..76dbf12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-10-21 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Revamp the handling of Magick++.
+
+ * m4/oln-with-lib.m4 (_OLN_WITH_LIB): Make all arguments
+ mandatory.
+ (OLN_WITH_LIB_PKG_CONFIG, _OLN_WITH_LIB_PKG_CONFIG): New macros.
+ * configure.ac: Use OLN_WITH_LIB_PKG_CONFIG to handle Magick++
+
2010-10-20 Roland Levillain <roland(a)lrde.epita.fr>
Have configure be terser.
diff --git a/configure.ac b/configure.ac
index 09b1fa4..02cd8bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -191,9 +191,6 @@ AM_CONDITIONAL([DARWIN], [echo "$host_os" | grep
'^darwin'])
## External libraries. ##
## -------------------- ##
-# Prepare calls to pkg-config
-PKG_PROG_PKG_CONFIG
-
### Support for FreeImagePlus has been disabled for Olena 1.0.
## OLN_WITH_LIB([FreeImagePlus], [FreeImagePlus.h], [freeimageplus])
@@ -249,45 +246,8 @@ OLN_WITH_LIB([CFITSIO], [fitsio.h], [cfitsio])
## Magick++. ##
## --------- ##
-# FIXME: We should handle Magick++ both with Magick++-config and
-# pkg-config? instead of OLN_WITH_LIB. See how other projects handle
-# this.
-
-
-AC_ARG_WITH([magickxx],
- [AC_HELP_STRING([--with-magickxx],
- [enable magickxx support (default)])],
- [with_magickxx=$withval],
- [with_magickxx='yes'])
-
-oln_have_magickxx=no
-
-if test "x$with_magickxx" != xno; then
- # Try to use ImageMagick from a specified path.
- if test "x$with_magickxx" != xyes; then
- AC_MSG_CHECKING([with given path $with_magickxx])
- OLN_WITH_LIB([Magick++], [Magick++.h], [Magick++], [magickxx],
- [MAGICKXX])
- fi
-
- # Check with pkg-config if previous test failed or if no path have
- # been passed through --with-magickxx argument.
- if test "x$oln_have_magickxx" = xno; then
- PKG_CHECK_MODULES(MAGICKXX,[ImageMagick++], oln_have_magickxx=yes,
- oln_have_magickxx=no)
-
- if test "x$oln_have_magickxx" = xyes; then
- AC_DEFINE([HAVE_MAGICKXX], 1,
- [Define to 1 if we can use libMagick++])
- # Use standard variable names.
- MAGICKXX_CPPFLAGS="$MAGICKXX_CFLAGS"
- MAGICKXX_LDFLAGS="$MAGICKXX_LIBS"
- AC_SUBST(MAGICKXX_CPPFLAGS)
- AC_SUBST(MAGICKXX_LDFLAGS)
- fi
- fi
-fi
-
+OLN_WITH_LIB_PKG_CONFIG([Magick++], [Magick++.h], [Magick++], [magickxx],
+ [MAGICKXX], [], [ImageMagick++])
AM_CONDITIONAL(HAVE_MAGICKXX, test "x$oln_have_magickxx" = xyes)
#------------------------------------------------------------
diff --git a/m4/oln-with-lib.m4 b/m4/oln-with-lib.m4
index 780923c..01530b9 100644
--- a/m4/oln-with-lib.m4
+++ b/m4/oln-with-lib.m4
@@ -1,6 +1,7 @@
# -*- Autoconf -*-
-# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+# (LRDE)
#
# This file is part of Olena.
#
@@ -61,7 +62,7 @@ m4_default([$5], m4_toupper([$3])),dnl
# _OLN_WITH_LIB(PACKAGE, HEADER, LIBRARY, SHELL_NAME, CPP_NAME,
-# [OTHER-LIBRARIES])
+# OTHER-LIBRARIES)
# -------------------------------------------------------------
# Actual implementation of OLN_WITH_LIB.
AC_DEFUN([_OLN_WITH_LIB],
@@ -101,3 +102,94 @@ AC_DEFUN([_OLN_WITH_LIB],
AM_CONDITIONAL([HAVE_$5], [test x$oln_have_$4 = xyes])
AC_LANG_POP([C++])
])# _OLN_WITH_LIB
+
+
+
+# FIXME: Factor the following macros with the previous ones.
+
+
+# OLN_WITH_LIB_PKG_CONFIG(PACKAGE, HEADER, LIBRARY, [SHELL_NAME], [CPP_NAME],
+# [OTHER-LIBRARIES], [MODULE])
+# ---------------------------------------------------------------------------
+# Like OLN_WITH_LIB, except that `pkg-config' is first tried to look
+# for the module (library) named MODULE. If this first step fails
+# (because `pkg-config' is missing, or not working, or cannot find
+# MODULE), use a fall-back code similar to OLN_WITH_LIB's.
+#
+# If not given, MODULE defaults to PACKAGE.
+#
+# Example of use:
+#
+# OLN_WITH_LIB_PKG_CONFIG([Magick++], [Magick++.h], [Magick++], [magickxx],
+# [MAGICKXX], [], [ImageMagick++])
+#
+AC_DEFUN([OLN_WITH_LIB_PKG_CONFIG],
+[dnl Do some sanity checking of the arguments.
+m4_if([$1], , [AC_FATAL([$0: missing argument 1])])dnl
+m4_if([$2], , [AC_FATAL([$0: missing argument 2])])dnl
+m4_if([$3], , [AC_FATAL([$0: missing argument 3])])dnl
+_OLN_WITH_LIB_PKG_CONFIG([$1], [$2], [$3],dnl
+dnl Process optional arguments.
+m4_default([$4], m4_tolower([$3])),dnl
+m4_default([$5], m4_toupper([$3])),dnl
+[$6],dnl
+m4_default([$7], [$1]))dnl
+])# OLN_WITH_LIB_PKG_CONFIG
+
+# _OLN_WITH_LIB_PKG_CONFIG(PACKAGE, HEADER, LIBRARY, SHELL_NAME, CPP_NAME,
+# OTHER-LIBRARIES, MODULE)
+# ------------------------------------------------------------------------
+# Actual implementation of OLN_WITH_LIB_PKG_CONFIG.
+AC_DEFUN([_OLN_WITH_LIB_PKG_CONFIG],
+[dnl
+ AC_REQUIRE([AC_PROG_CXX])
+ AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+ AC_LANG_PUSH([C++])
+ AC_ARG_WITH([$4],
+ [AC_HELP_STRING([--with-$4@<:@=DIR@:>@],
+ [use $1 (DIR = prefix for $1 installation)])])
+ $5_CPPFLAGS=''
+ $5_LDFLAGS=''
+ if test "x$with_$4" != xno; then
+ # First try with pkg-config.
+ PKG_CHECK_EXISTS([$7], [oln_with_lib_$4_uses_pkg_config=yes])
+ if test x$oln_with_lib_$4_uses_pkg_config = xyes; then
+ # `pkg-config' seems to work and has been able to find the library;
+ # use it.
+ PKG_CHECK_MODULES([$5], [$7],
+ [oln_have_$4=yes
+ AC_DEFINE([HAVE_$5], 1, [Define to 1 if we can use $1])
+ # Define CPPFLAGS and LDFLAGS.
+ $5_CPPFLAGS="$$5_CFLAGS"
+ $5_LDFLAGS="$$5_LIBS"])
+ else
+ # `pkg-config' is absent, unusable or is unable to find the library;
+ # use our fall-back code.
+ if test -n "$with_$4"; then
+ $5_CPPFLAGS="-I${with_$4}/include"
+ $5_LDFLAGS="-L${with_$4}/lib"
+ fi
+ oln_save_CPPFLAGS=$CPPFLAGS
+ oln_save_LDFLAGS=$LDFLAGS
+ CPPFLAGS="$$5_CPPFLAGS $CPPFLAGS"
+ LDFLAGS="$$5_LDFLAGS $LDFLAGS"
+ oln_have_$4=no
+ AC_CHECK_HEADER([$2],
+ [AC_CHECK_LIB([$3],
+ [main],
+ [oln_have_$4=yes
+ $5_LDFLAGS="$$5_LDFLAGS -l$3 $6"
+ AC_DEFINE([HAVE_$5], 1, [Define to 1 if we can use $1])],
+ [], [$6]
+ )]
+ )
+ CPPFLAGS=$oln_save_CPPFLAGS
+ LDFLAGS=$oln_save_LDFLAGS
+ TOOLS_LDFLAGS="$TOOLS_LDFLAGS $$5_LDFLAGS"
+ fi
+ fi
+ AC_SUBST([$5_CPPFLAGS])
+ AC_SUBST([$5_LDFLAGS])
+ AM_CONDITIONAL([HAVE_$5], [test x$oln_have_$4 = xyes])
+ AC_LANG_POP([C++])
+])# _OLN_WITH_LIB_PKG_CONFIG
--
1.5.6.5