Use OpenMP by default
[ctsim.git] / configure.ac
index e0fccd69c8ad1a50ca787b276f973b03da836823..930c62a2d65976362581aa3af73d07993f62c2cc 100644 (file)
@@ -1,11 +1,41 @@
+dnl *****************************************************************************
+dnl FILE IDENTIFICATION
+dnl   Name:          ctsim.cpp
+dnl   Purpose:       Top-level routines of CTSim program
+dnl   Programmer:    Kevin Rosenberg
+dnl   Date Started:  July 2000
+dnl
+dnl  This is part of the CTSim program
+dnl  Copyright (c) 1983-2009 Kevin Rosenberg
+dnl
+dnl  This program is free software; you can redistribute it and/or modify
+dnl  it under the terms of the GNU General Public License (version 2) as
+dnl  published by the Free Software Foundation.
+dnl
+dnl  This program is distributed in the hope that it will be useful,
+dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl  GNU General Public License for more details.
+dnl
+dnl  You should have received a copy of the GNU General Public License
+dnl  along with this program; if not, write to the Free Software
+dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+dnl****************************************************************************/
+
 dnl Process this file with autoconf to produce a configure script.
 
 dnl Must reset CDPATH so that bash's cd does not print to stdout
 dnl CDPATH=
 
-AC_INIT
+AC_INIT([CTSim], [6.0.0], [ctsim-users@kpe.io], [ctsim], [http://www.ctsim.org/])
 AC_CONFIG_SRCDIR([src/ctsim.cpp])
-AM_INIT_AUTOMAKE(ctsim,4.0.2)
+AC_CONFIG_MACRO_DIR([scripts])
+dnl permit auxiliary scripts directory (e.g. config.sub, config.guess, install-sh)
+AC_CONFIG_AUX_DIR(scripts/)
+
+AC_CANONICAL_TARGET
+AM_MAINTAINER_MODE
+AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(config.h)
 
 dnl Checks for programs.
@@ -16,6 +46,9 @@ AC_PROG_RANLIB
 
 AC_PROG_CC
 AC_PROG_CXX
+CFLAGS=""
+CXXFLAGS=""
+
 AC_C_BIGENDIAN
 
 AC_PATH_PROG(wxconfig,wx-config)
@@ -29,7 +62,6 @@ AC_CHECK_SIZEOF(long, 4)
 AC_CHECK_SIZEOF(float, 4)
 AC_CHECK_SIZEOF(double, 8)
 
-dnl Add define templates
 
 dnl Checks for libraries.
 AC_CHECK_LIB(z, deflate, [ zlib="true" ], [ zlib="false" ;  AC_MSG_WARN([zlib missing. Will need zlib for PNG support])])
@@ -40,14 +72,26 @@ AC_CHECK_LIB(readline, main, [readline=true;
                  AC_DEFINE([HAVE_READLINE],1,[Readline library])],
                 [readline=false], [-lcurses])  
 wxwin=false
-AC_CHECK_LIB(wx_gtk-2.4, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])])
-AC_CHECK_LIB(wx_mac-2.4, main, [wxwin=true; wx_mac=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])])
-AC_CHECK_LIB(fftw, fftw_one, [fftw=true; AC_DEFINE(HAVE_FFTW,1,[FFTW library])], [fftw=false])
-AC_CHECK_LIB(GL, main, [libgl=true], [libgl=false], [-L/usr/X11R6/lib -lXt -lXext])
+AC_CHECK_LIB(gtk-x11-2.0, main, [hasx11gtk2=true], [])
+if test "x$hasx11gtk2" = "x" ; then
+  AC_MSG_NOTICE([Does not have X11 GTK2])
+  AC_DEFUN([AM_PATH_GLIB_2_0], [])
+  AC_DEFUN([AM_PATH_GTK_2_0], [])
+fi
+if test "$hasx11gtk2" = "true" ; then
+  AM_PATH_GLIB_2_0(2.0.0,,AC_MSG_ERROR(You should get glib 2.0.0 or better.))
+  AM_PATH_GTK_2_0(2.0.0,havegtk_am=yes,havegtk_am=no)
+  CFLAGS="${CFLAGS} ${g76GTK_CFLAGS} ${GLIB_CFLAGS}"
+fi
+
+AC_CHECK_LIB(wx_gtk2u_core-3.0, main, [wxwin=true; wx_gtk=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])], [], [-L/usr/lib64 -L/usr/lib ${GTK_LIBS} ${GLIB_LIBS} ])
+AC_CHECK_LIB(wx_mac_core-3.0, main, [wxwin=true; wx_mac=true; AC_DEFINE(HAVE_WXWINDOWS,1,[wxwindows library])])
+AC_CHECK_LIB(fftw3, fftw_malloc, [fftw=true; AC_DEFINE(HAVE_FFTW,1,[FFTW library])], [fftw=false], [-L/usr/lib64 -L/usr/lib])
+AC_CHECK_LIB(GL, main, [libgl=true], [libgl=false], [-L/usr/X11R6/lib -L/usr/X11R6/lib64])
 AC_CHECK_LIB(pthread, main, [pthread=true], [pthread=false])
 
 if test "$zlib" = "true" ; then
