From 30ea0414e4920f1baaa082555cd62451e94b1871 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Thu, 11 Jul 2024 12:55:31 +0200
Subject: [PATCH] Enable optional NVTX profiling and add clang specific
 compiler flags

---
 build/configure.ac | 46 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/build/configure.ac b/build/configure.ac
index d2e77451..9bdce89f 100644
--- a/build/configure.ac
+++ b/build/configure.ac
@@ -92,7 +92,11 @@ AC_ARG_ENABLE(
   [AS_HELP_STRING([--enable-mpi], [enable MPI compilation [default=auto]])],
   [
     if test "x$enableval" = "xno"; then
-      AC_PROG_CXX([g++ clang])
+      if test "x$CXX" = "x"; then
+        AC_PROG_CXX([g++ clang++])
+      else
+        AC_PROG_CXX([$CXX])
+      fi
       AC_MSG_NOTICE([Using $CXX])
       AC_SUBST([MPIFLAGS], [""])
     elif test "x$enableval" = "xauto"; then
@@ -100,7 +104,7 @@ AC_ARG_ENABLE(
       if test "x$CXX" != "x"; then
         AC_SUBST([MPIFLAGS], [-DUSE_MPI])
       else
-        AC_PROG_CXX([g++ clang])
+        AC_PROG_CXX([g++ clang++])
         AC_SUBST([MPIFLAGS], [""])
       fi
     elif test "x$enableval" = "xyes"; then
@@ -113,17 +117,28 @@ AC_ARG_ENABLE(
     fi
   ],
   [
-    AC_PROG_CXX([mpicxx mpic++ mpiCC])
-    if test "x$CXX" != "x"; then
-      AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+    if test "x$CXX" = "x"; then
+      AC_PROG_CXX([mpicxx mpic++ mpiCC])
+      if test "x$CXX" != "x"; then
+        AC_SUBST([MPIFLAGS], [-DUSE_MPI])
+      else
+        AC_PROG_CXX([g++ clang++])
+        AC_SUBST([MPIFLAGS], [""])
+        AC_MSG_NOTICE([Using $CXX])
+      fi
     else
-      AC_PROG_CXX([g++ clang])
-      AC_SUBST([MPIFLAGS], [""])
-      AC_MSG_NOTICE([Using $CXX])
+      AC_PROG_CXX([$CXX])
     fi
   ]
 )
 AC_PROG_F77([gfortran f77])
+# Check whether the compiler is clang++ (needs additional flags)
+CXX_IS_CLANG=$($CXX --version | grep clang)
+AS_IF(
+  [test "x$CXX_IS_CLANG" = "x0"],
+  [AC_SUBST([CLANGFLAGS], [-stdlib=libstdc++])],
+  [AC_SUBST([CLANGFLAGS], [""])]
+)
 
 # Libtool initialization
 LT_INIT
@@ -219,8 +234,21 @@ AC_ARG_WITH(
   ]
 )
 
+AC_ARG_ENABLE(
+  [nvtx],
+  [AS_HELP_STRING([--enable-nvtx], [use NVTX profiling @<:@default=no@:>@])],
+  [
+    if test "x$enableval" = "xyes"; then
+      AC_SUBST([NVTXFLAGS], ["-DUSE_NVTX"])
+    fi
+  ],
+  [
+    AC_SUBST([NVTXFLAGS], [""])
+  ]
+)
+
 FFLAGS="-std=legacy -O3"
-CXXFLAGS="-O3 -ggdb -I$HDF5_INCLUDE $MPIFLAGS $OMPFLAGS $LAPACKFLAGS $MAGMAFLAGS"
+CXXFLAGS="$CLANGFLAGS -O3 -ggdb -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
 SUBDIRS="cluster libnptm sphere testing trapping"
 
 # Send output to Makefiles
-- 
GitLab