Skip to content

Commit

Permalink
Allow building debug/release, default to release
Browse files Browse the repository at this point in the history
  • Loading branch information
saihv authored and madratman committed Jul 24, 2020
1 parent ba3ead3 commit 46daded
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
43 changes: 35 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd "$SCRIPT_DIR" >/dev/null

set -e
set -x

function version_less_than_equal_to() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; }
debug=false

# Parse command line arguments
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--gcc)
gccBuild=true
shift # past argument
;;
esac
case $key in
--debug)
debug=true
shift # past argument
;;
esac
done

# check for rpclib
if [ ! -d "./external/rpclib/rpclib-2.2.1" ]; then
Expand Down Expand Up @@ -53,13 +72,23 @@ if [[ -d "./cmake/CMakeFiles" ]]; then
rm -rf "./cmake/CMakeFiles"
fi

folder_name=""

if [[ ! -d $build_dir ]]; then
mkdir -p $build_dir
pushd $build_dir >/dev/null

"$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Debug \
|| (popd && rm -r $build_dir && exit 1)
popd >/dev/null
if $debug; then
folder_name="Debug"
"$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Debug \
|| (popd && rm -r $build_dir && exit 1)
popd >/dev/null
else
folder_name="Release"
"$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Release \
|| (popd && rm -r $build_dir && exit 1)
popd >/dev/null
fi
fi

pushd $build_dir >/dev/null
Expand All @@ -69,15 +98,15 @@ pushd $build_dir >/dev/null
make -j`nproc`
popd >/dev/null

mkdir -p AirLib/lib/x64/Debug
mkdir -p AirLib/lib/x64/$folder_name
mkdir -p AirLib/deps/rpclib/lib
mkdir -p AirLib/deps/MavLinkCom/lib
cp $build_dir/output/lib/libAirLib.a AirLib/lib
cp $build_dir/output/lib/libMavLinkCom.a AirLib/deps/MavLinkCom/lib
cp $build_dir/output/lib/librpc.a AirLib/deps/rpclib/lib/librpc.a

# Update AirLib/lib, AirLib/deps, Plugins folders with new binaries
rsync -a --delete $build_dir/output/lib/ AirLib/lib/x64/Debug
rsync -a --delete $build_dir/output/lib/ AirLib/lib/x64/$folder_name
rsync -a --delete external/rpclib/rpclib-2.2.1/include AirLib/deps/rpclib
rsync -a --delete MavLinkCom/include AirLib/deps/MavLinkCom
rsync -a --delete AirLib Unreal/Plugins/AirSim/Source
Expand All @@ -87,8 +116,6 @@ Unreal/Environments/Blocks/clean.sh
mkdir -p Unreal/Environments/Blocks/Plugins
rsync -a --delete Unreal/Plugins/AirSim Unreal/Environments/Blocks/Plugins

set +x

echo ""
echo ""
echo "=================================================================="
Expand Down
3 changes: 3 additions & 0 deletions cmake/cmake-modules/CommonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ macro(CommonSetup)

set(BUILD_PLATFORM "x64")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_CXX_FLAGS "-O3 ${CMAKE_CXX_FLAGS}")
endif ()

ELSE()
#windows cmake build is experimental
Expand Down

0 comments on commit 46daded

Please sign in to comment.