hepmc.m4 6.21 KB
Newer Older
Vincent's avatar
v2.0.0  
Vincent committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
dnl hepmc.m4 -- checks for HepMC library
dnl

### Determine paths to HEPMC components
### If successful, set the conditional HEPMC_AVAILABLE
### Also: HEPMC_VERSION HEPMC_INCLUDES LDFLAGS_HEPMC
AC_DEFUN([WO_PROG_HEPMC],
[dnl
AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([AC_PROG_FC])

AC_ARG_ENABLE([hepmc],
  [AS_HELP_STRING([--enable-hepmc],
    [enable HepMC for handling event data [[yes]]])],
  [], [enable_hepmc="yes"])

Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
17
18
hepmc_is_v3="no"
hepmcok="no"
Vincent's avatar
v2.0.0  
Vincent committed
19
20

if test "$enable_hepmc" = "yes"; then
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
21
22
   ACX_CHECK_HEPMC3()
   if test "${hepmcok}" = "no"; then
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
23
     AC_MSG_NOTICE([HepMC3 not found, incompatible, or HepMC3-config not found])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
     AC_MSG_NOTICE([looking for HepMC2 instead ... ])
     if test -n "$HEPMC_DIR"; then
       wo_hepmc_includes="-I$HEPMC_DIR/include"
     fi
     AC_MSG_CHECKING([the HepMC version])
     AC_LANG([C++])
     wo_cxxflags_tmp=$CXXFLAGS
     CXXFLAGS="$CXXFLAGS $wo_hepmc_includes"
     AC_LINK_IFELSE([dnl
       AC_LANG_PROGRAM([[#include "HepMC/Version.h"]],
         [[std::cout << HepMC::versionName();]])],
       [dnl
       wk_hepmc_version=`./conftest`
       AC_MSG_RESULT([$wk_hepmc_version])],
       [dnl
       AC_MSG_RESULT([unknown])
       enable_hepmc="no"])
     CXXFLAGS=$wo_cxxflags_tmp
     
     HEPMC_VERSION=$wk_hepmc_version
     AC_SUBST([HEPMC_VERSION])
45
46
47
48
49
50

     if test -n "$HEPMC_DIR"; then
       wo_hepmc_ldflags="-Wl,-rpath,$HEPMC_DIR/lib -L$HEPMC_DIR/lib -lHepMC"
     else
       wo_hepmc_ldflags="-lHepMC"
     fi
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
     if test "$enable_hepmc" = "yes"; then
       wo_require_stdcpp="yes"
       AC_MSG_CHECKING([for GenEvent class in -lHepMC])
       wo_libs_tmp=$LIBS
       LIBS="$wo_hepmc_ldflags $wo_libs_tmp"
       AC_LANG([C++])
       wo_cxxflags_tmp=$CXXFLAGS
       CXXFLAGS="$CXXFLAGS $wo_hepmc_includes"
       AC_LINK_IFELSE([dnl
         AC_LANG_PROGRAM([[#include "HepMC/GenEvent.h"]],
           [[using namespace HepMC;  GenEvent* evt = new GenEvent();]])],
         [],
         [enable_hepmc="no"])
       AC_MSG_RESULT([$enable_hepmc])
       CXXFLAGS=$wo_cxxflags_tmp
       LIBS=$wo_libs_tmp
     else
       AC_MSG_CHECKING([for HepMC])
       AC_MSG_RESULT([(disabled)])
     fi
     
     if test "$enable_hepmc" = "yes"; then
       HEPMC_INCLUDES=$wo_hepmc_includes
       LDFLAGS_HEPMC=$wo_hepmc_ldflags
     fi
76
     AM_CONDITIONAL([HEPMC3_HAS_ROOT],false)
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
77
78
   else
      hepmc_is_v3="yes"
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
79
      AC_MSG_CHECKING([the HepMC3 version])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
80
81
      save_CXXFLAGS="$CXXFLAGS"
      save_LIBS="$LIBS"
82
      CXXFLAGS="${CXXFLAGS} `${hepmcconfig} --cxxflags`"
83
      LIBS="${LIBS} -Wl,-rpath,`${hepmcconfig} --libdir` `${hepmcconfig} --libs`"
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
84
85
86
87
88
      AC_LANG([C++])
      AC_LINK_IFELSE([dnl
        AC_LANG_PROGRAM([[
#include <stdio.h>
#include <iostream>
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
89
#include "HepMC3/Version.h"
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
90
]],
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
91
          [[using namespace HepMC3; std::cout << HepMC3::version();]])],
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
92
93
94
95
96
97
98
99
100
101
102
        [dnl
        wk_hepmc_version=`./conftest`
        AC_MSG_RESULT([$wk_hepmc_version])],
        [dnl
        AC_MSG_RESULT([unknown])
        enable_hepmc="no"])  
      CXXFLAGS="$save_CXXFLAGS"
      LIBS="$save_LIBS"  
      HEPMC_VERSION=$wk_hepmc_version
      AC_SUBST([HEPMC_VERSION])   
   fi
Vincent's avatar
v2.0.0  
Vincent committed
103
104
fi

Vincent Rothe's avatar
v2.4.0    
Vincent Rothe committed
105
106
HEPMC_AVAILABLE_FLAG=$enable_hepmc

Vincent's avatar
v2.0.0  
Vincent committed
107
108
AC_SUBST([HEPMC_INCLUDES])
AC_SUBST([LDFLAGS_HEPMC])
Vincent Rothe's avatar
v2.4.0    
Vincent Rothe committed
109
AC_SUBST([HEPMC_AVAILABLE_FLAG])
Vincent's avatar
v2.0.0  
Vincent committed
110
111

AM_CONDITIONAL([HEPMC_AVAILABLE], [test "$enable_hepmc" = "yes"])
112
113
114
115
116
117
118
119
120
121
122
123
AM_CONDITIONAL([HEPMC2_AVAILABLE], [test "$enable_hepmc" = "yes" -a "$hepmc_is_v3" = "no"])
AM_CONDITIONAL([HEPMC3_AVAILABLE], [test "$enable_hepmc" = "yes" -a "$hepmc_is_v3" = "yes"])
if test "$enable_hepmc" = "yes" -a "$hepmc_is_v3" = "yes"; then
   HEPMC3_AVAILABLE_FLAG=".true."
else
   HEPMC3_AVAILABLE_FLAG=".false."
fi
if test "$enable_hepmc" = "yes" -a "$hepmc_is_v3" = "no"; then
   HEPMC2_AVAILABLE_FLAG=".true."
else
   HEPMC2_AVAILABLE_FLAG=".false."
fi
124
125
126
if test "$enable_hepmc" = "no"; then
   AM_CONDITIONAL([HEPMC3_HAS_ROOT],false)
fi
127
128
AC_SUBST([HEPMC2_AVAILABLE_FLAG])
AC_SUBST([HEPMC3_AVAILABLE_FLAG])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
129
AM_CONDITIONAL([HEPMC_IS_VERSION3], [test "$enable_hepmc" = "yes" -a "$hepmc_is_v3" = "yes"])
Vincent's avatar
v2.0.0  
Vincent committed
130
])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

dnl #####################################################################
dnl CHECK HEPMC3 BEGIN
dnl
dnl This script can be used in configure scripts to check for the
dnl usability of the HepMC3 library.
dnl
dnl By defaults, it searches the HepMC3 library in standard system
dnl locations but an alternative path can be specified using the
dnl --with-hepmc=... configure option
dnl
dnl If HepMC3 is found and functional, the variables HEPMC_CXXFLAGS
dnl and HEPMC_LIBS are set
AC_DEFUN([ACX_CHECK_HEPMC3],
[
dnl ckeck if a directory is specified for HepMC
AC_ARG_WITH(HepMC,
148
            [AS_HELP_STRING([--with-hepmc=dir],
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
149
150
                            [assume the given directory for HepMC])])

Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
151
dnl search for the Hepmc3-config script
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
152
if test "$with_hepmc" = ""; then
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
153
   AC_PATH_PROG(hepmcconfig, HepMC3-config, no)
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
154
else
Vincent Rothe's avatar
v2.7.1    
Vincent Rothe committed
155
   AC_PATH_PROG(hepmcconfig, HepMC3-config, no, ${with_hepmc}/bin)
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
156
157
158
fi

if test "${hepmcconfig}" = "no"; then
159
   AC_MSG_CHECKING([for HepMC3 or newer])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
160
161
162
163
164
165
166
167
   AC_MSG_RESULT(no);
   $2
else

   dnl now see if HepMC is functional
   save_CXXFLAGS="$CXXFLAGS"
   save_LIBS="$LIBS"

168
   CXXFLAGS="${CXXFLAGS} `${hepmcconfig} --cxxflags`"
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
169
170
   LIBS="${LIBS} `${hepmcconfig} --libs`"

171
172
173
174
   AC_MSG_CHECKING([if HepMC3 is built with ROOT interface])
   if ${hepmcconfig} --rootIO | grep rootIO >/dev/null 2>&1; then
      hepmc3_root="yes"
      HEPMCROOTLIBS="`${hepmcconfig} --rootIO` -Wl,-rpath,$ROOTLIBDIR -L$ROOTLIBDIR $ROOTLIBS"
175
      HEPMCROOTINCL="-I$ROOTINCDIR"
176
177
178
179
180
181
182
   else
      hepmc3_root="no"
   fi
   AC_MSG_RESULT([$hepmc3_root])
   AM_CONDITIONAL([HEPMC3_HAS_ROOT], [test "$hepmc3_root" = "yes"])

   AC_MSG_CHECKING([if HepMC3 is functional])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
183
184
   AC_LANG_PUSH(C++)
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
185
#include <HepMC3/GenEvent.h>
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
186
   ]], [[
187
using namespace HepMC3; GenEvent evt(Units::GEV,Units::MM);
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
188
189
190
191
192
193
   ]])], [hepmcok='yes'], [hepmcok='no'])
   AC_MSG_RESULT([$hepmcok])
   AC_LANG_POP()
   CXXFLAGS="$save_CXXFLAGS"
   LIBS="$save_LIBS"

194
   AC_MSG_CHECKING([for HepMC3])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
195
   if test "${hepmcok}" = "yes"; then
196
      HEPMC_INCLUDES="`${hepmcconfig} --cxxflags` $HEPMCROOTINCL"
197
      LDFLAGS_HEPMC="-Wl,-rpath,`${hepmcconfig} --libdir` `${hepmcconfig} --libs` $HEPMCROOTLIBS"
198
      AC_MSG_RESULT([yes])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
199
200
      $1
   else
201
      AC_MSG_RESULT([no])
Vincent Rothe's avatar
v2.6.0    
Vincent Rothe committed
202
203
204
205
206
207
      $2
   fi
fi
])

dnl CHECK HEPMC3 END