Re: About PKG_CHECK_MODULES



On Monday 22 November 2004 00:30, dzho002 wrote:
> Hello All,
>
> Currently, I am porting my old program based on gtkmm
> 2.2 to gtkmm 2.4. I understood I should change the
> PKG_CHECK_MODULES line in file "configure.in":
> From:
> PKG_CHECK_MODULES(GTKMM,gtkmm-2.0>=${gtkmm_min_version})
> To
> PKG_CHECK_MODULES(GTKMM,gtkmm-2.4>=${gtkmm_min_version})
>
> I am just wondering if there is a way to let the
> configure scripts automatically dectect the installed
> gtkmm version (2.0 or 2.4). So, if the program is
> configured in a gtkmm2.0 system, gtkmm2.0 library will
> be used. Or in a 2.4 system, gtkmm2.4 library will be
> used.

The signature of the PKG_CHECK_MODULES macro is given as this:
PKG_CHECK_MODULES(NAME, lib >= version ..., action-if, action-not)

The action in the fourth argument of PKG_CHECK_MODULES will be performed if 
the test in the second argument one fails (the third argument is performed if 
it succeeds), so you can just chain the tests.  Here is what I do:

AC_DEFUN(PKG_CHECK_GTKMM, [

  GTKMM_VER=0
  PKG_CHECK_MODULES(GTKMM, gtkmm-2.4 >= 2.4.0,
  [
    GTKMM_VER=24
  ],
  [
    PKG_CHECK_MODULES(GTKMM, gtkmm-2.0 >= 2.0.0)
    GTKMM_VER=20
  ])
  AC_SUBST(GTKMM_VER)
])

You should then use the GTKMM_VER variable in your Makefile.am file by making 
a define such as the following in your INCLUDES line:

-DGTKMM_VERSION= GTKMM_VER@

Your user code can then test GKTMM_VERSION to do a conditional compile when 
compiling code which differs between gtkmm-2.0/2 and gtkmm-2.4.

Chris

Note:

Here is my version of PKG_CHECK_MODULES (I think the standard version was 
defective and double-reported the failure of the test for GKTMM-2.4 and I had 
to amend it to obtain a more sensible report, but I may have that wrong).  
Check your version of the PKG_CHECK_MODULES macro.

AC_DEFUN(PKG_CHECK_MODULES, [
  succeeded=no

  if test -z "$PKG_CONFIG"; then
    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  fi

  if test "$PKG_CONFIG" = "no" ; then
     echo "*** The pkg-config script could not be found. Make sure it is"
     echo "*** in your path, or set the PKG_CONFIG environment variable"
     echo "*** to the full path to pkg-config."
     echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get 
pkg-config."
  else
     PKG_CONFIG_MIN_VERSION=0.9.0
     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
        AC_MSG_CHECKING(for $2)

        if $PKG_CONFIG --exists "$2" ; then
            AC_MSG_RESULT(yes)
            succeeded=yes

            AC_MSG_CHECKING($1_CFLAGS)
            $1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
            AC_MSG_RESULT($$1_CFLAGS)

            AC_MSG_CHECKING($1_LIBS)
            $1_LIBS=`$PKG_CONFIG --libs "$2"`
            AC_MSG_RESULT($$1_LIBS)
        else
            $1_CFLAGS=""
            $1_LIBS=""
            AC_MSG_RESULT([no])
        fi

        AC_SUBST($1_CFLAGS)
        AC_SUBST($1_LIBS)
     else
        echo "*** Your version of pkg-config is too old. You need version 
$PKG_CONFIG_MIN_VERSION or newer."
        echo "*** See http://www.freedesktop.org/software/pkgconfig";
     fi
  fi

  if test $succeeded = yes; then
     ifelse([$3], , :, [$3])
  else
     ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider 
adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a 
nonstandard prefix so pkg-config can find them.]), [$4])
  fi
])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]