#!/bin/bash # where is the source tree located srcdir=$(dirname $(dirname $(dirname "$0"))) # display help text usage () { cat < if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor CXX C++ compiler command CXXFLAGS C++ compiler flags CXXCPP C++ preprocessor F77 Fortran 77 compiler command FFLAGS Fortran 77 compiler flags FC Fortran compiler command FCFLAGS Fortran compiler flags CMAKE_COMMAND Executable used to run cmake scripts Use these variables to override the choices made by \`configure' or to help it to find libraries and programs with nonstandard names/locations. EOF } # report an error regarding the arguments invalid_arg () { cat </dev/null 2>&1; then CMAKE_COMMAND=cmake28 else CMAKE_COMMAND=cmake fi fi for OPT in "$@"; do case "$OPT" in --*) OPTARG=${OPT#--} # OPTARG now contains everything after double dashes case "${OPTARG}" in prefix=*) # remove prefix consisting of everything up to equal sign prefix=${OPTARG#*=} ;; help) usage exit 0 ;; with-*) # get the name of the package; everything before equal sign pkgname=${OPTARG%=*} pkgname=${pkgname#with-} # get the location of the package; everyhing after equal sign pkgloc=${OPTARG#*=} # the parameter to this option is an executable program, so # skip the directory test in that case if [ "${pkgname}" = "cmake" ]; then CMAKE_COMMAND="${pkgloc}" break fi # tilde expansion; quote safely before running eval on it eval pkgloc=$(printf "%q" "${pkgloc}") # expand to full path since CMake changes to source directory (!) # this also normalize the path name wrt. not having a trailing slash test -d "${pkgloc}" && pkgloc=$(sh -c "cd \"${pkgloc}\"; pwd") # special aliases case "${pkgname}" in umfpack) pkgname="SuiteSparse" ;; tinyxml) pkgname="TinyXML" ;; esac # packages need different suffix for their root (sic) case "${pkgname}" in pch) pch_use=" -DPRECOMPILE_HEADERS:BOOL=ON" rootvar="" ;; mpi |\ mpi-prefix) rootvar="_MPI_PREFIX_PATH" ;; agmg |\ ert |\ boost |\ superlu |\ SuiteSparse |\ TinyXML |\ opm |\ opm-* |\ dune |\ dune-* |\ zlib) rootvar="${pkgname^^}_ROOT" rootvar="${rootvar/-/_}" ;; *) invalid_opt --with-${pkgname} rootvar="" ;; esac # add this to the list of existing features test -n "${rootvar}" && \ FEATURES="${FEATURES} \"-D${rootvar}=${pkgloc}\"" ;; without-* | \ disable-*) # get the name of the package pkgname=$OPTARG pkgname=${pkgname#disable-} pkgname=${pkgname#without-} # special aliases case "${pkgname}" in umfpack) pkgname="SuiteSparse" ;; tinyxml) pkgname="TinyXML" ;; esac # casing is of course different case "${pkgname}" in option-checking) option_check=no # special flag: don't disable any particular package pkgname="" ;; debug) buildtype=" -DCMAKE_BUILD_TYPE=Release" # special flag: don't disable any particular package pkgname="" ;; pch) pch_use=" -DPRECOMPILE_HEADERS:BOOL=OFF" pkgname="" ;; silent-rules) silent_rules=" -DCMAKE_VERBOSE_MAKEFILE=ON" pkgname="" ;; system-debug) debug_loc=" -DSYSTEM_DEBUG=OFF" pkgname="" ;; wpo |\ lto ) use_lto=" -DWHOLE_PROG_OPTIM=OFF" pkgname="" ;; openmp) use_openmp=" -DUSE_OPENMP=OFF" pkgname="" ;; mpi | \ parallel) use_mpi=" -DUSE_MPI=OFF" pkgname="" ;; tests) use_tests=" -DBUILD_TESTING=OFF" pkgname="" ;; examples) use_samples=" -DBUILD_EXAMPLES=OFF" pkgname="" ;; agmg |\ ert |\ superlu) pkgname="${pkgname^^}" ;; openmp) pkgname="OpenMP" ;; gxx11check) pkgname="CXX11Features" ;; *) invalid_opt --disable-${pkgname} pkgname="" ;; esac # only disable packages if the flag refers to a proper one test -n "${pkgname}" && \ FEATURES="${FEATURES} -DCMAKE_DISABLE_FIND_PACKAGE_${pkgname}=TRUE" ;; enable-*) # what kind of library are we building; shared or static? kind=${OPTARG#enable-} case "${kind}" in system-debug) debug_loc=" -DSYSTEM_DEBUG=ON" # special flag; don't set shared/static shared="" ;; openmp) use_openmp=" -DUSE_OPENMP=ON" # special flag; don't set shared/static shared="" ;; mpi | \ parallel) use_openmp=" -DUSE_MPI=ON" # special flag; don't set shared/static shared="" ;; debug) buildtype=" -DCMAKE_BUILD_TYPE=Debug" shared="" ;; pch) pch_use=" -DPRECOMPILE_HEADERS:BOOL=ON" shared="" ;; lto) use_lto=" -DWHOLE_PROG_OPTIM=ON" shared="" ;; tests) use_tests=" -DBUILD_TESTING=ON" pkgname="" ;; examples) use_samples=" -DBUILD_EXAMPLES=ON" pkgname="" ;; # this flag is just for compatibility with the deprecation # flag in DUNE, so we can build without warnings fieldvector-size-is-method) shared="" ;; shared) shared="ON" ;; static) shared="OFF" ;; *) invalid_opt --enable-${kind} shared="" ;; esac test -n "${shared}" && \ FEATURES="${FEATURES} -DBUILD_SHARED_LIBS:BOOL=${shared}" ;; *) # remove everything *after* the equal sign arg=${OPTARG%=*} invalid_arg --$arg exit 1 ;; esac ;; [A-Za-z0-9_]*=*) # collect for further processing later VARS+=("$OPT") ;; *) invalid_arg $OPT exit 1 ;; esac done # remove all arguments processed by getopts shift $((OPTIND-1)) # remove Autotools-specific variables. notice the usage of a quoted # array: each element will be returned even with spaces. for a in "${VARS[@]}"; do a="${a/ACLOCAL_*=*/}" [ -n "$a" ] && ENVVARS="$ENVVARS \"${a/\"/\\\"}\"" done # pass everything on to CMake CMDLINE="env ${ENVVARS} ${CMAKE_COMMAND} \"${srcdir}\" \"-DCMAKE_INSTALL_PREFIX=$prefix\"${buildtype}${pch_use}${silent_rules}${debug_loc}${use_openmp}${use_mpi}${use_lto}${use_tests}${use_samples} ${FEATURES}" echo --- calling CMake --- echo ${CMDLINE} eval exec ${CMDLINE}