Changeset 309 for trunk


Ignore:
Timestamp:
Apr 16, 2007 5:03:00 PM (13 years ago)
Author:
lou
Message:

Enhance COIN_HAS_USER_LIBRARY to take a list of function names and declare
victory if any one can be linked successfully.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/coin.m4

    r291 r309  
    22832283                test $m4_tolower(coin_has_$1) != skipping])
    22842284AC_MSG_RESULT([$m4_tolower(coin_has_$1)])
    2285 ]) # AC_COIN_HAS
     2285]) # AC_COIN_HAS_PROJECT
    22862286
    22872287###########################################################################
    22882288#                        COIN_HAS_USER_LIBRARY                            #
    22892289###########################################################################
    2290 
    2291 # This macro sets up usage of a library with header files.  It defines
    2292 # the LBRYINCDIR variable, and it defines COIN_HAS_LBRY preprocessor
    2293 # macro and makefile conditional.  The first argument should be the
    2294 # full name (LibraryName) of the library, and the second argument (in
    2295 # upper case letters) the abbreviation (LBRY).  This macro also
    2296 # introduces the configure arguments --with-libraryname-incdir and
    2297 # --with-libraryname-lib which have to be both given by a user to use
    2298 # this solver to tell the configure script where the include files and
    2299 # the library are located.  Those arguments can also be given as
    2300 # environement variables LBRYINCDIR and LBRYLIB, but a --with-*
    2301 # argument overwrites an environment variable.  If a third argument is
    2302 # given, it is assumed that this is the name of a header file that can
    2303 # be checked for in the given include directory, and if a fourth
    2304 # argument is given, it is assumed to be the name of a C function
    2305 # which is given and defined in the library, and a test is done to
    2306 # check if that symbol is defined in the library.
    2307 # If it possible to disable the check, by specifying
    2308 # --disable-libraryname-libcheck - this is a workaround for platforms
    2309 # where checks don't work (yet) properly.
     2290# This macro sets up usage of a user library with header files. The assumption
     2291# is that the header file(s) and library do not reside in standard system
     2292# directories, hence both the include directory and link flags must be
     2293# specified. There are two mandatory arguments and two optional arguments.
     2294#
     2295# The first argument (mandatory) should be a name (LibraryName) for the
     2296# library.  The second argument (mandatory) should be an abbreviation in
     2297# upper case letters (LBRY) for the library. Ultimately, the macro will
     2298# specify two variables, LBRYINCDIR and LBRYLIB, to be substituted in files
     2299# generated during configuration; a preprocessor symbol COIN_HAS_LBRY; and a
     2300# matching automake conditional COIN_HAS_LBRY. LBRYINCDIR should specify the
     2301# directory containing include files for the library. LBRYLIB should specify
     2302# the flags necessary to link to the library.
     2303#
     2304# The macro defines three configure arguments, --with-libraryname-incdir,
     2305# --with-libraryname-lib, and --disable-libraryname-libcheck, by converting
     2306# LibraryName to lower case.
     2307#
     2308# LBRYINCDIR and LBRYLIB can be specified as environment variables or as
     2309# part of the configure command using --with-libraryname-incdir and
     2310# --with-libraryname-lib, respectively. Command line arguments override
     2311# environment variables.
     2312#
     2313# If a third argument is given, it should specify a file in LBRYINCDIR.  The
     2314# macro will check for the presence of the file. If a fourth argument is given,
     2315# it should specify a function name, `fname'.  The macro will attempt to link a
     2316# trivial program containing a parameterless call to the function, `fname()',
     2317# using the LBRYLIB flags. The link check uses C as the language; this has been
     2318# adequate to date but has limitations. It is possible to disable the link
     2319# check by specifying --disable-libraryname-libcheck. This is a workaround for
     2320# instances where the link check does not work properly, for whatever reason.
     2321# If you're trying to link to a Fortran library, consider using F77_FUNC or
     2322# FC_FUNC to obtain a mangled fname appropriate for use from C code. For a C++
     2323# library, you're on your own unless the library declares some function with
     2324# extern "C" linkage. Otherwise, you'll have to somehow find the mangled C++
     2325# name.
    23102326
    23112327AC_DEFUN([AC_COIN_HAS_USER_LIBRARY],
    2312 [AC_REQUIRE([AC_COIN_PROJECTDIR_INIT])
    2313 AC_MSG_CHECKING(if user provides library for $1)
     2328[ AC_REQUIRE([AC_COIN_PROJECTDIR_INIT])
     2329  AC_MSG_CHECKING(if user provides library for $1)
    23142330
    23152331# Check for header file directory
    2316 AC_ARG_WITH(m4_tolower($1)-incdir,
    2317             AC_HELP_STRING([--with-m4_tolower($1)-incdir],
    2318                            [specify the directory with the header files for library $1]),
    2319                            [$2INCDIR=`cd $withval; pwd`])
     2332
     2333  AC_ARG_WITH(m4_tolower($1)-incdir,
     2334      AS_HELP_STRING([--with-m4_tolower($1)-incdir],
     2335                     [specify the header file directory for library $1]),
     2336      [$2INCDIR=`cd $withval; pwd`])
     2337
    23202338# Check for library directory
    2321 AC_ARG_WITH(m4_tolower($1)-lib,
    2322             AC_HELP_STRING([--with-m4_tolower($1)-lib],
    2323                            [specify the flags to link with the library $1]),
    2324                            [$2LIB=$withval])
     2339
     2340  AC_ARG_WITH(m4_tolower($1)-lib,
     2341      AS_HELP_STRING([--with-m4_tolower($1)-lib],
     2342                     [specify the flags used to link with the library $1]),
     2343      [$2LIB=$withval])
     2344
    23252345# Switch to disable library check if requested
    2326 AC_ARG_ENABLE(m4_tolower($1)-libcheck,
    2327               AC_HELP_STRING([--enable-m4_tolower($1)-libcheck],
    2328                              [use disable-m4_tolower($1)-libcheck to skip the link check at configuration time]),
    2329               [m4_tolower($1)_libcheck=$enableval],
    2330               [m4_tolower($1)_libcheck=yes])
    2331 
    2332 if test x"$$2INCDIR" != x || test x"$$2LIB" != x; then
    2333   m4_tolower(coin_has_$2)=true
    2334 else
    2335   m4_tolower(coin_has_$2)=false
    2336 fi
    2337 
    2338 if test $m4_tolower(coin_has_$2) = true; then
    2339 # Check either both arguments or none are given
    2340   if test x"$$2INCDIR" = x || test x"$$2LIB" = x; then
    2341     AC_MSG_ERROR([You need to specify both --with-m4_tolower($1)-incdir and --with-m4_tolower($1)-lib if you want to use library $1])
    2342   fi
    2343   AC_MSG_RESULT(yes)
    2344   # Check if the given header file is there
    2345   m4_ifvaln([$3],[AC_CHECK_FILE([$$2INCDIR/$3],[],
    2346                  [AC_MSG_ERROR([Cannot find file $3 in $$2INCDIR])])])
    2347   # Check if the symbol is provided in the library
    2348   # ToDo: FOR NOW WE ASSUME THAT WE ARE USING THE C++ COMPILER
    2349   m4_ifvaln([$4],[if test x"$m4_tolower($1)_libcheck" != xno; then
    2350                     coin_save_LIBS="$LIBS"
    2351                     LIBS="$$2LIB $ADDLIBS"
    2352                     AC_MSG_CHECKING([whether symbol $4 is available with $2])
    2353                     AC_LANG_PUSH(C)
    2354 # ToDo find out what to do about extern "C"
    2355 #                    AC_TRY_LINK([extern "C" {void $4();}],[$4()],
    2356                     AC_TRY_LINK([void $4();],[$4()],
    2357                                 [AC_MSG_RESULT(yes)],
    2358                                 [AC_MSG_RESULT(no)
    2359                                  AC_MSG_ERROR([Cannot find symbol $4 with $2])])
    2360                     AC_LANG_POP(C)
    2361                     LIBS="$coin_save_LIBS"
    2362                   fi])
    2363   ADDLIBS="$$2LIB $ADDLIBS"
    2364   AC_DEFINE(COIN_HAS_$2,[1],[Define to 1 if the $1 package is used])
    2365 else
    2366   AC_MSG_RESULT(no)
    2367 fi
    2368 
    2369 AC_SUBST($2INCDIR)
    2370 AC_SUBST($2LIB)
    2371 AM_CONDITIONAL(COIN_HAS_$2,
    2372                test $m4_tolower(coin_has_$2) = true)
    2373 ]) #AC_COIN_HAS_SOLVER
     2346
     2347  AC_ARG_ENABLE(m4_tolower($1)-libcheck,
     2348      AS_HELP_STRING([--enable-m4_tolower($1)-libcheck],
     2349                     [use disable-m4_tolower($1)-libcheck to skip the link
     2350                      check at configuration time]),
     2351      [m4_tolower($1)_libcheck=$enableval],
     2352      [m4_tolower($1)_libcheck=yes])
     2353
     2354# At this point, if we're going to use the library, both LBRYINCDIR and
     2355# LBRYLIB must be defined and not empty.
     2356
     2357  if test x"$$2INCDIR" != x || test x"$$2LIB" != x; then
     2358    if test x"$$2INCDIR" = x || test x"$$2LIB" = x; then
     2359      AC_MSG_ERROR([You need to specify both an include directory and link flags to use library $1. Use --with-m4_tolower($1)-incdir of environment variable $$2INCDIR to specify the include directory. Use --with-m4_tolower($1)-lib or environment variable $$2LIB to specify link flags.])
     2360    fi
     2361    m4_tolower(coin_has_$2)=true
     2362    AC_MSG_RESULT(yes)
     2363  else
     2364    m4_tolower(coin_has_$2)=false
     2365    AC_MSG_RESULT(no)
     2366  fi
     2367
     2368# If we have instructions for use, consider header and link checks.
     2369
     2370  if test $m4_tolower(coin_has_$2) = true; then
     2371
     2372# If argument 3 (file) is given, check for the file. Typically this will be a
     2373# header file, but that's not assumed.
     2374
     2375    m4_ifval([$3],
     2376        [AC_CHECK_FILE([$$2INCDIR/$3],[],
     2377             [AC_MSG_ERROR([Cannot find file $3 in $$2INCDIR])])])
     2378
     2379# Now see if we can link the function. There are arguments for and against
     2380# assuming argument 3 is a header file declaring the function. A correct
     2381# function declaration is the main argument in favour. Having to cope with
     2382# possible dependencies or other oddities are the main arguments against.
     2383# Force the use of C as the best single choice amongst C++, C, and Fortran.
     2384# Obviously, this has limits.
     2385
     2386    m4_ifvaln([$4],
     2387        [if test x"$m4_tolower($1)_libcheck" != xno; then
     2388           coin_save_LIBS="$LIBS"
     2389           LIBS="$$2LIB $ADDLIBS"
     2390           coin_$2_link=no
     2391           AC_LANG_PUSH(C)
     2392           for fnm in $4 ; do
     2393             AC_MSG_CHECKING([whether symbol $fnm is available with $2])
     2394             AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[$fnm()]])],
     2395                 [AC_MSG_RESULT(yes)
     2396                  coin_$2_link=yes
     2397                  break],
     2398                 [AC_MSG_RESULT(no)])
     2399           done
     2400           AC_LANG_POP(C)
     2401           if test x"$coin_$2_link" = xyes ; then
     2402             LIBS="$coin_save_LIBS"
     2403           else
     2404             AC_MSG_ERROR([Cannot find symbol(s) $4 with $2])
     2405           fi
     2406         fi])
     2407
     2408# If we make it this far, we've verified the file and linked the function. Add
     2409# the necessary link flags to ADDLIBS and define the preprocessor symbol
     2410# COIN_HAS_LBRY.
     2411
     2412    ADDLIBS="$$2LIB $ADDLIBS"
     2413    AC_DEFINE(COIN_HAS_$2,[1],[Define to 1 if the $1 package is used])
     2414  fi
     2415
     2416# Arrange for configure to substitute LBRYINCDIR and LBRYLIB and create the
     2417# automake conditional. These actions must occur unconditionally.
     2418
     2419  AC_SUBST($2INCDIR)
     2420  AC_SUBST($2LIB)
     2421  AM_CONDITIONAL(COIN_HAS_$2, test $m4_tolower(coin_has_$2) = true)
     2422]) #AC_COIN_HAS_USER_LIBRARY
    23742423
    23752424###########################################################################
Note: See TracChangeset for help on using the changeset viewer.