-  AC_CHECK_LIB(png, main, [png=true ; AC_DEFINE(HAVE_PNG,1,[PNG library])], [png=false], [-lz -lm])
+  AC_CHECK_LIB(png, main, [png=true ; AC_DEFINE(HAVE_PNG,1,[PNG library])], [png=false], [-L/opt/local/lib -lz -lm])
 fi
 
 dnl Checks for header files.
@@ -62,7 +106,7 @@ AC_STRUCT_TM
 
 dnl Checks for library functions.
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS(strtod strtol snprintf htonl usleep vsprintf vsnprintf)
+AC_CHECK_FUNCS(strtod strtol snprintf htonl usleep vsprintf vsnprintf basename setjmp setpriority time gettimeofday getenv)
 AC_CHECK_FUNC(basename)
 AC_CHECK_FUNC(setjmp)
 AC_CHECK_FUNC(setpriority)
@@ -81,8 +125,29 @@ if test "${getopt_long}" = "false" ; then
   AC_DEFINE(HAVE_GETOPT_LONG,1,[getopt_long library])
   ctlibs_base="$ctlibs_base -lgetopt"
   LDFLAGS="$LDFLAGS -L../getopt"
-  AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test 1==1)
+  GETOPTLONG=1
 fi
+AM_CONDITIONAL(INCLUDED_GETOPT_LONG, test "$GETOPTLONG"="1")
+
+ARCH_OPTION=""
+case $target_cpu in
+    i386|i486|i586|i686|x86|x86_64)
+        AX_EXT
+        CFLAGS="$CFLAGS $CPUEXT_FLAGS $SIMD_FLAGS"
+        CXXFLAGS="$CXXFLAGS $CPUEXT_FLAGS $SIMD_FLAGS"
+        ;;
+    powerpc*)
+        ARCH_OPTION="-fno-common -faltivec";;
+    armv1*|armv2*|armv3*|armv4*|armv5*|armv6*)
+        ARCH_OPTION="-ffast-math";;
+    armv7*|armv8*)
+        ARCH_OPTION="-ffast-math -mcpu=cortex-a7 -mfloat-abi=hard -mfpu=neon-vfpv4";;
+    *)
+        # unknown architecture : use portable C version
+        ARCH_OPTION="";;
+esac
+CPPFLAGS="$CPPFLAGS $ARCH_OPTION"
+CXXFLAGS="$CPPFLAGS $ARCH_OPTION"
 
 if test "${readline}" = "true" ; then
   ctlibs_base="$ctlibs_base -lreadline"
@@ -98,10 +163,10 @@ AC_MSG_CHECKING([debug])
 AC_ARG_ENABLE(debug,
 [  --enable-debug          Turn on debugging],
 [case "${enableval}" in
-  yes) debug=true 
+  yes) debug="true" 
        AC_MSG_RESULT(yes)
        ;;
-  no)  debug=false 
+  no)  debug="false" 
        AC_MSG_RESULT(no)
        ;;
   *) AC_MSG_RESULT([bad value ${enableval} for --enable-debug]) 
@@ -117,10 +182,10 @@ dnl CFLAGS="$CFLAGS -I/usr/local/include"
 dnl LDFLAGS="$LDFLAGS -L/usr/local/lib"
 
 if test "$debug" = "true" ; then
-  CFLAGS="$CFLAGS -g -DDEBUG"
+  CFLAGS="$CFLAGS -g -O0 -DDEBUG"
   AC_DEFINE(DEBUG,1,[turn on debugging])
 else
-  CFLAGS="$CFLAGS -O3 -DNDEBUG -fomit-frame-pointer -funroll-loops"
+  CFLAGS="$CFLAGS -g -O4 -DNDEBUG -fomit-frame-pointer"
   AC_DEFINE(NDEBUG,1,[no debugging])
 fi
 
@@ -142,9 +207,7 @@ AC_MSG_CHECKING(sstream)
 
 CFLAGS="$CFLAGS -Wall"
 AC_MSG_CHECKING(whether to enable verbose warnings)
