[cig-commits] r22940 - cs/autoconf/trunk

elliott.sales.de.andrade at geodynamics.org elliott.sales.de.andrade at geodynamics.org
Tue Oct 8 00:11:42 PDT 2013


Author: elliott.sales.de.andrade
Date: 2013-10-08 00:11:41 -0700 (Tue, 08 Oct 2013)
New Revision: 22940

Modified:
   cs/autoconf/trunk/cit_cuda.m4
Log:
Fixup CUDA macros.

* Move AC_ARG_VAR calls here instead of duplicating them in every
  configure.ac file.
* Merge checks into one macro.
* Fix library check which only tested compilation and not linking.
* Correctly push and pop state.
* Move CPP require after the language change.

Modified: cs/autoconf/trunk/cit_cuda.m4
===================================================================
--- cs/autoconf/trunk/cit_cuda.m4	2013-10-08 07:11:36 UTC (rev 22939)
+++ cs/autoconf/trunk/cit_cuda.m4	2013-10-08 07:11:41 UTC (rev 22940)
@@ -1,53 +1,65 @@
 # -*- Autoconf -*-
 
 
-## --------------------------- ##
+## ------------------------- ##
 ## Autoconf macros for CUDA. ##
-## --------------------------- ##
+## ------------------------- ##
 
+
 # ----------------------------------------------------------------------
-# CIT_CUDA_INCDIR
+# CIT_CUDA_CONFIG
 # ----------------------------------------------------------------------
 # Determine the directory containing <cuda_runtime.h>
-AC_DEFUN([CIT_CUDA_INCDIR], [
+AC_DEFUN([CIT_CUDA_CONFIG], [
+  AC_ARG_VAR(CUDA_INC, [Location of CUDA include files])
+  AC_ARG_VAR(CUDA_LIB, [Location of CUDA library libcudart])
+
+  dnl Check for compiler
+  AC_PATH_PROG(NVCC, nvcc)
+  if test -z "$NVCC" ; then
+    AC_MSG_ERROR([cannot find 'nvcc' program.])
+  fi
+
+  AC_LANG_PUSH([C++])
   AC_REQUIRE_CPP
-  AC_LANG(C++)
+  CPPFLAGS_save="$CPPFLAGS"
+  LDFLAGS_save="$LDFLAGS"
+  LIBS_save="$LIBS"
+
+  dnl Check for CUDA headers
+  if test "x$CUDA_INC" != "x"; then
+    CUDA_CPPFLAGS="-I$CUDA_INC"
+    CPPFLAGS="$CUDA_CPPFLAGS $CPPFLAGS"
+  fi
   AC_CHECK_HEADER([cuda_runtime.h], [], [
-    AC_MSG_ERROR([CUDA runtime header not found; try CPPFLAGS="-I<CUDA include dir>"])
-  ])dnl
-])dnl CIT_CUDA_INCDIR
+    AC_MSG_ERROR([CUDA runtime header not found; try setting CUDA_INC.])
+  ])
 
-
-# ----------------------------------------------------------------------
-# CIT_CUDA_LIB
-# ----------------------------------------------------------------------
-# Checking for the CUDA library.
-AC_DEFUN([CIT_CUDA_LIB], [
-  AC_REQUIRE_CPP
-  AC_LANG(C++)
-  AC_MSG_CHECKING([for cudaMalloc in -lcuda])
-  AC_COMPILE_IFELSE(
+  if test "x$CUDA_LIB" != "x"; then
+    CUDA_LDFLAGS="-L$CUDA_LIB"
+    LDFLAGS="$CUDA_LDFLAGS $LDFLAGS"
+  fi
+  CUDA_LIBS="-lcudart"
+  LIBS="$CUDA_LIBS $LIBS"
+  AC_MSG_CHECKING([for cudaMalloc in -lcudart])
+  AC_LINK_IFELSE(
     [AC_LANG_PROGRAM([[#include <cuda_runtime.h>]],
                      [[void* ptr = 0;]]
   	             [[cudaMalloc(&ptr, 1);]])],
     [AC_MSG_RESULT(yes)],
     [AC_MSG_RESULT(no)
-     AC_MSG_ERROR([cuda library not found.])
-  ])dnl
-])dnl CIT_CUDA_LIB
+     AC_MSG_ERROR([CUDA library not found; try setting CUDA_LIB.])
+  ])
 
-# ----------------------------------------------------------------------
-# CIT_CUDA_COMPILER
-# ----------------------------------------------------------------------
-# Checking for the CUDA compiler.
-AC_DEFUN([CIT_CUDA_COMPILER], [
-  AC_PATH_PROG(NVCC, nvcc)
-  if test -z "$NVCC" ; then
-    AC_MSG_FAILURE([cannot find 'nvcc' program.])
-    NVCC=`echo "Error: nvcc is not installed." ; false`
-  fi
+  CPPFLAGS="$CPPFLAGS_save"
+  LDFLAGS="$LDFLAGS_save"
+  LIBS="$LIBS_save"
+  AC_LANG_POP([C++])
+
+  AC_SUBST([CUDA_CPPFLAGS])
+  AC_SUBST([CUDA_LDFLAGS])
+  AC_SUBST([CUDA_LIBS])
 ])dnl CIT_CUDA_COMPILER
 
 
-
 dnl end of file



More information about the CIG-COMMITS mailing list