Changeset 1398 for stable


Ignore:
Timestamp:
Aug 2, 2009 12:46:01 PM (11 years ago)
Author:
stefan
Message:

add some macros to setup a project directory with the use of pkg-config

File:
1 edited

Legend:

Unmodified
Added
Removed
  • stable/BSPsplit/coin.m4

    r1395 r1398  
    33423342
    33433343]) # AC_COIN_HAS_GLPK
     3344
     3345###########################################################################
     3346#                           COIN_HAS_PKGCONFIG                            #
     3347###########################################################################
     3348
     3349# This macro checks whether a pkg-config tool with a minimal version number is available.
     3350# If so, then the variable PKGCONFIG is set to its path.
     3351# If not, PKGCONFIG is set to "".
     3352# The minimal version number can be given as first parameter, by default it is 0.9.0.
     3353# This macro is a modified version of PKG_PROG_PKG_CONFIG in pkg.m4
     3354AC_DEFUN([AC_COIN_HAS_PKGCONFIG],
     3355[AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
     3356
     3357if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
     3358  AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
     3359fi
     3360if test -n "$PKG_CONFIG"; then
     3361  _pkg_min_version=m4_default([$1], [0.9.0])
     3362  AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
     3363  if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
     3364    AC_MSG_RESULT([yes])
     3365  else
     3366    AC_MSG_RESULT([no])
     3367    PKG_CONFIG=""
     3368  fi
     3369fi
     3370
     3371# check if pkg-config supports the short-errors flag
     3372if test -n "$PKG_CONFIG" && \
     3373  $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
     3374  pkg_short_errors=" --short-errors "
     3375else
     3376  pkg_short_errors=""
     3377fi
     3378
     3379])
     3380
     3381###########################################################################
     3382#                           COIN_PKG_CHECK_EXISTS                         #
     3383###########################################################################
     3384
     3385# COIN_PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
     3386#
     3387# Check to see whether a particular module exists.  Similar
     3388# to PKG_CHECK_MODULES(), but set only the variables $1_VERSION and $1_PKG_ERRORS variables
     3389#
     3390AC_DEFUN([AC_COIN_PKG_CHECK_EXISTS],
     3391[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
     3392if test -n "$PKG_CONFIG" ; then
     3393  if $PKG_CONFIG --exists "m4_tolower($1)"; then
     3394    m4_toupper($1)[]_VERSION=`$PKG_CONFIG --modversion "m4_tolower($1)" 2>/dev/null`
     3395    m4_ifval([$2], [$2], [:])
     3396  else
     3397    m4_toupper($1)_PKG_ERRORS=`$PKG_CONFIG $pkg_short_errors --errors-to-stdout --print-errors "m4_tolower($1)"`
     3398    $3
     3399  fi
     3400else
     3401  AC_MSG_ERROR("Cannot check for existance of module $1 without pkg-config")
     3402fi
     3403])
     3404
     3405
     3406###########################################################################
     3407#                           COIN_PKG_CHECK_MODULE                         #
     3408###########################################################################
     3409
     3410# COIN_PKG_CHECK_MODULE(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
     3411#
     3412# Checks whether a pkg-config file for a given module is available.
     3413# If so, sets MODULE_CFLAGS, MODULE_LIBS, and MODULES_DATA and executes ACTION-IF-FOUND.
     3414# If not, then ACTION-IF-NOT-FOUND is executed.
     3415# A reason for not finding a package is stored in MODULE_PKG_ERRORS
     3416#
     3417# --------------------------------------------------------------
     3418AC_DEFUN([AC_COIN_PKG_CHECK_MODULE],
     3419[AC_REQUIRE([AC_COIN_HAS_PKGCONFIG])
     3420
     3421AC_COIN_PKG_CHECK_EXISTS([$1],
     3422  [ m4_toupper($1)[]_CFLAGS=`$PKG_CONFIG --cflags "m4_tolower($1)" 2>/dev/null`
     3423    m4_toupper($1)[]_LIBS=`$PKG_CONFIG --libs "m4_tolower($1)" 2>/dev/null`
     3424    m4_toupper($1)[]_DATA=`$PKG_CONFIG --variable=datadir "m4_tolower($1)" 2>/dev/null`
     3425    $2
     3426  ],
     3427  [ $3 ])
     3428
     3429])# PKG_CHECK_MODULES
     3430
     3431###########################################################################
     3432#                           COIN_MAIN_SUBDIR2                             #
     3433###########################################################################
     3434
     3435# This is the macro for AC_COIN_MAIN_SUBDIRS taking care of ONE (or two or three) argument(s)
     3436# It calles AC_COIN_HAS_PROJECT with the given argument(s) and adds $1 to the CONFIG_SUBDIRS, if
     3437# either argument $3 is given and the file $2/$1/$3 is available in $srcdir,
     3438# or $3 is not given and the file $2/$1/configure is available in $srcdir,
     3439# where $2 = . if not given
     3440AC_DEFUN([AC_COIN_MAIN_SUBDIR2],
     3441[AC_ARG_VAR([COIN_SKIP_PROJECTS],[Set to the subdirectories of projects that should be skipped in the configuration])
     3442
     3443AC_MSG_CHECKING([for project $1])
     3444# First check, if the sub-project is actually available
     3445
     3446m4_tolower(coin_has_$1)=notGiven
     3447
     3448# check if user wants to skip project in any case
     3449if test x"$COIN_SKIP_PROJECTS" != x; then
     3450  for dir in $COIN_SKIP_PROJECTS; do
     3451    if test $dir = "$1"; then
     3452      m4_tolower(coin_has_$1)=skipping
     3453    fi
     3454    if test $dir = "$2/$1"; then
     3455      m4_tolower(coin_has_$1)=skipping
     3456    fi
     3457  done
     3458fi
     3459
     3460if test $m4_tolower(coin_has_$1) != skipping; then
     3461  if test $PACKAGE_TARNAME = m4_tolower($1); then
     3462    m4_tolower(coin_has_$1)=.
     3463  fi
     3464
     3465  AC_ARG_WITH([m4_tolower($1)-lib],
     3466    AC_HELP_STRING([--with-m4_tolower($1)-lib],
     3467                   [linker flags for using project $1]),
     3468      [m4_tolower(coin_has_$1)=installed],
     3469      [])
     3470
     3471  AC_ARG_WITH([m4_tolower($1)-incdir],
     3472    AC_HELP_STRING([--with-m4_tolower($1)-incdir],
     3473                   [directory with header files for using project $1]),
     3474    [m4_tolower(coin_has_$1)=installed],
     3475    [])
     3476
     3477  AC_ARG_WITH([m4_tolower($1)-datadir],
     3478    AC_HELP_STRING([--with-m4_tolower($1)-datadir],
     3479                   [directory with data files for using project $1]),
     3480    [m4_tolower(coin_has_$1)=installed],
     3481    [])
     3482fi
     3483
     3484if test $m4_tolower(coin_has_$1) = notGiven; then
     3485  #see if user gives directory where project might be installed: assemble search path for pkg-config
     3486  coin_save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
     3487  AC_ARG_WITH([coin-instdir],
     3488    AC_HELP_STRING([--with-coin-instdir],
     3489                   [prefix of installation directory for precompiled COIN packages]),
     3490    [if test -d "$withval"; then : ; else
     3491       AC_MSG_ERROR([argument for --with-coin-instdir not a directory])
     3492     fi
     3493     PKG_CONFIG_PATH="$withval/lib/$2/pkgconfig:$PKG_CONFIG_PATH"
     3494    ],[])
     3495
     3496  AC_ARG_WITH([m4_tolower($1)],
     3497    AC_HELP_STRING([--with-m4_tolower($1)],
     3498                   [prefix of installation directory for precompiled $1 package]),
     3499    [if test -d "$withval"; then : ; else
     3500       AC_MSG_ERROR([argument for --with-m4_tolower($1) not a directory])
     3501     fi
     3502     # maybe the user points directly to the directory with the .pc file
     3503     PKG_CONFIG_PATH="$withval:$PKG_CONFIG_PATH"
     3504     # maybe the user points to a project main directory
     3505     if test -d "$withval/lib/$2/pkgconfig"; then
     3506       PKG_CONFIG_PATH="$withval/lib/$2/pkgconfig:$PKG_CONFIG_PATH"
     3507     fi
     3508    ],[])
     3509
     3510  # let pkgconfig check if the project is already installed somewhere
     3511  # need to export variable to be sure that the following pkg-config call gets these values
     3512  export PKG_CONFIG_PATH
     3513  AC_COIN_PKG_CHECK_EXISTS([$1], [m4_tolower(coin_has_$1)="$m4_toupper($1)_VERSION"])
     3514
     3515  PKG_CONFIG_PATH="$coin_save_PKG_CONFIG_PATH"
     3516fi
     3517
     3518# if not found yet, check if project is available in present directory
     3519if test "$m4_tolower(coin_has_$1)" = notGiven; then
     3520  if test -d $srcdir/$2/$1; then
     3521    coin_pkg_is_here=no
     3522    m4_ifvaln([$3],
     3523      [for i in $srcdir/$2/$1/$3; do
     3524         if test -r $i; then
     3525           coin_pkg_is_here=yes
     3526         fi
     3527       done],
     3528      [ coin_pkg_is_here=yes ])
     3529    if test $coin_pkg_is_here = yes; then
     3530      m4_tolower(coin_has_$1)=$2/$1
     3531    fi
     3532  fi
     3533fi
     3534
     3535AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
     3536
     3537AC_MSG_CHECKING(whether project $1 need to be configured)
     3538if test "$m4_tolower(coin_has_$1)" != skipping &&
     3539   test "$m4_tolower(coin_has_$1)" != notGiven &&
     3540   test "$m4_tolower(coin_has_$1)" != installed; then
     3541
     3542  if test -r $srcdir/$2/$1/configure; then
     3543    coin_subdirs="$coin_subdirs m4_ifval($2,[$2/],)$1"
     3544    AC_MSG_RESULT(yes)
     3545    AC_CONFIG_SUBDIRS(m4_ifval($2,[$2/],)$1)
     3546  else
     3547    AC_MSG_RESULT(no)
     3548  fi
     3549else
     3550  AC_MSG_RESULT(no)
     3551fi
     3552])
     3553
     3554###########################################################################
     3555#                            COIN_HAS_PROJECT2                            #
     3556###########################################################################
     3557
     3558# This macro sets up usage of a Coin package.  It defines the
     3559# PKG_CFLAGS and PKG_LIBS variables, refering to the compiler and linker
     3560# flags to use when linking against this package.
     3561# It also defines a COIN_HAS_PKG preprocessor macro and makefile conditional.
     3562# The argument should be the name (Pkg) of the project (in correct lower
     3563# and upper case), optionally a directory where to look at it, and
     3564# optionally a file that need to be present in the package directory.
     3565#
     3566# It is also possible to specify a preinstalled version of this Coin
     3567# package or to specify only the linker and compiler flags.
     3568
     3569AC_DEFUN([AC_COIN_HAS_PROJECT2],
     3570[AC_MSG_CHECKING([for COIN project $1])
     3571# First check, if the sub-project is actually available
     3572
     3573m4_tolower(coin_has_$1)=notGiven
     3574
     3575# check if user wants to skip project in any case
     3576if test x"$COIN_SKIP_PROJECTS" != x; then
     3577  for dir in $COIN_SKIP_PROJECTS; do
     3578    if test $dir = "$1"; then
     3579      m4_tolower(coin_has_$1)=skipping
     3580    fi
     3581    if test $dir = "$2/$1"; then
     3582      m4_tolower(coin_has_$1)=skipping
     3583    fi
     3584  done
     3585fi
     3586
     3587m4_toupper($1_LIBS)=
     3588m4_toupper($1_CFLAGS)=
     3589m4_toupper($1_DATA)=
     3590AC_SUBST(m4_toupper($1_LIBS))
     3591AC_SUBST(m4_toupper($1_CFLAGS))
     3592AC_SUBST(m4_toupper($1_DATA))
     3593
     3594if test $m4_tolower(coin_has_$1) != skipping; then
     3595  if test $PACKAGE_TARNAME = m4_tolower($1); then
     3596    m4_tolower(coin_has_$1)=.
     3597  fi
     3598
     3599  AC_ARG_WITH([m4_tolower($1)-lib],
     3600    AC_HELP_STRING([--with-m4_tolower($1)-lib],
     3601                   [linker flags for using project $1]),
     3602      [m4_tolower(coin_has_$1)=yes
     3603       m4_toupper($1_LIBS)="$withval"],
     3604      [])
     3605
     3606  AC_ARG_WITH([m4_tolower($1)-incdir],
     3607    AC_HELP_STRING([--with-m4_tolower($1)-incdir],
     3608                   [directory with header files for using project $1]),
     3609    [m4_tolower(coin_has_$1)=yes
     3610     m4_toupper($1_CFLAGS)="-I$withval"],
     3611    [])
     3612
     3613  AC_ARG_WITH([m4_tolower($1)-datadir],
     3614    AC_HELP_STRING([--with-m4_tolower($1)-datadir],
     3615                   [directory with data files for using project $1]),
     3616    [m4_tolower(coin_has_$1)=yes
     3617     m4_toupper($1_DATA)="$withval"],
     3618    [])
     3619fi
     3620
     3621if test $m4_tolower(coin_has_$1) = notGiven; then
     3622  #assemble search path for pkg-config
     3623  coin_save_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
     3624
     3625  AC_ARG_WITH([coin-instdir],
     3626    AC_HELP_STRING([--with-coin-instdir],
     3627                   [prefix of installation directory for precompiled COIN packages]),
     3628    [if test -d "$withval"; then : ; else
     3629       AC_MSG_ERROR([argument for --with-coin-instdir not a directory])
     3630     fi
     3631     PKG_CONFIG_PATH="$withval/lib/$2/pkgconfig:$PKG_CONFIG_PATH",
     3632    ],[])
     3633
     3634  AC_ARG_WITH([m4_tolower($1)],
     3635    AC_HELP_STRING([--with-m4_tolower($1)],
     3636                   [prefix of installation directory for precompiled $1 package]),
     3637    [if test -d "$withval"; then : ; else
     3638       AC_MSG_ERROR([argument for --with-m4_tolower($1) not a directory])
     3639     fi
     3640     #if the user points directly to the directory with the .pc file
     3641     PKG_CONFIG_PATH="$withval:$PKG_CONFIG_PATH"
     3642     #if the user points to a project main directory
     3643     if test -d "$withval/lib/$2/pkgconfig"; then
     3644       PKG_CONFIG_PATH="$withval/lib/$2/pkgconfig:$PKG_CONFIG_PATH"
     3645     fi
     3646    ],[])
     3647
     3648  # check if uninstalled project can be found in ../$2/$1
     3649  # this is for the classic setup when this macro is called from the project main directory
     3650  if test -d $srcdir/../$2/$1; then
     3651    coin_pkg_is_here=no
     3652    m4_ifvaln([$3],
     3653      [for i in $srcdir/../$2/$1/$3; do
     3654         if test -r $i; then
     3655           coin_pkg_is_here=yes
     3656         fi
     3657       done],
     3658      [ coin_pkg_is_here=yes ])
     3659    if test $coin_pkg_is_here = yes; then
     3660      PKG_CONFIG_PATH="../$2/$1:$PKG_CONFIG_PATH"
     3661    fi
     3662  fi
     3663
     3664  # let pkg-config do it's magic
     3665  # need to export variable to be sure that the following pkg-config gets these values
     3666  export PKG_CONFIG_PATH
     3667  AC_COIN_PKG_CHECK_MODULE([$1],
     3668    [ m4_tolower(coin_has_$1)=$m4_toupper($1)_VERSION
     3669      AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
     3670    ],
     3671    [ m4_tolower(coin_has_$1)=notGiven
     3672      AC_MSG_RESULT([not given: $m4_toupper($1)_PKG_ERRORS])
     3673    ])
     3674
     3675  PKG_CONFIG_PATH="$coin_save_PKG_CONFIG_PATH"
     3676
     3677else
     3678  AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
     3679fi
     3680
     3681if test $m4_tolower(coin_has_$1) != skipping &&
     3682   test $m4_tolower(coin_has_$1) != notGiven ; then
     3683  if test "x$m4_toupper($1)_CFLAGS" != x ; then
     3684    AC_MSG_NOTICE([$1 CFLAGS are $m4_toupper($1)_CFLAGS])
     3685  fi
     3686  if test "x$m4_toupper($1)_LIBS" != x ; then
     3687    AC_MSG_NOTICE([$1 LIBS   are $m4_toupper($1)_LIBS])
     3688    ADDLIBS="$m4_toupper($1)_LIBS $ADDLIBS"
     3689  fi
     3690  if test "x$m4_toupper($1)_DATA" != x ; then
     3691    AC_MSG_NOTICE([$1 DATA   is  $m4_toupper($1)_DATA])
     3692  fi
     3693  AC_DEFINE(m4_toupper(COIN_HAS_$1),[1],[Define to 1 if the $1 package is used])
     3694fi
     3695
     3696# Define the Makefile conditional
     3697AM_CONDITIONAL(m4_toupper(COIN_HAS_$1),
     3698               [test $m4_tolower(coin_has_$1) != notGiven &&
     3699                test $m4_tolower(coin_has_$1) != skipping])
     3700
     3701]) # AC_COIN_HAS_PROJECT2
Note: See TracChangeset for help on using the changeset viewer.