@@ -94,6 +94,7 @@ UsageFull() {
9494}
9595
9696# ----- Script variables -------------------------------------------------------
97+ WORKDIR=` dirname $0 ` # Working directory of the configure script
9798COMPILERS=' ' # User-specified compiler suite to use.
9899FLINK=' ' # Flag for linking in Fortran code
99100REQUIRES_FLINK=0 # If 1 FLINK flag required during link phase
@@ -108,6 +109,7 @@ SFX='' # Binary suffix
108109EXE=' ' # Binary executable suffix
109110
110111# ----- Configure options ------------------------
112+ USE_CMAKE=0 # 1 = use cmake for build
111113COMPILE_VERBOSE=0 # 1 = show details during compile
112114USE_MPI=0 # 0 = no MPI, 1 = mpicc etc, 2 = mpiicc etc
113115USE_OPENMP=0 # 0 = no OpenMP, 1 = OpenMP
@@ -128,6 +130,9 @@ USE_CPPTRAJDEBUG=0 # Enable internal cpptraj debug flags
128130CLEAN=' yes' # yes = clean after configure, no = do not
129131PERFORM_CHECKS=' yes' # yes = Check compilers/libraries, no = do not
130132
133+ AR_CMD=' ar cqs' # Archive command for creating static libraries.
134+ RM_CMD=' /bin/rm -f' # Command for removing files.
135+
131136# Flags for large file support
132137LFS=' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
133138
@@ -1453,6 +1458,151 @@ EOF
14531458 fi
14541459}
14551460
1461+ # -------------------------------------------------------------------------------
1462+ # BuildRules <config file> {cxx|cc|f77} ...
1463+ # Write build rules for config files.
1464+ BuildRules () {
1465+ if [ -z " $1 " ] ; then
1466+ echo " Internal Error: BuildRules(): No output file." > /dev/stderr
1467+ exit 1
1468+ fi
1469+ configfile=$1
1470+ shift
1471+ while [ ! -z " $1 " ] ; do
1472+ rule=' '
1473+ case " $1 " in
1474+ cxx )
1475+ echo " CXX=$CXX " >> $configfile
1476+ echo " CXXFLAGS=$CXXFLAGS \$ (DBGFLAGS)" >> $configfile
1477+ rule=' .cpp.o:'
1478+ cmd=' CXX'
1479+ line=' $(CXX) $(DIRECTIVES) $(INCLUDE) $(CXXFLAGS)'
1480+ ;;
1481+ cc )
1482+ echo " CC=$CC " >> $configfile
1483+ echo " CFLAGS=$CFLAGS \$ (DBGFLAGS)" >> $configfile
1484+ rule=' .c.o:'
1485+ cmd=' CC'
1486+ line=' $(CC) $(DIRECTIVES) $(INCLUDE) $(CFLAGS)'
1487+ ;;
1488+ f77 )
1489+ echo " FC=$FC " >> $configfile
1490+ echo " F77FLAGS=$F77FLAGS \$ (DBGFLAGS)" >> $configfile
1491+ rule=' .f.o:'
1492+ cmd=' FC'
1493+ line=' $(FC) $(DIRECTIVES) $(INCLUDE) $(F77FLAGS)'
1494+ ;;
1495+ f90 )
1496+ echo " FC=$FC " >> $configfile
1497+ echo " FFLAGS=$FFLAGS \$ (DBGFLAGS)" >> $configfile
1498+ # No rule needed for pub_fft.F90
1499+ ;;
1500+ nvcc )
1501+ echo " NVCC=$NVCC " >> $configfile
1502+ echo " NVCCFLAGS=$NVCCFLAGS " >> $configfile
1503+ rule=' %%.o : %%.cu'
1504+ cmd=' NVCC'
1505+ line=' $(NVCC) $(DBGFLAGS) $(NVCCFLAGS)'
1506+ ;;
1507+ esac
1508+ if [ ! -z " $rule " ] ; then
1509+ printf " \n$rule \n" >> $configfile
1510+ if [ $COMPILE_VERBOSE -eq 0 ] ; then
1511+ printf " \t@echo $cmd \$ <\n" >> $configfile
1512+ printf " \t@$line -c -o \$ @ \$ <\n\n" >> $configfile
1513+ else
1514+ printf " \n\t$line -c -o \$ @ \$ <\n\n" >> $configfile
1515+ fi
1516+ fi
1517+ shift
1518+ done
1519+ }
1520+
1521+ # -------------------------------------------------------------------------------
1522+ # Use cmake to configure build.
1523+ SetupCmake () {
1524+ CMAKE=` which cmake`
1525+ if [ -z " $CMAKE " ] ; then
1526+ echo " Error: 'cmake' binary not found. Cannot configure with cmake." > /dev/stderr
1527+ exit 1
1528+ fi
1529+ # Not recommended to run in same directory as configure
1530+ if [ " $WORKDIR " = ' .' ] ; then
1531+ echo " Error: 'cmake' configure should be done in a separate directory." > /dev/stderr
1532+ echo " e.g. $ cd \$ CPPTRAJHOME" > /dev/stderr
1533+ echo " $ mkdir build" > /dev/stderr
1534+ echo " $ cd build" > /dev/stderr
1535+ echo " $ ../configure -cmake <options>" > /dev/stderr
1536+ exit 1
1537+ fi
1538+ # Ensure cmake bnuild system exists
1539+ if [ ! -f " $WORKDIR /cmake/AmberBuildSystemInit.cmake" ] ; then
1540+ echo " Error: cmake build system is not present." > /dev/stderr
1541+ echo " If this is a GIT repostitory, you may need to initialize the" > /dev/stderr
1542+ echo " cmake submodule:" > /dev/stderr
1543+ echo " $ git submodule update --init --recursive" > /dev/stderr
1544+ exit 1
1545+ fi
1546+ # Set up cmake options
1547+ cmake_options=' '
1548+ # Figure out compilers
1549+ if [ " $COMPILERS " = ' gnu' ] ; then
1550+ cmake_options=' -DCOMPILER=GNU'
1551+ elif [ " $COMPILERS " = ' intel' ] ; then
1552+ cmake_options=' -DCOMPILER=INTEL'
1553+ elif [ " $COMPILERS " = ' pgi' ] ; then
1554+ cmake_options=' -DCOMPILER=PGI'
1555+ elif [ " $COMPILERS " = ' clang' ] ; then
1556+ cmake_options=' -DCOMPILER=CLANG'
1557+ elif [ " $COMPILERS " = ' cray' ] ; then
1558+ cmake_options=' -DCOMPILER=CRAY'
1559+ fi
1560+ # Build options
1561+ if [ " $USE_MPI " -eq 0 ] ; then
1562+ cmake_options=" $cmake_options -DMPI=FALSE"
1563+ else
1564+ cmake_options=" $cmake_options -DMPI=TRUE"
1565+ fi
1566+ if [ " $USE_OPENMP " -eq 0 ] ; then
1567+ cmake_options=" $cmake_options -DOPENMP=FALSE"
1568+ else
1569+ cmake_options=" $cmake_options -DOPENMP=TRUE"
1570+ fi
1571+ if [ " $USE_CUDA " -eq 0 ] ; then
1572+ cmake_options=" $cmake_options -DCUDA=FALSE"
1573+ else
1574+ cmake_options=" $cmake_options -DCUDA=TRUE"
1575+ fi
1576+ # if [ "${LIB_STAT[$LFFTW3]}" = 'off' ] ; then
1577+ # cmake_options="$cmake_options -DUSE_FFT=FALSE"
1578+ # fi
1579+ if [ $USE_STATIC -eq 1 ] ; then
1580+ cmake_options=" $cmake_options -DSTATIC=TRUE"
1581+ fi
1582+ if [ ! -z " $CPPTRAJHOME " ] ; then
1583+ cmake_options=" $cmake_options -DCMAKE_INSTALL_PREFIX=$CPPTRAJHOME "
1584+ else
1585+ cmake_options=" $cmake_options -DCMAKE_INSTALL_PREFIX=$WORKDIR "
1586+ fi
1587+ if [ $USE_OPT -eq 0 ] ; then
1588+ cmake_options=" $cmake_options -DOPTIMIZE=FALSE"
1589+ else
1590+ cmake_options=" $cmake_options -DOPTIMIZE=TRUE"
1591+ fi
1592+ if [ $USE_DEBUG -eq 0 ] ; then
1593+ cmake_options=" $cmake_options -DCMAKE_BUILD_TYPE=Release"
1594+ else
1595+ cmake_options=" $cmake_options -DCMAKE_BUILD_TYPE=Debug"
1596+ fi
1597+ if [ $COMPILE_VERBOSE -eq 1 ] ; then
1598+ cmake_options=" $cmake_options -DCMAKE_VERBOSE_MAKEFILE=TRUE"
1599+ fi
1600+ echo " Cmake options: $WORKDIR $cmake_options "
1601+ # Run cmake
1602+ $CMAKE $WORKDIR $cmake_options
1603+ exit $?
1604+ }
1605+
14561606# ==============================================================================
14571607# MAIN SCRIPT
14581608
@@ -1516,6 +1666,7 @@ while [ ! -z "$1" ] ; do
15161666 ' NVCCFLAGS' ) NVCCFLAGS=" $VALUE " ;;
15171667 ' SHADER_MODEL' ) SHADER_MODEL=" $VALUE " ;;
15181668 # Build options
1669+ ' -cmake' ) USE_CMAKE=1 ;;
15191670 ' -mpi' ) USE_MPI=1 ;;
15201671 ' -intelmpi' ) USE_MPI=2 ;;
15211672 ' -openmp' ) USE_OPENMP=1 ;;
@@ -1595,6 +1746,11 @@ if [ -z "$NBITS" ] ; then
15951746 fi
15961747fi
15971748
1749+ # Should we use cmake instead?
1750+ if [ $USE_CMAKE -eq 1 ] ; then
1751+ SetupCmake
1752+ fi
1753+
15981754# Basic checks and directives
15991755BasicChecks
16001756
@@ -1727,18 +1883,12 @@ fi
17271883
17281884# ----- Determine which targets to build ---------
17291885CPPTRAJ_TARGET=" "
1730- AMBPDB_TARGET=" "
17311886LIBCPPTRAJ_TARGET=" "
17321887NPROC_TARGET=" "
17331888INSTALL_TARGETS=" "
17341889# Always build cpptraj
17351890CPPTRAJ_TARGET=cpptraj$SFX$EXE
17361891INSTALL_TARGETS=$INSTALL_TARGETS " install_cpptraj"
1737- # Only build ambpdb in serial
1738- if [ $USE_MPI -eq 0 -a $USE_OPENMP -eq 0 -a $USE_CUDA -eq 0 ] ; then
1739- AMBPDB_TARGET=ambpdb
1740- INSTALL_TARGETS=$INSTALL_TARGETS " install_ambpdb"
1741- fi
17421892# Can we build libcpptraj? TODO serial/OpenMP only?
17431893if [ $USE_SHARED -eq 1 ] ; then
17441894 LIBCPPTRAJ_TARGET=' $(CPPTRAJLIB)/libcpptraj$(SHARED_SUFFIX)'
@@ -1753,22 +1903,43 @@ fi
17531903# CUDA
17541904if [ $USE_CUDA -eq 1 ] ; then
17551905 CUDA_TARGET=' cuda_kernels/libcpptraj_cuda.a'
1906+ cat > src/cuda_kernels/cuda.config.h << EOF
1907+ AR = $AR_CMD
1908+ DEL_FILE = $RM_CMD
1909+ EOF
1910+ BuildRules src/cuda_kernels/cuda.config.h nvcc
17561911fi
17571912# Readline
17581913if [ " ${LIB_STAT[$LREADLINE]} " = ' bundled' ] ; then
17591914 READLINE_TARGET=${LIB_FLAG[$LREADLINE]}
1915+ cat > src/readline/readline.config.h << EOF
1916+ DIRECTIVES = -DHAVE_CONFIG_H
1917+ INCLUDE = -I.
1918+ AR = $AR_CMD
1919+ DEL_FILE = $RM_CMD
1920+ EOF
1921+ BuildRules src/readline/readline.config.h cc
17601922else
17611923 READLINE_TARGET=' noreadline'
17621924fi
17631925# Xdrfile
17641926if [ " ${LIB_STAT[$LXDRFILE]} " = ' bundled' ] ; then
17651927 XDRFILE_TARGET=${LIB_FLAG[$LXDRFILE]}
1928+ cat > src/xdrfile/xdrfile.config.h << EOF
1929+ AR = $AR_CMD
1930+ DEL_FILE = $RM_CMD
1931+ EOF
1932+ BuildRules src/xdrfile/xdrfile.config.h cc
17661933else
17671934 XDRFILE_TARGET=' noxdrfile'
17681935fi
17691936# Arpack
17701937if [ " ${LIB_STAT[$LARPACK]} " = ' bundled' ] ; then
17711938 ARPACK_TARGET=${LIB_FLAG[$LARPACK]}
1939+ cat > src/arpack/arpack.config.h << EOF
1940+ DEL_FILE = $RM_CMD
1941+ EOF
1942+ BuildRules src/arpack/arpack.config.h f77
17721943else
17731944 ARPACK_TARGET=' noarpack'
17741945fi
@@ -1800,21 +1971,14 @@ if [ ! -z "$DBGFLAGS" ] ; then
18001971 echo " DBGFLAGS=$DBGFLAGS " >> config.h
18011972fi
18021973cat >> config.h << EOF
1803- CC=$CC
1804- CXX=$CXX
1805- FC=$FC
1806- CFLAGS=$CFLAGS \$ (DBGFLAGS)
1807- CXXFLAGS=$CXXFLAGS \$ (DBGFLAGS)
1808- FFLAGS=$FFLAGS \$ (DBGFLAGS)
1809- F77FLAGS=$F77FLAGS \$ (DBGFLAGS)
1974+ DEL_FILE = $RM_CMD
1975+
18101976SHARED_SUFFIX=$SHARED_SUFFIX
18111977DIRECTIVES=$DIRECTIVES
18121978INCLUDE=$INCLUDE
18131979
18141980LIBCPPTRAJ_TARGET=$LIBCPPTRAJ_TARGET
18151981
1816- NVCC=$NVCC
1817- NVCCFLAGS=$NVCCFLAGS \$ (DBGFLAGS)
18181982CUDA_TARGET=$CUDA_TARGET
18191983
18201984READLINE_TARGET=$READLINE_TARGET
@@ -1832,25 +1996,11 @@ SFX=$SFX
18321996EXE=$EXE
18331997
18341998EOF
1835- if [ $COMPILE_VERBOSE -eq 1 ] ; then
1836- cat > buildrules.h << EOF
1837- .cpp.o:
1838- \$ (CXX) \$ (DIRECTIVES) \$ (INCLUDE) \$ (CXXFLAGS) -c -o \$ @ \$ <
1839-
1840- .c.o:
1841- \$ (CC) \$ (DIRECTIVES) \$ (INCLUDE) \$ (CFLAGS) -c -o \$ @ \$ <
1842- EOF
1843- else
1844- cat > buildrules.h << EOF
1845- .cpp.o:
1846- @echo CXX \$ <
1847- @\$ (CXX) \$ (DIRECTIVES) \$ (INCLUDE) \$ (CXXFLAGS) -c -o \$ @ \$ <
1848-
1849- .c.o:
1850- @echo CC \$ <
1851- @\$ (CC) \$ (DIRECTIVES) \$ (INCLUDE) \$ (CFLAGS) -c -o \$ @ \$ <
1852- EOF
1853- fi
1999+ # if [ "$FFT_TARGET" = 'pub_fft.o' ] ; then
2000+ BuildRules config.h cc cxx f90
2001+ # else
2002+ # BuildRules config.h cc cxx
2003+ # fi
18542004
18552005# ----- Create directories if necessary ----------
18562006if [ ! -e " $CPPTRAJBIN " ] ; then
0 commit comments