-AC_ARG_ENABLE(verbose-warnings,
-[  --enable-verbose-warnings
-                          Enable verbose compiler warnings.],
+AC_ARG_ENABLE(verbose-warnings,AS_HELP_STRING([--enable-verbose-warnings],[Enable verbose compiler warnings.]),
 [ case "$enableval" in
   yes)
     AC_MSG_RESULT(yes)
@@ -157,9 +220,7 @@ AC_ARG_ENABLE(verbose-warnings,
 )
 
 AC_MSG_CHECKING(static executables)
-AC_ARG_ENABLE(static,
-[  --enable-static
-                            Enable static executables.],
+AC_ARG_ENABLE(static,AS_HELP_STRING([--enable-static],[Enable static executables]),
 [ case "$enableval" in
   yes)
     AC_MSG_RESULT(yes)
@@ -171,9 +232,16 @@ AC_ARG_ENABLE(static,
   esac ], AC_MSG_RESULT(no)
 )
 
+dnl Checking if use OpenMP
+AC_ARG_ENABLE([openmp], AS_HELP_STRING([--disable-openmp],[Disable use of OpenMP]))
+AS_IF([test "x$enable_openmp" != "xno"], [
+    AX_OPENMP
+    CFLAGS="$CFLAGS $OPENMP_CFLAGS"
+    CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
+])
+
 dnl Set LAM path
-AC_ARG_WITH(lam,
-[  --with-lam[=PATH]         Set path of LAM MPI ],
+AC_ARG_WITH(lam,AS_HELP_STRING([--with-lam[=PATH]],[Set path of LAM MPI ]),
 [    if test "$withval" != "no" ; then
          trylamdir=$withval
      fi ]
@@ -213,7 +281,7 @@ AC_ARG_WITH(ctn,
      fi ]
 )
 
-if test "$withval" == "no" -o "$withval" == "NONE" ; then
+if test "$withval" = "no" -o "$withval" = "NONE" ; then
   AC_MSG_CHECKING([for CTN DICOM installation])
   AC_MSG_RESULT([disabled])
 else
@@ -232,7 +300,7 @@ else
       break
     fi
   done
-  if test "$ctnlib" == "true" -a "$ctninclude" == "true" ; then
+  if test "$ctnlib" = "true" -a "$ctninclude" = "true" ; then
       ctn="true"
       AC_DEFINE(HAVE_CTN_DICOM,1,[ctn dicom library])
       AC_MSG_RESULT([yes])
@@ -246,7 +314,7 @@ AC_MSG_CHECKING([for CPU specification])
 AC_ARG_WITH(mcpu,
 [  --with-mcpu[=CPU]         Set name of CPU for gcc -mcpu])
 
-if [ "$withval" == "" ] || [ "$withval" == "no" ]; then
+if test "$withval" = "no" -o "$withval" = "yes" -o "$withval" = ""; then
   AC_MSG_RESULT([no])
 else
   AC_MSG_RESULT([$withval])
@@ -268,50 +336,39 @@ AC_ARG_WITH(webdata-url, [  --with-webdata-url=PATH Set URL path of webdata],
 [ webdataurl=$withval ; AC_SUBST(webdataurl) ] )
 
 AC_ARG_WITH(html-dir, [  --with-html-dir=PATH    Set directory of html files], 
-[ htmldir=$withval ; AC_SUBST(htmldir) ] )
+[ html_%dir=$withval ; AC_SUBST(htmldir) ] )
 
-if test -n "$cgibindir" -o -n "$cgibinurl" ; then
+if test "x$cgibindir" != "x" -o "x$cgibinurl" != "x" ; then
   cgiprograms="ctsim.cgi ctsim.conf"
   AC_SUBST(cgiprograms)
 fi
 
-if test -n "$htmldir" ; then
+if test "x$html_dir" = "x" ; then
   htmldata=simulate.html
   AC_SUBST(htmldata)
 fi
-AM_CONDITIONAL(USE_HTML, test -n "$htmldir")
+AM_CONDITIONAL(USE_HTML, test "x$html_dir" = "x")
 
-if test -n "$cgibindir" -o -n "$cgibinurl" -o -n "$webdatadir" -o -n "$webdataurl" -o -n "$htmldir" ; then
+if test "x$cgibindir" != "x" -o "x$cgibinurl" != "x" -o "x$webdatadir" != "x" -o "x$webdataurl" != "x" -o "x$html_dir" != "x" ; then
   webenabled=true
   AC_SUBST(webenabled)
   AC_MSG_RESULT([yes])
-  if test -z "$cgibindir" ; then
+  if test "x$cgibindir" = "x" ; then
     AC_MSG_ERROR([--with-cgibin-dir not set for web access])
-  elif test -z "$cgibinurl" ; then
+  elif test "x$cgibinurl" = "x" ; then
     AC_MSG_ERROR([--with-cgibin-url not set for web access])
-  elif test -z "$webdatadir" ; then
+  elif test "x$webdatadir" = "x" ; then
     AC_MSG_ERROR([--with-webdata-dir not set for web access])
-  elif test -z "$webdataurl" ; then
+  elif test "x$webdataurl" = "x" ; then
     AC_MSG_ERROR([--with-webdata-url not set for web access])
-  elif test -z "$htmldir" ; then
+  elif test "x$html_dir" = "x" ; then
     AC_MSG_ERROR([--with-html-dir not set for web access])
   fi
 else
   AC_MSG_RESULT([no])
 fi
 
-AM_CONDITIONAL(USE_LAM, test -n "$lamdir")
-
-dnl Prepare to support X.  If the user gave the command-line option
-dnl --without-x, AC_PATH_XTRA will set no_x to "yes".  Otherwise, it will
-dnl add appropriate preprocessor flags to X_CFLAGS, and appropriate linker
-dnl flags to X_LIBS.  It also checks for system-specific X libraries, and
-dnl adds them to X_PRE_LIBS or X_EXTRA_LIBS, as appropriate.  (The former
-dnl is where "-lSM -lICE" goes, in X11R6.)  We define the X_TOOLKIT_LIBS
-dnl and X_BASIC_LIBS argument vectors ourselves, and if X is to be
-dnl supported, we'll concatenate the whole lot of these into a command line
-dnl for libtool.  See, e.g., the libplot_la_LIBADD line in
-dnl libplot/Makefile.am.
+AM_CONDITIONAL(USE_LAM, test "x$lamdir" != "x")
 
 AC_PATH_XTRA
 AC_SUBST(X_CFLAGS)
@@ -322,52 +379,48 @@ AC_SUBST(X_PRE_LIBS)
 AC_SUBST(X_BASIC_LIBS)
 AC_SUBST(X_EXTRA_LIBS)
 
-X_TOOLKIT_LIBS="-lXt"
-X_BASIC_LIBS="-lXext -lX11 -lXmu"
-
-dnl Check whether libXt has thread support.  Some platforms may have
-dnl pthread support in libc, but no thread support in libXt/libX11.
-our_saved_LDFLAGS="$LDFLAGS"
-LDFLAGS="$X_LIBS $LDFLAGS"
-AC_CHECK_LIB(Xt, XtToolkitThreadInitialize, AC_DEFINE(X_THREAD_SUPPORT,1,[x thread supported]), , $X_PRE_LIBS $X_BASIC_LIBS $X_EXTRA_LIBS)
-LDFLAGS="$our_saved_LDFLAGS"
-
 dnl Our Makefile.am files test the automake variable NO_X to determine
 dnl whether X should be supported.
-AM_CONDITIONAL(NO_X, test "x$no_x" = "xyes")
+AM_CONDITIONAL(NO_X, test "x$with_x" = "xno")
 
 my_includes="$my_includes -I../include -I.. -I/usr/local/include"
-AC_SUBST(my_includes)
 
 LDFLAGS="$LDFLAGS -L/usr/local/lib"
 
 AC_MSG_CHECKING([for X])
-if test "$no_x" != "yes" ; then
+if test "$with_x" != "no" && test "$wxwin" = "true"; then
   AC_DEFINE(HAVE_X11,1,[X11 system])
-  LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib"
-  my_includes="$my_includes -I/usr/X11R6/include"
+  LDFLAGS="$LDFLAGS -L../libctgraphics -L/usr/X11R6/lib -L/usr/X11R6/lib64"
+  my_includes="$my_includes -I/usr/X11R6/include -I/usr/include/X11"
   ctlib_graphics="$ctlibs_base -lctgraphics"
   AC_MSG_RESULT(yes)
   ctlib_graphics="$ctlib_graphics $X_BASIC_LIBS $X_TOOLKIT_LIBS"
+  wx_cppflags="`$wxconfig --cppflags`"
   if test "$libgl" = "true" ; then
-    # Removed "-lglut" for Mac OS X compilation
+    dnl  Removed "-lglut" for Mac OS X compilation
     ctlib_graphics="$ctlib_graphics -lGL -lGLU"
     if test "$wxwin" = "true" ; then
-      if [ "$wx_gtk" ]; then 
-        ctlib_graphics="$ctlib_graphics -lwx_gtk_gl-2.4"
-      elif [ "$wx_mac" ]; then
-        ctlib_graphics="$ctlib_graphics -lwx_mac_gl-2.4"
+       wxdebug=""
+       if test "$debug" = "true"; then
+         wxdebug="--debug"
+       fi  
+      if test "x$wx_gtk" != "x" ; then
+       ctlib_graphics="$ctlib_graphics `$wxconfig $wxdebug --version=3.0  --libs std,gl` ${GTK_LIBS} ${GLIB_LIBS}"
+       
+      elif test "x$wx_mac" != "x" ; then
+        ctlib_graphics="$ctlib_graphics `$wxconfig $wxdebug --version=3.0 --libs std,gl`"
       fi
     fi
   fi
   if test "$wxwin" = "true" ; then
     AC_DEFINE(HAVE_SGP,1,[use sgp library])
-    AM_CONDITIONAL(HAVE_SGP, test 1==1)
   fi
 else
   AC_MSG_RESULT(no)
 fi
 
+AM_CONDITIONAL(HAVE_SGP, test "$wxwin" = "true")
+
 if test "$png" = "true" ; then
   ctlibs_tools="$ctlibs_tools -lpng"
 fi
@@ -375,7 +428,7 @@ if test "$zlib" = "true" ; then
   ctlibs_tools="$ctlibs_tools -lz"
 fi
 if test "$fftw" = "true" ; then
-  ctlibs_tools="$ctlibs_tools -lrfftw -lfftw"
+  ctlibs_tools="$ctlibs_tools -lfftw3"
 fi
 if test "$ctn" = "true"; then
   ctlibs_tools="$ctlibs_tools -lctn"
@@ -408,7 +461,7 @@ dnl Check for efence
 AC_CHECK_LIB(efence, main, [efence=true], [efence=false])
 AC_MSG_CHECKING([for enable-efence])
 AC_ARG_ENABLE(efence,
-[  --enable-efence        Use ElectricFence memory allocation],
+[--enable-efence],[Use ElectricFence memory allocation],
 [case "${enableval}" in
   yes) useefence=true 
        AC_MSG_RESULT(yes)
@@ -428,26 +481,26 @@ if test "$efence" = "true" -a "$useefence" = "true" ; then
 fi
 
 if test "$wxwin" = "true" ; then
-  if [ "$wx_gtk" = "true" ] || [ "$wx_mac" == "true" ] ; then  
-    wxcflags=`$wxconfig --cflags`
-    wxlibs=`$wxconfig --libs`
+  if test "$wx_gtk" = "true"  -o "$wx_mac" = "true" ; then
+    wxcflags=`$wxconfig $wxdebug --cxxflags --version=3.0`
+    #wxlibs=`$wxconfig --libs`
   else
        wxcflags="-D__WXMSW__ -D__WIN32__ -D__GNUWIN32__"
         wxlibs="-lwx -lglui -ljpeg -lxpm -lzlib -ltiff"
   fi
   CFLAGS="$CFLAGS -I../include $wxcflags"
   ctlib_graphics="$ctlib_graphics $wxlibs"
-  AM_CONDITIONAL(HAVE_WXWINDOWS, test 1==1 )
 fi
 AC_SUBST(wxcflags)
 AC_SUBST(wxlibs)
+AM_CONDITIONAL(HAVE_WXWINDOWS, test "$wxwin"="true")
 
 dnl Setting projet libraries and includes
 LDFLAGS="$LDFLAGS -L../libctsupport -L../libctsim" 
 ctlibs="$ctlibs_base -lctsim $ctlib_graphics -lctsupport $ctlibs_tools"
 AC_SUBST(ctlibs)
 
-if test -n "$lamdir" ; then
+if test "x$lamdir" != "x" ; then
   lamprograms="ctsimtext-lam"
   AC_SUBST(lamprograms)
   lamdefs="$CFLAGS"
@@ -456,6 +509,9 @@ fi
 
 CXXFLAGS="$CFLAGS"
 
+AC_SUBST(my_includes)
+AC_SUBST(wx_cppflags)
+
 AC_CONFIG_FILES([Makefile libctgraphics/Makefile libctsupport/Makefile libctsim/Makefile man/Makefile cgi-bin/ctsim.cgi cgi-bin/Makefile html/simulate.html html/Makefile include/Makefile getopt/Makefile tools/sample-ctsim.sh cgi-bin/ctsim.conf tools/Makefile src/Makefile helical/Makefile helical/sample-helical.sh])
 
 AC_OUTPUT