2018-07-04 17:59:59 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
source $(dirname "$0")/Environment.sh
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- Parse arguments -----------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
DOC_STRING="Build LibCarla."
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
USAGE_STRING=$(cat <<- END
|
|
|
|
Usage: $0 [-h|--help]
|
|
|
|
|
|
|
|
Choose one or more build configurations
|
|
|
|
|
|
|
|
[--server] Build server-side configuration.
|
|
|
|
[--client] Build client-side configuration.
|
|
|
|
|
|
|
|
and choose one or more build options
|
|
|
|
|
|
|
|
[--debug] Build debug targets.
|
|
|
|
[--release] Build release targets.
|
|
|
|
|
|
|
|
Other commands
|
|
|
|
|
|
|
|
[--clean] Clean intermediate files.
|
|
|
|
[--rebuild] Clean and rebuild both configurations.
|
|
|
|
END
|
|
|
|
)
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
REMOVE_INTERMEDIATE=false
|
|
|
|
BUILD_SERVER=false
|
|
|
|
BUILD_CLIENT=false
|
2019-03-13 21:57:44 +08:00
|
|
|
BUILD_OPTION_DEBUG=false
|
|
|
|
BUILD_OPTION_RELEASE=false
|
|
|
|
BUILD_OPTION_DUMMY=false
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
OPTS=`getopt -o h --long help,rebuild,server,client,clean,debug,release -n 'parse-options' -- "$@"`
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
if [ $? != 0 ] ; then echo "$USAGE_STRING" ; exit 2 ; fi
|
|
|
|
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--rebuild )
|
|
|
|
REMOVE_INTERMEDIATE=true;
|
|
|
|
BUILD_SERVER=true;
|
|
|
|
BUILD_CLIENT=true;
|
2019-03-13 21:57:44 +08:00
|
|
|
BUILD_OPTION_DEBUG=true;
|
|
|
|
BUILD_OPTION_RELEASE=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
|
|
|
--server )
|
|
|
|
BUILD_SERVER=true;
|
|
|
|
shift ;;
|
|
|
|
--client )
|
|
|
|
BUILD_CLIENT=true;
|
|
|
|
shift ;;
|
|
|
|
--clean )
|
|
|
|
REMOVE_INTERMEDIATE=true;
|
2019-03-13 21:57:44 +08:00
|
|
|
BUILD_OPTION_DUMMY=true;
|
|
|
|
shift ;;
|
|
|
|
--debug )
|
|
|
|
BUILD_OPTION_DEBUG=true;
|
|
|
|
shift ;;
|
|
|
|
--release )
|
|
|
|
BUILD_OPTION_RELEASE=true;
|
2018-07-04 17:59:59 +08:00
|
|
|
shift ;;
|
|
|
|
-h | --help )
|
|
|
|
echo "$DOC_STRING"
|
|
|
|
echo "$USAGE_STRING"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! { ${REMOVE_INTERMEDIATE} || ${BUILD_SERVER} || ${BUILD_CLIENT}; }; then
|
|
|
|
fatal_error "Nothing selected to be done."
|
|
|
|
fi
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if ! { ${BUILD_OPTION_DUMMY} || ${BUILD_OPTION_DEBUG} || ${BUILD_OPTION_RELEASE} ; }; then
|
|
|
|
fatal_error "Choose --debug and/or --release."
|
|
|
|
fi
|
|
|
|
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
# -- Clean intermediate files --------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
if ${REMOVE_INTERMEDIATE} ; then
|
|
|
|
|
|
|
|
log "Cleaning intermediate files and folders."
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
rm -Rf ${LIBCARLA_BUILD_SERVER_FOLDER}* ${LIBCARLA_BUILD_CLIENT_FOLDER}*
|
2018-07-04 17:59:59 +08:00
|
|
|
rm -Rf ${LIBCARLA_INSTALL_SERVER_FOLDER} ${LIBCARLA_INSTALL_CLIENT_FOLDER}
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
2019-03-13 21:57:44 +08:00
|
|
|
# -- Define build function -----------------------------------------------------
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
# Build LibCarla for the given configuration.
|
|
|
|
#
|
|
|
|
# usage: build_libcarla {Server,Client} {Debug,Release}
|
|
|
|
#
|
|
|
|
function build_libcarla {
|
|
|
|
|
|
|
|
if [ $1 == Server ] ; then
|
|
|
|
M_TOOLCHAIN=${LIBCPP_TOOLCHAIN_FILE}
|
|
|
|
M_BUILD_FOLDER=${LIBCARLA_BUILD_SERVER_FOLDER}.$(echo "$2" | tr '[:upper:]' '[:lower:]')
|
|
|
|
M_INSTALL_FOLDER=${LIBCARLA_INSTALL_SERVER_FOLDER}
|
|
|
|
elif [ $1 == Client ] ; then
|
|
|
|
M_TOOLCHAIN=${LIBSTDCPP_TOOLCHAIN_FILE}
|
|
|
|
M_BUILD_FOLDER=${LIBCARLA_BUILD_CLIENT_FOLDER}.$(echo "$2" | tr '[:upper:]' '[:lower:]')
|
|
|
|
M_INSTALL_FOLDER=${LIBCARLA_INSTALL_CLIENT_FOLDER}
|
|
|
|
else
|
|
|
|
fatal_error "Invalid build configuration \"$1\""
|
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if [ $2 == Debug ] ; then
|
|
|
|
M_DEBUG=ON
|
|
|
|
M_RELEASE=OFF
|
|
|
|
elif [ $2 == Release ] ; then
|
|
|
|
M_DEBUG=OFF
|
|
|
|
M_RELEASE=ON
|
|
|
|
else
|
|
|
|
fatal_error "Invalid build option \"$2\""
|
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
log "Building LibCarla \"$1.$2\" configuration."
|
|
|
|
|
|
|
|
mkdir -p ${M_BUILD_FOLDER}
|
|
|
|
pushd "${M_BUILD_FOLDER}" >/dev/null
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
if [ ! -f "build.ninja" ]; then
|
|
|
|
|
|
|
|
cmake \
|
|
|
|
-G "Ninja" \
|
2019-03-13 21:57:44 +08:00
|
|
|
-DCMAKE_BUILD_TYPE=$1 \
|
|
|
|
-DLIBCARLA_BUILD_DEBUG=${M_DEBUG} \
|
|
|
|
-DLIBCARLA_BUILD_RELEASE=${M_RELEASE} \
|
|
|
|
-DCMAKE_TOOLCHAIN_FILE=${M_TOOLCHAIN} \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=${M_INSTALL_FOLDER} \
|
2018-07-19 18:43:21 +08:00
|
|
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
|
2018-07-04 17:59:59 +08:00
|
|
|
${CARLA_ROOT_FOLDER}
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
ninja
|
|
|
|
|
|
|
|
ninja install | grep -v "Up-to-date:"
|
|
|
|
|
|
|
|
popd >/dev/null
|
2019-03-13 21:57:44 +08:00
|
|
|
}
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
# ==============================================================================
|
2019-03-13 21:57:44 +08:00
|
|
|
# -- Build all possible configurations -----------------------------------------
|
2018-07-04 17:59:59 +08:00
|
|
|
# ==============================================================================
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if { ${BUILD_SERVER} && ${BUILD_OPTION_DEBUG}; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
build_libcarla Server Debug
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if { ${BUILD_SERVER} && ${BUILD_OPTION_RELEASE}; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
build_libcarla Server Release
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if { ${BUILD_CLIENT} && ${BUILD_OPTION_DEBUG}; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
build_libcarla Client Debug
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if { ${BUILD_CLIENT} && ${BUILD_OPTION_RELEASE}; }; then
|
|
|
|
|
|
|
|
build_libcarla Client Release
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- ...and we are done --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
log "Success!"
|