2018-07-04 17:59:59 +08:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- 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
|
2019-06-03 19:01:53 +08:00
|
|
|
BUILD_RSS_VARIANT=false
|
2022-09-23 21:39:09 +08:00
|
|
|
USE_PYTORCH=false
|
2023-11-06 19:34:07 +08:00
|
|
|
USE_ROS2=false
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2023-11-06 19:34:07 +08:00
|
|
|
OPTS=`getopt -o h --long help,rebuild,server,client,clean,debug,release,rss,pytorch,carsim,ros2 -n 'parse-options' -- "$@"`
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
eval set -- "$OPTS"
|
|
|
|
|
2020-10-01 22:35:12 +08:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2018-07-04 17:59:59 +08:00
|
|
|
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 ;;
|
2022-09-23 21:39:09 +08:00
|
|
|
--pytorch )
|
|
|
|
USE_PYTORCH=true;
|
|
|
|
shift ;;
|
2023-11-06 19:34:07 +08:00
|
|
|
--ros2 )
|
|
|
|
USE_ROS2=true;
|
|
|
|
shift ;;
|
2019-06-03 19:01:53 +08:00
|
|
|
--rss )
|
|
|
|
BUILD_RSS_VARIANT=true;
|
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
-h | --help )
|
|
|
|
echo "$DOC_STRING"
|
|
|
|
echo "$USAGE_STRING"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
* )
|
2020-09-30 22:57:53 +08:00
|
|
|
shift ;;
|
2018-07-04 17:59:59 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-12-17 17:53:03 +08:00
|
|
|
source $(dirname "$0")/Environment.sh
|
|
|
|
|
|
|
|
function get_source_code_checksum {
|
|
|
|
local EXCLUDE='*__pycache__*'
|
|
|
|
find "${LIBCARLA_ROOT_FOLDER}"/* \! -path "${EXCLUDE}" -print0 | sha1sum | awk '{print $1}'
|
|
|
|
}
|
|
|
|
|
2018-07-04 17:59:59 +08:00
|
|
|
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}*
|
2022-09-23 21:39:09 +08:00
|
|
|
rm -Rf ${LIBCARLA_BUILD_PYTORCH_FOLDER}* ${LIBCARLA_BUILD_PYTORCH_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.
|
|
|
|
#
|
2019-06-03 19:01:53 +08:00
|
|
|
# usage: build_libcarla {Server,Client,ClientRSS} {Debug,Release}
|
2019-03-13 21:57:44 +08:00
|
|
|
#
|
|
|
|
function build_libcarla {
|
|
|
|
|
2019-06-03 19:01:53 +08:00
|
|
|
CMAKE_EXTRA_OPTIONS=''
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
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}
|
2022-09-23 21:39:09 +08:00
|
|
|
elif [ $1 == Pytorch ] ; then
|
|
|
|
M_TOOLCHAIN=${LIBSTDCPP_TOOLCHAIN_FILE}
|
|
|
|
M_BUILD_FOLDER=${LIBCARLA_BUILD_PYTORCH_FOLDER}.$(echo "$2" | tr '[:upper:]' '[:lower:]')
|
|
|
|
M_INSTALL_FOLDER=${LIBCARLA_INSTALL_SERVER_FOLDER}
|
2023-11-06 19:34:07 +08:00
|
|
|
elif [ $1 == ros2 ] ; then
|
|
|
|
M_TOOLCHAIN=${LIBSTDCPP_TOOLCHAIN_FILE}
|
|
|
|
M_BUILD_FOLDER=${LIBCARLA_FASTDDS_FOLDER}.$(echo "$2" | tr '[:upper:]' '[:lower:]')
|
|
|
|
M_INSTALL_FOLDER=${LIBCARLA_INSTALL_SERVER_FOLDER}
|
2019-06-03 19:01:53 +08:00
|
|
|
elif [ $1 == ClientRSS ] ; then
|
|
|
|
BUILD_TYPE='Client'
|
|
|
|
M_TOOLCHAIN=${LIBSTDCPP_TOOLCHAIN_FILE}
|
|
|
|
M_BUILD_FOLDER=${LIBCARLA_BUILD_CLIENT_FOLDER}.rss.$(echo "$2" | tr '[:upper:]' '[:lower:]')
|
|
|
|
M_INSTALL_FOLDER=${LIBCARLA_INSTALL_CLIENT_FOLDER}
|
2023-11-16 23:03:58 +08:00
|
|
|
CMAKE_EXTRA_OPTIONS="${CMAKE_EXTRA_OPTIONS:+${CMAKE_EXTRA_OPTIONS} }-DBUILD_RSS_VARIANT=ON -DADRSS_INSTALL_DIR=${CARLA_BUILD_FOLDER}/ad-rss-4.4.4/install"
|
2019-03-13 21:57:44 +08:00
|
|
|
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
|
|
|
|
2020-02-25 03:16:29 +08:00
|
|
|
CHECKSUM_FILE=checksum.txt
|
|
|
|
|
|
|
|
if [ ! -f "${CHECKSUM_FILE}" ] ; then
|
|
|
|
NEEDS_CMAKE=true
|
|
|
|
elif [ "$(cat ${CHECKSUM_FILE})" != "$(get_source_code_checksum)" ] ; then
|
|
|
|
log "Re-running cmake, some files were added or removed."
|
|
|
|
NEEDS_CMAKE=true
|
|
|
|
else
|
|
|
|
NEEDS_CMAKE=false
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ${NEEDS_CMAKE} ; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
cmake \
|
2019-06-03 19:01:53 +08:00
|
|
|
-G "Eclipse CDT4 - Ninja" \
|
|
|
|
-DCMAKE_BUILD_TYPE=${BUILD_TYPE:-$1} \
|
2019-03-13 21:57:44 +08:00
|
|
|
-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 \
|
2019-06-03 19:01:53 +08:00
|
|
|
${CMAKE_EXTRA_OPTIONS} \
|
2018-07-04 17:59:59 +08:00
|
|
|
${CARLA_ROOT_FOLDER}
|
|
|
|
|
2020-02-25 03:16:29 +08:00
|
|
|
get_source_code_checksum > ${CHECKSUM_FILE}
|
|
|
|
|
2018-07-04 17:59:59 +08:00
|
|
|
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
|
2022-09-23 21:39:09 +08:00
|
|
|
if ${USE_PYTORCH} ; then
|
|
|
|
build_libcarla Pytorch Release
|
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2023-11-06 19:34:07 +08:00
|
|
|
if ${USE_ROS2} ; then
|
|
|
|
build_libcarla ros2 Release
|
|
|
|
fi
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
fi
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-06-03 19:01:53 +08:00
|
|
|
CLIENT_VARIANT='Client'
|
|
|
|
if [ $BUILD_RSS_VARIANT == true ] ; then
|
|
|
|
CLIENT_VARIANT='ClientRSS'
|
|
|
|
fi
|
|
|
|
|
2019-03-13 21:57:44 +08:00
|
|
|
if { ${BUILD_CLIENT} && ${BUILD_OPTION_DEBUG}; }; then
|
2018-07-04 17:59:59 +08:00
|
|
|
|
2019-06-03 19:01:53 +08:00
|
|
|
build_libcarla ${CLIENT_VARIANT} 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
|
|
|
|
|
2019-06-03 19:01:53 +08:00
|
|
|
build_libcarla ${CLIENT_VARIANT} Release
|
2018-07-04 17:59:59 +08:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ==============================================================================
|
|
|
|
# -- ...and we are done --------------------------------------------------------
|
|
|
|
# ==============================================================================
|
|
|
|
|
|
|
|
log "Success!"
|