1# SYNOPSIS
2#
3#   Test for VEXCL
4#
5#   AX_PATH_VEXCL( <Minimum Required Version>, <package-required=yes/no> )
6#
7# DESCRIPTION
8#
9#   Provides a --with-vexcl=DIR option. Searches --with-vexcl,
10#   $VEXCL_DIR, and the usual places for VEXCL headers and libraries.
11#
12#   On success, sets VEXCL_CPPFLAGS, VEXCL_LIBS, and #defines HAVE_VEXCL.
13#   Also defines automake conditional VEXCL_ENABLED.  Assumes package
14#   is optional unless overridden with $2=yes.
15#
16# LAST MODIFICATION
17#
18#   $Id: vexcl.m4 -1   $
19#
20# COPYLEFT
21#
22#   Copyright (c) 2013-2018 Roy H. Stogner <roystgnr@ices.utexas.edu>
23#   Copyright (c) 2012 Paul T. Bauman <pbauman@ices.utexas.edu>
24#   Copyright (c) 2010 Karl W. Schulz <karl@ices.utexas.edu>
25#   Copyright (c) 2009 Rhys Ulerich <rhys.ulerich@gmail.com>
26#   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
27#   Copyright (c) 2008 Caolan McNamara <caolan@skynet.ie>
28#   Copyright (c) 2008 Alexandre Duret-Lutz <adl@gnu.org>
29#   Copyright (c) 2008 Matthew Mueller <donut@azstarnet.com>
30#
31#   Copying and distribution of this file, with or without modification, are
32#   permitted in any medium without royalty provided the copyright notice
33#   and this notice are preserved.
34
35AC_DEFUN([AX_PATH_VEXCL],
36[
37
38AC_ARG_VAR(VEXCL_DIR,[root directory of VEXCL installation])
39
40AC_ARG_WITH(vexcl,
41  [AS_HELP_STRING([--with-vexcl[=DIR]],[root directory of VEXCL installation (default = VEXCL_DIR)])],
42  [with_vexcl=$withval
43if test "${with_vexcl}" != yes; then
44    VEXCL_PREFIX=$withval
45elif test "x${VEXCL_DIR}" != "x"; then
46   VEXCL_PREFIX=${VEXCL_DIR}
47else
48    VEXCL_PREFIX=/usr
49fi
50],[
51with_vexcl=$withval
52if test "x${VEXCL_DIR}" != "x"; then
53   VEXCL_PREFIX=${VEXCL_DIR}
54fi
55])
56
57# package requirement; if not specified, the default is to assume that
58# the package is optional
59
60is_package_required=ifelse([$2], ,no, $2 )
61
62HAVE_VEXCL=0
63
64VEXCL_INCLUDE="$VEXCL_PREFIX"
65
66if test "${with_vexcl}" != no ; then
67
68    # If we can see the vexcl headers, then we know where to get them
69    # and we'll need C++11 to compile them
70    if test -e "${VEXCL_PREFIX}/vexcl/vexcl.hpp" ; then
71       VEXCL_CPPFLAGS="-I${VEXCL_PREFIX}"
72       AS_IF([test x$HAVE_CXX11 = x1], [],
73             [AX_CXX_COMPILE_STDCXX(11,noext)])
74    elif test -e "${VEXCL_PREFIX}/include/vexcl/vexcl.hpp" ; then
75       VEXCL_INCLUDE="${VEXCL_PREFIX}/include"
76       VEXCL_CPPFLAGS="-I${VEXCL_PREFIX}/include"
77       AS_IF([test x$HAVE_CXX11 = x1], [],
78             [AX_CXX_COMPILE_STDCXX(11,noext)])
79    else
80       AC_MSG_NOTICE([${VEXCL_PREFIX}/vexcl/vexcl.hpp not found])
81       AC_MSG_NOTICE([${VEXCL_PREFIX}/include/vexcl/vexcl.hpp not found])
82    fi
83
84    # Make sure we have OpenCL support
85    AX_CHECK_CL([C++])
86
87    found_boost=yes
88    BOOST_REQUIRE([1.47],[found_boost=no]) # Chrono introduced in 1.47
89
90    BOOST_CHRONO
91    if test "x$boost_cv_lib_chrono" != xyes; then
92      found_boost=no
93    fi
94
95    BOOST_DATE_TIME
96    if test "x$boost_cv_lib_date_time" != xyes; then
97      found_boost=no
98    fi
99
100    BOOST_FILESYSTEM
101    if test "x$boost_cv_lib_filesystem" != xyes; then
102      found_boost=no
103    fi
104
105    BOOST_SYSTEM
106    if test "x$boost_cv_lib_system" != xyes; then
107      found_boost=no
108    fi
109
110    BOOST_THREADS
111    if test "x$boost_cv_lib_threads" != xyes; then
112      found_boost=no
113    fi
114
115    # Make sure we have OpenCL support
116    AX_CHECK_CL([C++])
117
118    AC_LANG_PUSH([C++])
119    ac_VEXCL_save_CPPFLAGS="$CPPFLAGS"
120    CPPFLAGS="$CXXFLAGS $CPPFLAGS $VEXCL_CPPFLAGS $BOOST_CPPFLAGS $CL_CFLAGS $CL_CPPFLAGS"
121    AC_CHECK_HEADER([vexcl/vexcl.hpp],[found_header=yes],[found_header=no])
122    CPPFLAGS="$ac_VEXCL_save_CPPFLAGS"
123    AC_LANG_POP([C++])
124
125    #-----------------------
126    # Minimum version check skipped - there's no versioning
127    # information in vexcl headers as of 0.7.0
128    #----------------------
129
130    succeeded=yes
131    if test x$found_header = xyes -a x"$no_cl" != xyes; then
132      VEXCL_CPPFLAGS="$VEXCL_CPPFLAGS $BOOST_CPPFLAGS $CL_CFLAGS $CL_CPPFLAGS"
133      VEXCL_LDFLAGS="$BOOST_CHRONO_LDFLAGS $BOOST_DATE_TIME_LDFLAGS $BOOST_FILESYSTEM_LDFLAGS $BOOST_SYSTEM_LDFLAGS $CL_LDFLAGS"
134      VEXCL_LIBS="$BOOST_CHRONO_LIBS $BOOST_DATE_TIME_LIBS $BOOST_FILESYSTEM_LIBS $BOOST_SYSTEM_LIBS $CL_LIBS"
135
136      HAVE_VEXCL=1
137      AC_DEFINE(HAVE_VEXCL,1,[Define if VEXCL is available])
138      AC_SUBST(VEXCL_CPPFLAGS)
139      AC_SUBST(VEXCL_LDFLAGS)
140      AC_SUBST(VEXCL_LIBS)
141      AC_SUBST(VEXCL_PREFIX)
142      AC_SUBST(VEXCL_INCLUDE)
143    else
144      succeeded=no
145
146      if test "$is_package_required" = yes; then
147        AC_MSG_ERROR([VEXCL not found.  Try either --with-vexcl or setting VEXCL_DIR.])
148      else
149        AC_MSG_NOTICE([optional VEXCL library not found])
150        VEXCL_CPPFLAGS="" # VEXCL_CPPFLAGS empty on failure
151        VEXCL_LDFLAGS="" # VEXCL_LDFLAGS empty on failure
152        VEXCL_LIBS="" # VEXCL_LIBS empty on failure
153      fi
154    fi
155
156    AC_SUBST(HAVE_VEXCL)
157
158fi
159
160AM_CONDITIONAL(VEXCL_ENABLED,test x$HAVE_VEXCL = x1)
161
162])
163