Move all-cmake-build files to a single build.sh script

parent 8e5169dd
...@@ -24,7 +24,7 @@ if (NOT CMAKE_BUILD_TYPE) ...@@ -24,7 +24,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif () endif ()
if (NOT CMAKE_BUILD_TYPE MATCHES "(Release|Debug)") if (NOT CMAKE_BUILD_TYPE MATCHES "(Release|Debug)")
message(FATAL_ERROR "Unsupported build type") message(FATAL_ERROR "Unsupported build type (${{CMAKE_BUILD_TYPE}})")
endif() endif()
if(DEFINED ENV{{CMAKE_BUILD_PARALLEL_LEVEL}}) if(DEFINED ENV{{CMAKE_BUILD_PARALLEL_LEVEL}})
......
#!/usr/bin/env bash
THREADS=${1:-5}
BUILD_DIR=${2:-"debug"}
source $(dirname $0)/all-cmake-template.sh
build "$BUILD_DIR" "Debug" "$THREADS" "$(dirname $0)"
#!/usr/bin/env bash
THREADS=${1:-5}
BUILD_DIR=${2:-"release"}
source $(dirname $0)/all-cmake-template.sh
build "$BUILD_DIR" "Release" "$THREADS" "$(dirname $0)"
THREADS=${1:-5}
# $1 - release/build
# $2 - cmake build-type
# $3 - $THREADS
# $4 - root directory
function build () {
BUILD_DIR="$1"
THREADS="$3"
DIRECTORY=$(realpath "$4")
echo "------------------------------------------------------------------------------" 1>&2
echo "Building '$DIRECTORY' in $2 mode: Build dir is '$BUILD_DIR', threads: $THREADS" 1>&2
echo "------------------------------------------------------------------------------" 1>&2
./CMake/generate.py -wm || exit 1
if [ ! -d "$BUILD_DIR" ] && [ ! -L "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
if [ -L "${BUILD_DIR}" ]; then
LINK=$(readlink "${BUILD_DIR}")
if [ ! -d ${LINK} ]; then
mkdir ${LINK}
fi
cd ${LINK}
cmake -DCMAKE_BUILD_TYPE=$2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ${DIRECTORY}
cd ${DIRECTORY}/${BUILD_DIR}
else
cd "${BUILD_DIR}"
cmake -DCMAKE_BUILD_TYPE=$2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
fi
make -j${THREADS} || exit 1
make test ARGS="-j${THREADS} --output-on-failure" || exit 1
}
extra/scripts/build.sh
\ No newline at end of file
#!/bin/bash
BUILD_THREADS="$(grep -c processor /proc/cpuinfo)"
BUILD_DIR=
BUILD_MODE=
BUILD_SYSTEM=
is_installed() {
FOUND=0
for dep in "$@"; do
if command -v "$dep" >/dev/null 2>/dev/null; then
FOUND=1
break
fi
done
if [[ $FOUND -eq 0 ]]; then
echo "Could not find (at least one of) the following dependencies: $@" >&2
return 1
else
return 0
fi
}
installed_or_exit() {
if ! is_installed "$@"; then
exit 1
fi
}
get_buildsystem() {
is_installed "ninja" && { echo "ninja"; return 0; }
is_installed "make" && { echo "make"; return 0; }
}
usage_and_exit() {
cat >&2 << EOF
Usage: $0 -d DIRECTORY -m MODE [-j THREADS]
$0 debug [-j THREADS] ( shortcut for => $0 -d debug -m Debug [-j THREADS] )
$0 release [-j THREADS] ( shortcut for => $0 -d release -m Release [-j THREADS] )
Algorithms Library Core builder helper script.
Arguments:
-d DIRECTORY Build directory (relative to ALT root)
-m MODE 'Release' or 'Debug'
-j THREADS Number of build threads. Default: Number of CPU cores ($(grep -c processor /proc/cpuinfo))
EOF
exit 1
}
installed_or_exit "python3"
installed_or_exit "cmake"
installed_or_exit "make" "ninja"
# check if shortcut
ARGS_SHORTCUT=
if [[ $# -ge 1 ]] && [[ $1 == "release" || $1 == "debug" ]]; then
ARGS_SHORTCUT=1
if [[ $1 == "release" ]]; then
BUILD_DIR="release"
BUILD_MODE="Release"
elif [[ $1 == "debug" ]]; then
BUILD_DIR="debug"
BUILD_MODE="Debug"
fi
shift
fi
while getopts "d:m:j:" arg; do
case "$arg" in
d)
[[ ! -z $ARGS_SHORTCUT ]] && usage_and_exit
BUILD_DIR=${OPTARG}
;;
m)
[[ ! -z $ARGS_SHORTCUT ]] && usage_and_exit
TMP=$(echo "$OPTARG" | tr '[:upper:]' '[:lower:]')
if [[ "$TMP" == "debug" ]]; then
BUILD_MODE="Debug"
elif [[ "$TMP" == "release" ]]; then
BUILD_MODE="Release"
else
usage_and_exit
fi
;;
j)
if [[ "${OPTARG}" =~ ^[1-9][0-9]* ]]; then
BUILD_THREADS="${OPTARG}"
else
usage_and_exit
fi
;;
?)
usage_and_exit
;;
esac
done
if [[ -z $BUILD_DIR || -z $BUILD_MODE ]]; then
usage_and_exit
fi
BUILD_SYSTEM=$(get_buildsystem)
[[ -L $0 ]] && SCRIPT_PATH=$(readlink $0) || SCRIPT_PATH="$0"
ROOT=$(realpath $(dirname $SCRIPT_PATH)/../..)
cd $ROOT
# show what will be done:
BUILD_DIR_SYMLINK=$([[ -L $BUILD_DIR ]] && echo "-> $(realpath $(readlink ${BUILD_DIR}))" || echo "")
cat >&2 << EOF
------------------------------------------------------------------------------
Building Algorithms Library Core from $ROOT:
- Mode: $BUILD_MODE
- Into: $ROOT/$BUILD_DIR $BUILD_DIR_SYMLINK
- Threads: $BUILD_THREADS
- Builder: $BUILD_SYSTEM
------------------------------------------------------------------------------
EOF
# generate cmakefiles
./CMake/generate.py -wm || exit 1
# create build dir if nonexistent
if [ ! -d "$BUILD_DIR" ] && [ ! -L "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
# if build_dir is a link...
if [ -L "${BUILD_DIR}" ]; then
LINK=$(readlink "${BUILD_DIR}")
if [ ! -d ${LINK} ]; then
mkdir -p ${LINK}
fi
cd ${LINK}
else
cd "${ROOT}/${BUILD_DIR}"
fi
CMAKE_FLAGS="-DCMAKE_BUILD_TYPE=$BUILD_MODE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
if [[ $BUILD_SYSTEM == "ninja" ]]; then
CMAKE_FLAGS="$CMAKE_FLAGS -GNinja"
fi
cmake $CMAKE_FLAGS ${ROOT}
# build and test
if [[ $BUILD_SYSTEM == "ninja" ]]; then
ninja -j${BUILD_THREADS} || exit 1
ctest . --output-on-failure -j ${BUILD_THREADS} || exit 1
else
make -j${BUILD_THREADS} || exit 1
make test ARGS="-j${BUILD_THREADS} --output-on-failure" || exit 1
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment