Salome HOME
Copyright update 2021
[tools/configuration.git] / autotools / m4 / check_cppunit.m4
1 dnl Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 dnl
3 dnl Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 dnl
6 dnl This library is free software; you can redistribute it and/or
7 dnl modify it under the terms of the GNU Lesser General Public
8 dnl License as published by the Free Software Foundation; either
9 dnl version 2.1 of the License, or (at your option) any later version.
10 dnl
11 dnl This library is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 dnl Lesser General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU Lesser General Public
17 dnl License along with this library; if not, write to the Free Software
18 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 dnl
20 dnl See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 dnl
22
23 AC_DEFUN([CHECK_CPPUNIT],[
24
25 AC_CHECKING(for cppunit)
26
27 cppunit_ok=yes
28
29 dnl were is cppunit ?
30
31 AC_ARG_WITH(cppunit,
32     [AC_HELP_STRING([--with-cppunit=DIR],[directory path to CPPUNIT installation])],
33     [CPPUNITHOME="$withval"
34       AC_MSG_RESULT("select $withval as path to CPPUNIT")
35     ])
36
37 AC_ARG_WITH(cppunit_inc,
38     [AC_HELP_STRING([--with-cppunit_inc=DIR],[directory path to CPPUNIT includes])],
39     [CPPUNIT_INCLUDES="$withval"
40       AC_MSG_RESULT("select $withval as path to CPPUNIT includes")
41     ])
42
43 if test -z "$CPPUNITHOME"; then
44   AC_MSG_RESULT(CPPUNITHOME not defined)
45   exits_ok=no   
46   if test "x$exits_ok" = "xno"; then
47      for d in /usr/local /usr ; do
48         AC_CHECK_FILE(${d}/lib64/libcppunit.so,exits_ok=yes,exits_ok=no)
49         if test "x$exits_ok" = "xyes"; then
50            CPPUNITHOME=$d
51            AC_MSG_RESULT(libcppunit.so detected in $d/lib64)
52            break
53         fi
54         AC_CHECK_FILE(${d}/lib/libcppunit.so,exits_ok=yes,exits_ok=no)
55         if test "x$exits_ok" = "xyes"; then
56            CPPUNITHOME=$d
57            AC_MSG_RESULT(libcppunit.so detected in $d/lib)
58            break
59         fi
60      done
61   fi
62   if test "x$exits_ok" = "xno"; then
63      for d in `echo $LD_LIBRARY_PATH | sed -e "s/:/ /g"` ; do
64         if test -f $d/libcppunit.so ; then
65            AC_MSG_RESULT(libcppunit.so detected in $d)
66            CPPUNITHOME=$d
67            CPPUNITHOME=`echo ${CPPUNITHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"`
68            exits_ok=yes
69            break
70         fi
71      done
72   fi
73   if test "x$exits_ok" = "xyes"; then
74      if test -z "$CPPUNIT_INCLUDES"; then
75         CPPUNIT_INCLUDES=$CPPUNITHOME"/include"
76      fi
77   fi
78 else
79   if test -z "$CPPUNIT_INCLUDES"; then
80      CPPUNIT_INCLUDES="$CPPUNITHOME/include"
81   fi    
82 fi
83
84 if test "x$cppunit_ok" = xno -o ! -d "$CPPUNITHOME" ; then
85   AC_MSG_RESULT(no)
86   AC_MSG_WARN(cppunit not found)
87   cppunit_ok=no
88 else
89    AC_LANG_SAVE
90    AC_LANG_CPLUSPLUS
91    CPPFLAGS_old=$CPPFLAGS
92    CPPFLAGS="$CPPFLAGS -I$CPPUNIT_INCLUDES"
93    
94    AC_CHECK_HEADER(cppunit/extensions/HelperMacros.h,cppunit_ok=yes,cppunit_ok=no) 
95
96    CPPFLAGS=$CPPFLAGS_old
97
98    if test "x$cppunit_ok" = xno ; then
99      AC_MSG_RESULT(no)
100      AC_MSG_WARN(cppunit not found)
101    else
102      cppunit_ok=yes
103    fi
104
105   if  test "x$cppunit_ok" = "xno"
106   then
107     AC_MSG_RESULT(unable to found cppunit headers and library)
108     AC_MSG_RESULT(CPPUNITHOME environment variable may be wrong)
109   else
110     if test "x$CPPUNIT_INCLUDES" = "x/usr/include"
111     then
112       CPPUNIT_INCLUDES=""
113     else
114       CPPUNIT_INCLUDES="-I$CPPUNIT_INCLUDES"
115     fi
116     if test "x$CPPUNITHOME" = "x/usr"
117     then
118       CPPUNIT_LIBS=" -lcppunit"
119     else
120       CPPUNIT_LIBS="-L$CPPUNITHOME/lib -lcppunit"
121     fi
122
123     AC_SUBST(CPPUNIT_INCLUDES)
124     AC_SUBST(CPPUNIT_LIBS)
125     AC_SUBST(cppunit_ok)
126     AC_MSG_RESULT(yes)
127   fi
128 fi
129
130 AM_CONDITIONAL(CPPUNIT_IS_OK, [test x"$cppunit_ok" = xyes])
131
132 AC_LANG_RESTORE
133
134 ])dnl
135 dnl