#!/bin/sh # This script is based on "Autotools-style wrapper for CMake", # Modifications made: # 1. configuration parameters specific for C++ toolkit and Gpipe # 2. --without- arguments support # 3. custom root directory # etc # Autotools-style (./configure) wrapper for CMake # # # *** IMPORTANT *** # # You must include the GNUInstallDirs module (which comes with # CMake) in your project. Just put "include (GNUInstallDirs)" in # you CMakeLists.txt and you should be good. # # This script was originally written for Squash # by Evan Nemerson # , but has been spun off into a separate # repository. Please feel free to copy it into your own repository, # though I would appreciate it if you would post improvements, bugs, # feature requests, etc. to the issue tracker at # . # # To the extent possible under law, the author(s) hereby waive all # copyright and related or neighboring rights to this work. For # details, see TOP_SRCDIR="$(dirname $0)" if [ "${CMAKE_CMD}" = "" ]; then CMAKE_CMD="cmake" fi if [ -z "$CC" ]; then CC=`which gcc` fi if [ -z "$CXX" ]; then CXX=`which g++` fi BUILD_TYPE="Debug" BUILD_SHARED_LIBS= # NOTE: By default, not set and neither ON nor OFF! PREFIX=/usr/local LIBDIR= CMAKE_ARGS= #CMAKE_ARGS=-DNCBI_EXPERIMENTAL=ON if [ -e "${TOP_SRCDIR}/configure-custom.sh" ]; then . "${TOP_SRCDIR}/configure-custom.sh" fi quote() { echo "$1" | sed -e "s|'|'\\\\''|g; 1s/^/'/; \$s/\$/'/" } extract_var_string() { VAR_NAME=$1 VAR_NAME=$(echo $1 | sed -e 's/[ \t]*$//') if [ "x$2" != "x" ]; then VAR_VALUE=$2 else VAR_VALUE=yes fi if [ "x$3" != "x" ]; then VAR_UC_NAME=$3 else VAR_UC_NAME=$(echo "$1" | tr '[:lower:]' '[:upper:]' | tr -c '[:alnum:]' '_' | sed 's/_$//g') fi } set_config_var() { is_with=n case "$1" in "--enable-"*) name="${1#--enable-}" cfg="${ENABLE_VARS}" ;; "--disable-"*) name="${1#--disable-}"; cfg="${DISABLE_VARS}"; ;; "--with-"*) # IFS="=" read -ra WITHARGS <<< "${1}" name="${1#--with-}" cfg="${WITH_VARS}" is_with=y ;; "--without-"*) # IFS="=" read -ra WITHARGS <<< "${1}" name="${1#--without-}" cfg="${WITH_VARS}" is_without=y ;; esac found=n for varstring in $cfg; do extract_var_string $(echo "${varstring}" | tr '|' ' ') if [ "x$VAR_NAME" = "x$name" ]; then found=y break; fi done if [ "$found" = "y" ]; then if [ "x$is_without" = "xy" ]; then CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}_DISABLED=yes" elif [ "x$is_with" = "xy" ]; then CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "$2")" else CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "${VAR_VALUE}")" fi else echo "Unknown parameter: ${1}" exit 1 fi } prefix_to_offset() { expr $(echo "${1}" | awk '{ print length }') + 1 } print_help() { cat < \"" ;; "--enable-"*) set_config_var "$1" ;; "--disable-"*) set_config_var "$1" ;; "--with-"*) name=$(echo "${1#--with-}" | awk '{split($1,v,"="); print v[1]}') case "${1}" in "--with-${name}="*) set_config_var "--with-${name}" "${1#--with-${name}=}";; "--with-${name}") set_config_var "$1" "$2"; shift;; esac ;; "--without-"*) set_config_var "$1" ;; *) echo "$0: error: unrecognized option: \`$1'" >&2 echo "Try \`$0 --help' for more information" >&2 exit -1 esac; shift done if [ "x${LIBDIR}" = "x" ]; then LIBDIR="${PREFIX}/lib" fi CMAKE_ARGS="$CMAKE_ARGS $DISTCC_OPTS" # Unlike CFLAGS/CXXFLAGS/CC/CXX, LDFLAGS isn't handled by CMake, so we # need to parse it here. if [ "x${LDFLAGS}" != "x" ]; then for varname in EXE MODULE SHARED; do CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_${varname}_LINKER_FLAGS=$(quote "$LDFLAGS")" done fi if [ -z "$ROOT" ]; then if [ -z "$GPIPEROOT" ]; then ROOT="CMake-$BUILD_TYPE" case "$BUILD_SHARED_LIBS" in ON) ROOT="$ROOT"DLL ;; OFF) ROOT="$ROOT"Static ;; esac else ROOT=`cd "${TOP_SRCDIR}/../../../" && /bin/pwd` || exit 1 ROOT=`/usr/bin/dirname "$ROOT"` || exit 1 ROOT=$ROOT/$GPIPEROOT fi fi if [ ! -z "$MAX_DEBUG" ]; then CXXFLAGS="${CXXFLAGS:-}${CXXFLAGS:+ }-D_GLIBCXX_DEBUG" fi if [ ! -z "$EXPERIMENTAL" ]; then for x in `echo $EXPERIMENTAL | tr , ' '`; do case "$x" in ChaosMonkey ) CPPFLAGS="$CPPFLAGS -DNCBI_MONKEY" ;; Int8GI ) CPPFLAGS="$CPPFLAGS -DNCBI_INT8_GI" NCBI_C_PATH_TAGS="/ncbi.gi64 .gi64" ;; StrictGI ) CPPFLAGS="$CPPFLAGS -DNCBI_STRICT_GI" NCBI_C_PATH_TAGS="/ncbi.gi64 .gi64" ;; * ) echo "cmake-configure: error: unrecognized experimental feature \"$x\"." >&2 exit 1;; esac done fi CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=$(quote "$CXX")" CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "$CC")" CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_FLAGS=$(quote "$CFLAGS")" CXXFLAGS="${CXXFLAGS:-}${CXXFLAGS:+ }${CPPFLAGS:-}${CPPFLAGS:+ }" CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_FLAGS=$(quote "$CXXFLAGS")" mkdir -p $ROOT/build ROOT_SOURCE_PATH=`pwd` cd $ROOT/build #we need to do this because CMake caches configuration parameters, and if you run ./cmake-configure for existing build directory #but with another parameters, CMake will use old values for paramers you omit (not default ones) if [ -e CMakeCache.txt ]; then rm CMakeCache.txt fi eval "${CMAKE_CMD}" ${TRACE_CMAKE} ${NINJA_FLAGS} "${TOP_SRCDIR}/../../" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_INSTALL_LIBDIR="${LIBDIR}" ${CMAKE_ARGS}