1- #! /bin/bash
1+ #! /usr/ bin/env bash
22print_usage () {
3- printf " bash $0 [-c ( for clean) ] [-i ( for install) ]\n"
3+ printf " bash $0 [-c < for clean> ] [-i < for install>] [-t <for torch>] [-p <for python>] [-d <workspace_dir> ]\n"
44}
55
6+ # Get directory of script
7+ # https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
8+ SOURCE=${BASH_SOURCE[0]}
9+ while [ -L " $SOURCE " ]; do # resolve $SOURCE until the file is no longer a symlink
10+ DIR=$( cd -P " $( dirname " $SOURCE " ) " > /dev/null 2>&1 && pwd )
11+ SOURCE=$( readlink " $SOURCE " )
12+ [[ $SOURCE != /* ]] && SOURCE=$DIR /$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
13+ done
14+ DIR=$( cd -P " $( dirname " $SOURCE " ) " > /dev/null 2>&1 && pwd )
15+
616WITH_TORCH=0
7- while getopts ' ictp' flag; do
17+ while getopts ' d: ictp' flag; do
818 case " ${flag} " in
919 i) INSTALL=true;;
1020 c) CLEAN=true;;
1121 t) WITH_TORCH=ON;;
1222 p) WITH_PYTHON=true;;
23+ d) WS_DIR=${OPTARG} ;;
1324 * ) print_usage
1425 exit 1 ;;
1526 esac
1627done
1728
18- BUILD_DIR=${COVERAGECONTROL_WS} /build
19- # INSTALL_DIR=${COVERAGECONTROL_WS}/install
29+ # if -d was given then set build_dir and install_dir to that
2030
31+ CMAKE_END_FLAGS=" -DCMAKE_BUILD_TYPE=Release"
2132if [[ ${WITH_TORCH} == " ON" ]]
2233then
23- CMAKE_END_FLAGS=" -DCMAKE_PREFIX_PATH=$Torch_DIR -DCMAKE_BUILD_TYPE=RelWithDebInfo"
34+ CMAKE_END_FLAGS=" ${CMAKE_END_FLAGS} -DCMAKE_PREFIX_PATH=${Torch_DIR} "
35+ fi
36+ if [[ ${WS_DIR} ]]
37+ then
38+ BUILD_DIR=${WS_DIR} /build/
39+ INSTALL_DIR=${WS_DIR} /install/CoverageControl/
40+ CMAKE_END_FLAGS=" ${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} "
2441else
25- CMAKE_END_FLAGS=" -DCMAKE_BUILD_TYPE=RelWithDebInfo"
42+ TMP_DIR=$( mktemp -d)
43+ BUILD_DIR=${TMP_DIR} /build
2644fi
2745
28- CleanBuild () {
29- rm -rf ${BUILD_DIR}
30- rm -rf ${INSTALL_DIR}
31- }
32-
3346InstallCoverageControlCore () {
34- cmake -S ${COVERAGECONTROL_WS} /src/CoverageControl/cppsrc /core -B ${BUILD_DIR} /CoverageControlCore ${CMAKE_END_FLAGS}
47+ cmake -S ${DIR} /core -B ${BUILD_DIR} /CoverageControlCore ${CMAKE_END_FLAGS}
3548 cmake --build ${BUILD_DIR} /CoverageControlCore -j$( nproc)
3649 if [ $? -ne 0 ]; then
3750 echo " CoverageControlCore build failed"
@@ -46,7 +59,7 @@ InstallCoverageControlCore () {
4659}
4760
4861InstallCoverageControlTorch () {
49- cmake -S ${COVERAGECONTROL_WS} /src/CoverageControl/cppsrc/ torch -B ${BUILD_DIR} /CoverageControlTorch ${CMAKE_END_FLAGS} -DCMAKE_PREFIX_PATH= ${Torch_DIR }
62+ cmake -S ${DIR} / torch -B ${BUILD_DIR} /CoverageControlTorch ${CMAKE_END_FLAGS}
5063 cmake --build ${BUILD_DIR} /CoverageControlTorch -j$( nproc)
5164 if [ $? -ne 0 ]; then
5265 echo " CoverageControlTorch build failed"
@@ -62,7 +75,7 @@ InstallCoverageControlTorch () {
6275}
6376
6477InstallCoverageControlTests () {
65- cmake -S ${COVERAGECONTROL_WS} /src/CoverageControl/cppsrc/ tests -B ${BUILD_DIR} /CoverageControlTests ${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX =${INSTALL_DIR }
78+ cmake -S ${DIR} / tests -B ${BUILD_DIR} /CoverageControlTests ${CMAKE_END_FLAGS} -DWITH_TORCH =${WITH_TORCH }
6679 cmake --build ${BUILD_DIR} /CoverageControlTests -j$( nproc)
6780 if [ $? -ne 0 ]; then
6881 echo " CoverageControlTests build failed"
@@ -78,7 +91,7 @@ InstallCoverageControlTests () {
7891}
7992
8093InstallCoverageControlMain () {
81- cmake -S ${COVERAGECONTROL_WS} /src/CoverageControl/cppsrc/ main -B ${BUILD_DIR} /CoverageControlMain ${CMAKE_END_FLAGS} -DCMAKE_INSTALL_PREFIX= ${INSTALL_DIR } -DWITH_TORCH=${WITH_TORCH}
94+ cmake -S ${DIR} / main -B ${BUILD_DIR} /CoverageControlMain ${CMAKE_END_FLAGS} -DWITH_TORCH=${WITH_TORCH}
8295 cmake --build ${BUILD_DIR} /CoverageControlMain -j$( nproc)
8396 if [ $? -ne 0 ]; then
8497 echo " CoverageControlMain build failed"
98111 if [[ ${WITH_TORCH} == " ON" ]]
99112 then
100113 InstallCoverageControlTorch
114+ InstallCoverageControlTests
101115 fi
102116 InstallCoverageControlMain
103- InstallCoverageControlTests
104117fi
105118
106119if [[ ${CLEAN} ]]
0 commit comments