compile_cmake() { local olddir="$PWD" local builddir='build' local generator='' local noinstall=false local OPTIND=1 local opt while getopts 'b:g:I' opt; do case "$opt" in b) local builddir="$OPTARG" ;; g) local generator="$OPTARG" ;; I) local noinstall=true ;; esac; done shift $(expr $OPTIND - 1) [ "$#" -ge 1 ] && [ "$1" = '--' ] && shift || true if [ ! "$generator" ]; then local generator='Unix Makefiles' if command -v ninja > /dev/null 2> /dev/null; then local generator='Ninja' fi fi case "$generator" in 'Unix Makefiles') local make='make' ;; 'Ninja') local make="ninja $NINJAFLAGS" ;; *) local make='make' ;; esac # https://github.com/Kitware/CMake/blob/master/Modules/GNUInstallDirs.cmake mkdir -p "$builddir"; cd "$builddir" cmake "$olddir" -G "$generator" \ -DCMAKE_AR="$(command -v ${AR:-ar})" \ -DCMAKE_NM="$(command -v ${NM:-nm})" \ -DCMAKE_RANLIB="$(command -v ${RANLIB:-ranlib})" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX="/$dir_prefix" \ -DCMAKE_INSTALL_BINDIR="/$dir_prefix/$dir_bin" \ -DCMAKE_INSTALL_SBINDIR="/$dir_prefix/$dir_sbin" \ -DCMAKE_INSTALL_LIBEXECDIR="/$dir_prefix/$dir_libexec" \ -DCMAKE_INSTALL_SYSCONFDIR="/$dir_prefix/$dir_sysconf" \ -DCMAKE_INSTALL_LOCALSTATEDIR="/$dir_prefix/$dir_localstate" \ -DCMAKE_INSTALL_LIBDIR="/$dir_prefix/$dir_lib" \ -DCMAKE_INSTALL_INCLUDEDIR="/$dir_prefix/$dir_include" \ -DCMAKE_INSTALL_DATADIR="/$dir_prefix/$dir_data" \ -DCMAKE_INSTALL_INFODIR="/$dir_prefix/$dir_info" \ -DCMAKE_INSTALL_LOCALEDIR="/$dir_prefix/$dir_locale" \ -DCMAKE_INSTALL_MANDIR="/$dir_prefix/$dir_man" \ -DCMAKE_INSTALL_DOCDIR="/$dir_prefix/$dir_doc/$name" \ "$@" $make if [ "$noinstall" = false ]; then DESTDIR="$dir_install" $make install fi cd "$olddir" }