2019-02-14 10:30:42 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -o errexit -o pipefail -o noclobber -o nounset
|
|
|
|
|
|
|
|
# Test if getopt exists
|
|
|
|
command -v getopt >/dev/null 2>&1 || { echo "can't execute getopt"; exit 1; }
|
|
|
|
|
|
|
|
# Test if getopt works
|
|
|
|
! getopt --test 2> /dev/null
|
|
|
|
[[ ${PIPESTATUS[0]} -ne 4 ]] && { exit 2; }
|
|
|
|
|
|
|
|
# List of available options
|
|
|
|
OPTIONS=g:t:qcfs:b:o:
|
|
|
|
LONGOPTS=generator:,type:,qtcreator,cmake,force,source-dir:,build-dir:,output-dir:
|
|
|
|
|
|
|
|
# Parse options
|
|
|
|
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
|
|
|
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit 3
|
|
|
|
|
|
|
|
# Read getopt's output to handle the quoting right
|
|
|
|
eval set -- "$PARSED"
|
|
|
|
|
|
|
|
# Default generator
|
2019-03-14 08:14:57 +00:00
|
|
|
[ -x "$(command -v make)" ] && GENERATOR="Unix Makefiles"
|
|
|
|
[ -x "$(command -v ninja)" ] && GENERATOR=Ninja
|
2019-02-14 10:30:42 +00:00
|
|
|
|
2019-05-21 07:48:00 +00:00
|
|
|
# Build types list separated with comma
|
|
|
|
TYPES="Release"
|
2019-02-14 10:30:42 +00:00
|
|
|
|
|
|
|
# Force destructive actions
|
|
|
|
FORCE="n"
|
|
|
|
|
|
|
|
# Default source directory is two levels upper
|
|
|
|
SOURCE_DIR="$(dirname -- "$(dirname -- "$(pwd)")")"
|
|
|
|
|
|
|
|
# Default build directory is _build
|
|
|
|
BUILD_DIR="${SOURCE_DIR}/_build"
|
|
|
|
|
|
|
|
# Default output directory is _output
|
|
|
|
OUTPUT_DIR="${SOURCE_DIR}/_output"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-g|--generator)
|
|
|
|
GENERATOR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2019-05-21 07:48:00 +00:00
|
|
|
-t|--types)
|
|
|
|
TYPES="$2"
|
2019-02-14 10:30:42 +00:00
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-f|--force)
|
|
|
|
FORCE="y"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-s|--source-dir)
|
|
|
|
SOURCE_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-b|--build-dir)
|
|
|
|
BUILD_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-o|--output-dir)
|
|
|
|
OUTPUT_DIR="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
2019-05-21 07:48:00 +00:00
|
|
|
echo "Wrong argument is set"
|
2019-02-14 10:30:42 +00:00
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-03-14 08:14:57 +00:00
|
|
|
if [ "x${GENERATOR}" = "x" ]; then
|
|
|
|
echo "Build command is not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-13 16:51:01 +00:00
|
|
|
CMAKE_ARGS=""
|
2019-08-12 11:40:14 +00:00
|
|
|
[ ${#@} -gt 0 ] && CMAKE_ARGS=${@}
|
2019-02-14 10:30:42 +00:00
|
|
|
|
|
|
|
[ ! -f "${SOURCE_DIR}/CMakeLists.txt" ] && { echo "Source directory does not contain CMakeLists.txt"; exit 4; }
|
|
|
|
|
2020-03-25 07:23:32 +00:00
|
|
|
if grep -i ^"project.*fortran" "${SOURCE_DIR}/CMakeLists.txt" >/dev/null 2>&1 ; then
|
|
|
|
if [ -x "$(command -v make)" ]; then
|
|
|
|
GENERATOR="Unix Makefiles"
|
|
|
|
else
|
|
|
|
echo "Projects with Fortran sources need Make to build"
|
|
|
|
exit 5
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-02-14 10:30:42 +00:00
|
|
|
export GENERATOR
|
|
|
|
export SOURCE_DIR
|
|
|
|
export BUILD_DIR
|
|
|
|
export OUTPUT_DIR
|
|
|
|
export CMAKE_ARGS
|
2019-02-19 08:19:38 +00:00
|
|
|
export FORCE
|
2019-02-14 10:30:42 +00:00
|
|
|
|
|
|
|
generate_configuration() {
|
|
|
|
local BUILD_TYPE="${!#}"
|
|
|
|
local BUILD="$BUILD_TYPE"
|
|
|
|
|
2019-05-21 07:48:00 +00:00
|
|
|
case "$BUILD_TYPE" in
|
|
|
|
qtNone)
|
|
|
|
BUILD="unknown"
|
|
|
|
BUILD_TYPE="None"
|
|
|
|
;;
|
|
|
|
qtDebug)
|
|
|
|
BUILD="debug"
|
|
|
|
BUILD_TYPE="Debug"
|
|
|
|
;;
|
|
|
|
qtRelease)
|
|
|
|
BUILD="release"
|
|
|
|
BUILD_TYPE="Release"
|
|
|
|
;;
|
|
|
|
qtProfile)
|
|
|
|
BUILD="profile"
|
|
|
|
BUILD_TYPE="Profile"
|
|
|
|
;;
|
|
|
|
esac
|
2019-02-14 10:30:42 +00:00
|
|
|
|
2019-05-21 07:48:00 +00:00
|
|
|
GEN_DIR="${BUILD_DIR}/${BUILD}"
|
2019-02-19 08:19:38 +00:00
|
|
|
|
|
|
|
if [ -d "${GEN_DIR}" ]; then
|
|
|
|
if [ "x${FORCE}" == "xy" ]; then
|
|
|
|
rm -rf "${GEN_DIR}"
|
|
|
|
else
|
|
|
|
echo "Build directory '${GEN_DIR}' already exists. Use --force to remove this directory or do it manually"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-11-27 13:18:37 +00:00
|
|
|
cmake -B"${GEN_DIR}" -H"${SOURCE_DIR}" -G "${GENERATOR}" -DCMAKE_INSTALL_PREFIX="${OUTPUT_DIR}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${CMAKE_ARGS}
|
2019-02-14 10:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export -f generate_configuration
|
2019-05-21 07:48:00 +00:00
|
|
|
set -f
|
2019-02-14 10:30:42 +00:00
|
|
|
|
2019-05-21 07:48:00 +00:00
|
|
|
BUILD_TYPES=(${TYPES//,/ })
|
2019-02-14 10:30:42 +00:00
|
|
|
|
2019-05-21 07:48:00 +00:00
|
|
|
for i in "${!BUILD_TYPES[@]}"; do
|
|
|
|
case ${BUILD_TYPES[i]} in
|
|
|
|
None|Debug|Release|Profile|RelWithDebInfo|MinSizeRel|qtNone|qtDebug|qtRelease|qtProfile)
|
|
|
|
true
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Wrong CMake build type. Possible value are:"
|
|
|
|
echo "None,Debug,Release,Profile,RelWithDebInfo,MinSizeRel,qtNone,qtDebug,qtRelease,qtProfile"
|
|
|
|
exit 6
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2019-02-14 10:30:42 +00:00
|
|
|
|
|
|
|
# Try to work in parallel
|
|
|
|
if [ -x "$(command -v parallel)" ]; then
|
|
|
|
PV=$(parallel --version | head -n 1 | awk '{ print $3; }')
|
|
|
|
if [ "$PV" -lt "20131121" ]; then
|
2019-02-19 08:25:25 +00:00
|
|
|
parallel --delay 2 -r generate_configuration ::: "${BUILD_TYPES[@]}"
|
2019-02-14 10:30:42 +00:00
|
|
|
elif [ "$PV" -lt "20141023" ]; then
|
2019-02-19 08:25:25 +00:00
|
|
|
parallel --delay 2 -r --no-notice generate_configuration ::: "${BUILD_TYPES[@]}"
|
2019-02-14 10:30:42 +00:00
|
|
|
else
|
2019-02-19 08:25:25 +00:00
|
|
|
parallel --delay 2 -r --will-cite generate_configuration ::: "${BUILD_TYPES[@]}"
|
2019-02-14 10:30:42 +00:00
|
|
|
fi
|
|
|
|
else
|
2019-02-14 11:33:44 +00:00
|
|
|
for T in "${BUILD_TYPES[@]}"; do generate_configuration "${T}"; done
|
2019-02-14 10:30:42 +00:00
|
|
|
fi
|
|
|
|
|