diff --git a/configure.ac b/configure.ac index 6ce6452..717a3dd 100644 --- a/configure.ac +++ b/configure.ac @@ -719,7 +719,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],,)], # Check if openMP is available m4_ifdef([AC_OPENMP],[AC_OPENMP], [AX_OPENMP([openmp_ok=yes],[openmp_ok=no])]) if test "x$ac_cv_prog_cxx_openmp" != "xunsupported" && test "x$ac_cv_prog_cxx_openmp" != "x"; then - openmp_ok=yes + openmp_ok=yes fi # Signal actual test @@ -727,47 +727,63 @@ AC_MSG_CHECKING(whether to enable OpenMP) # If OpenMP is available if test "x$openmp_ok" = "xyes"; then - # If gammalib is compiled with OpenMP, ctools must also be compiled with - # openmp - if test "x$gammalib_with_openmp" = "xyes"; then - enable_openmp="yes" - else - # ... otherwise, we use it optionally - AC_ARG_ENABLE([openmp], - AS_HELP_STRING([--enable-openmp], - [turn on OpenMP support [default=yes]]), - [enable_openmp="$enableval"], - [enable_openmp="yes"]) - fi + + # Special Linux test to detect shared libgomp libraries that can not be loaded + # dynamically + if test "$OPENMP_CXXFLAGS" = "-fopenmp" -a "$ac_sys_system" = "Linux"; then + AC_MSG_CHECKING(whether we can dynamically load libgomp) + SAVED_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -ldl" + AC_TRY_RUN(AC_LANG_PROGRAM([#include ], + [if (dlopen("libgomp.so.1", RTLD_NOW) == 0) return 1;]), + [AC_MSG_RESULT(yes)], + [enable_openmp="no" + AC_MSG_RESULT(no) + AC_MSG_WARN([OpenMP detected but shared libgomp.so.1 library cannot be dlopen()ed.]) + AC_MSG_WARN([If you use a gcc 4.2.x compiler, this is a known feature. Try to use gcc >= 4.3.])]) + LDFLAGS=$SAVED_LDFLAGS + fi + + # If gammalib is compiled with OpenMP, ctools must also be compiled with + # openmp + if test "x$gammalib_with_openmp" = "xyes"; then + enable_openmp="yes" + else + # ... otherwise, we use it optionally + AC_ARG_ENABLE([openmp], + AS_HELP_STRING([--enable-openmp], + [turn on OpenMP support [default=yes]]), + [enable_openmp="$enableval"], + [enable_openmp="yes"]) + fi + fi # Set compiler flags accordingly if test "x$enable_openmp" = "xyes"; then - CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS" - AC_DEFINE([HAVE_OPENMP], [1], [Define if OpenMP is enabled]) - AC_MSG_RESULT(yes) + CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS" + AC_DEFINE([HAVE_OPENMP], [1], [Define if OpenMP is enabled]) + AC_MSG_RESULT(yes) else - enable_openmp=no - AC_MSG_RESULT(no) + enable_openmp=no + AC_MSG_RESULT(no) fi # Set system specific settings OPENMP_LIB_LDFLAGS= if test "x$enable_openmp" = "xyes"; then - case $ac_sys_system/$ac_sys_release in - Darwin/*) - # - # - OPENMP_LIB_LDFLAGS=-lgomp - ;; - esac + case $ac_sys_system/$ac_sys_release in + Darwin/*) + OPENMP_LIB_LDFLAGS=-lgomp + ;; + esac fi AC_SUBST(OPENMP_LIB_LDFLAGS) # Signal if ctools cannot be compiled as gammalibe requires OpenMP but ctools # cannot be compiled with OpenMP if test "x$enable_openmp" = "xno" && test "x$gammalib_with_openmp" = "xyes"; then - AC_MSG_ERROR([The GammaLib library has been built with openMP support but OpenMP is not available on this system. Please install OpenMP or re-build GammaLib without OpenMP support.]) + AC_MSG_ERROR([The GammaLib library has been built with openMP support but OpenMP is not available on this system. Please install OpenMP or re-build GammaLib without OpenMP support.]) fi AM_CONDITIONAL(OPENMP,test "x$enable_openmp" = "xyes")