ax_cuda.m4 3.44 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# -*- mode: autoconf -*-
#
# AX_OPENCL
#
# Check for an OpenCL implementation. If CL is found, _OPENCL is defined and
# the required compiler and linker flags are included in the output variables
# "CL_CFLAGS" and "CL_LIBS", respectively. If no usable CL implementation is
# found, "no_cl" is set to "yes".
#
# If the header "CL/OpenCL.h" is found, "HAVE_CL_OPENCL_H" is defined. If the
# header "OpenCL/OpenCL.h" is found, HAVE_OPENCL_OPENCL_H is defined. These
# preprocessor definitions may not be mutually exclusive.
#
# Based on AX_CHECK_GL, version: 2.4 author: Braden McDaniel
# <braden@endoframe.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# As a special exception, the you may copy, distribute and modify the
# configure scripts that are the output of Autoconf when processing
# the Macro. You need not follow the terms of the GNU General Public
# License when using or distributing such scripts.
#
AC_DEFUN([AX_CUDA],
[AC_REQUIRE([AC_CANONICAL_HOST])dnl

# Search nvcc compiler
AC_CHECK_PROG([NVCC_EXIST],[nvcc],["yes"],["no"])
AS_IF([test "x$NVCC_EXIST" = "xno"],[],[
          NVCC=`which nvcc`
incardon's avatar
incardon committed
44

incardon's avatar
incardon committed
45 46
          # Set CUDA_CFLAGS to $NVCC, where substring "bin/nvcc"
          # is substituted by "include".
incardon's avatar
incardon committed
47 48
          CUDA_CFLAGS=" ${NVCC%bin//nvcc}"
          CUDA_CFLAGS=" ${CUDA_CFLAGS%bin/nvcc}"
incardon's avatar
incardon committed
49 50 51 52
          CUDA_CFLAGS=" -I${CUDA_CFLAGS}include"

          #Set CUDA_CFLAGS to $NVCC, where substring "bin/nvcc"
          #is substituted by "lib".
incardon's avatar
incardon committed
53 54 55
          CUDA_LIBS="${NVCC%bin//nvcc}"
          CUDA_LIBS="${CUDA_LIBS%bin/nvcc}"
          CUDA_PATH=$CUDA_LIBS
incardon's avatar
incardon committed
56 57 58 59
          CUDA_LIBS=" -L${CUDA_LIBS}lib"

          # If $build_cpu contains "_64", append "64" to CUDA_LIBS
          AS_IF([echo $build_cpu | grep -q "_64"],
incardon's avatar
incardon committed
60 61 62 63 64 65 66 67 68 69 70 71 72
                [
                 AS_IF([ test -d $CUDA_PATH/lib64 ], [ CUDA_LIBS+="64" ], [])
                 # Be carefull the return code 0 mean true return code 1 mean false
                 AS_IF([ command -v bumblebeed >/dev/null ], [ CUDA_LIBS+=" -L/usr/lib64/nvidia-bumblebee/ "  ],
                                                             [
                                                               echo "bumblebee, NVIDIA optimus,  not found"
                                                             ])
                 AS_IF([ test -d /usr/local/cuda/lib64  ], [ CUDA_LIBS+=" -L/usr/local/cuda/lib64 "  ],
                       [
                        AS_IF([ test -d /usr/local/cuda/lib ],[ CUDA_LIBS+=" -L/usr/local/cuda/lib  "  ])
                       ])
                ])

incardon's avatar
incardon committed
73 74
          # Append " -lcuda -lcudart" to CUDA_LIBS
          CUDA_LIBS+=" -lcuda -lcudart"
incardon's avatar
incardon committed
75
          
incardon's avatar
incardon committed
76
          # Make variables available in Makefile.am
incardon's avatar
incardon committed
77 78
          AC_SUBST([CUDA_CFLAGS])
          AC_SUBST([CUDA_LIBS])
incardon's avatar
incardon committed
79
          echo $NVCC
incardon's avatar
incardon committed
80
          AC_SUBST([NVCC])
incardon's avatar
incardon committed
81 82 83 84
          AC_DEFINE([NVCC],[],[NVCC compiling])
])dnl

])dnl