Skip to content

Commit

Permalink
[PZACXX-44] new build.sh and install_dependencies.sh scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wardru committed Oct 2, 2023
1 parent 4daf993 commit 354e95f
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 97 deletions.
173 changes: 76 additions & 97 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,110 +1,89 @@
#!/bin/bash

BUILD_DIR_LINUX="build"
BUILD_DIR_WINDOWS="buildwin"
BUILD_TYPE="Debug"
BUILD_EXAMPLES="False"
SHARED="True"
TARGET="Linux"
BUILD_DIR=$BUILD_DIR_LINUX
LIB_MODE="Shared"
BUILD_MODE="Debug"
PROJECT_ROOT_DIR="$(dirname "$(realpath "$0")")/.."
CONAN_PROFILES_DIR="$PROJECT_ROOT_DIR/conan_profiles"

function set_build_dir {
if [ "$TARGET" = "Windows" ]; then
BUILD_DIR=$BUILD_DIR_WINDOWS
fi
if [ "$SHARED" = "False" ]; then
BUILD_DIR="$BUILD_DIR-static"
fi
}

function install_deps {
echo "Installing dependencies for $TARGET..."
if [ "$TARGET" = "Windows" ]; then
EXTRA_CONAN_ARGS="-pr:h ../conan_profiles/x86_64_Cross_Windows"
else
EXTRA_CONAN_ARGS="-pr:h ../conan_profiles/x86_64_Linux"
fi
mkdir -p $BUILD_DIR
cd $BUILD_DIR
conan install .. -o shared=$SHARED -o build_examples=$BUILD_EXAMPLES -s build_type=$BUILD_TYPE --build=missing -pr:b ../conan_profiles/x86_64_Linux $EXTRA_CONAN_ARGS
}

function build {
echo "Building for $TARGET..."
cd $BUILD_DIR
conan build ..
}

function clean {
echo "Cleaning build directory for $TARGET"
set_build_dir
rm -rf $BUILD_DIR
}
TEMP=$(getopt -o t:l:b:h --long target:,lib:,build:,help -n "$0" -- "$@")
if [ $? != 0 ]; then
echo "Error processing arguments." >&2
exit 1
fi

function usage {
echo "Usage: $0 [-t <target>] [-r] [-s] [-d] [-e] [-c] [-h]"
echo " -t Target platform (Windows or Linux). Default is Linux"
echo " -r Build in Release mode. Default is Debug"
echo " -s Build in Static mode. Default is Shared"
echo " -d Install dependencies"
echo " -e Build examples"
echo " -c Clean build directory"
echo " -h Display this help message"
}
eval set -- "$TEMP"

# Parse command line arguments
while getopts "t:rscdebh" opt; do
case $opt in
t)
TARGET=$OPTARG
if [ "$TARGET" != "Windows" ] && [ "$TARGET" != "Linux" ]; then
echo "Invalid target: $TARGET" >&2
usage
exit 1
fi
;;
r)
BUILD_TYPE="Release"
;;
s)
SHARED="False"
;;
c)
CLEAN="True"
;;
d)
DEPS="True"
;;
e)
BUILD_EXAMPLES="True"
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
exit 1
;;
esac
while true; do
case "$1" in
-t|--target)
TARGET="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-l|--lib)
LIB_MODE="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-b|--build)
BUILD_MODE="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-h|--help)
echo "Usage: $0 [-t <target>] [-l <lib>] [-b <build>] [-h]"
echo " -t --target Target platform (Windows or Linux). Default is Linux"
echo " -l --lib Library mode (Static or Shared). Default is Shared"
echo " -b --build Build mode (Debug or Release). Default is Debug"
echo " -h --help Display this help message"
exit 0
;;
--)
shift
break
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

set_build_dir
if [ "$TARGET" == "Linux" ]; then
BUILD_DIR="build"
PROFILE_BUILD="x86_64_Linux"
PROFILE_HOST="x86_64_Linux"
elif [ "$TARGET" == "Windows" ]; then
BUILD_DIR="buildwin"
PROFILE_BUILD="x86_64_Linux"
PROFILE_HOST="x86_64_Cross_Windows"
else
echo "Target not supported: $TARGET"
exit 1
fi

if [ "$CLEAN" = "True" ]; then
clean
exit 0
if [ "$LIB_MODE" == "Static" ]; then
BUILD_DIR="${BUILD_DIR}_static"
elif [ "$LIB_MODE" == "Shared" ]; then
pass
else
echo "Library mode not supported: $LIB_MODE"
exit 1
fi

if [ "$DEPS" = "True" ]; then
install_deps
exit 0
FULL_BUILD_DIR="$PROJECT_ROOT_DIR/$BUILD_DIR"
FULL_PROFILE_BUILD="$CONAN_PROFILES_DIR/$PROFILE_BUILD"
FULL_PROFILE_HOST="$CONAN_PROFILES_DIR/$PROFILE_HOST"

echo "Configuration:"
echo " Target : $TARGET"
echo " Lib Mode : $LIB_MODE"
echo " Build Mode : $BUILD_MODE"

if [ ! -d "$FULL_BUILD_DIR" ]; then
echo "Build directory not found: $FULL_BUILD_DIR"
echo "Please run install_dependencies.sh first"
exit 1
fi

build
cd $FULL_BUILD_DIR
cmake -DCMAKE_TOOLCHAIN_FILE=./$BUILD_MODE/generators/pzacxx_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_MODE ..
cmake --build . --config $BUILD_MODE --parallel ${nproc}
85 changes: 85 additions & 0 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

TARGET="Linux"
LIB_MODE="Shared"
BUILD_MODE="Debug"
PROJECT_ROOT_DIR="$(dirname "$(realpath "$0")")/.."
CONAN_PROFILES_DIR="$PROJECT_ROOT_DIR/conan_profiles"

TEMP=$(getopt -o t:l:b:h --long target:,lib:,build:,help -n "$0" -- "$@")
if [ $? != 0 ]; then
echo "Error processing arguments." >&2
exit 1
fi

eval set -- "$TEMP"

while true; do
case "$1" in
-t|--target)
TARGET="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-l|--lib)
LIB_MODE="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-b|--build)
BUILD_MODE="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}"
shift 2
;;
-h|--help)
echo "Usage: $0 [-t <target>] [-l <lib>] [-b <build>] [-h]"
echo " -t --target Target platform (Windows or Linux). Default is Linux"
echo " -l --lib Library mode (Static or Shared). Default is Shared"
echo " -b --build Build mode (Debug or Release). Default is Debug"
echo " -h --help Display this help message"
exit 0
;;
--)
shift
break
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

if [ "$TARGET" == "Linux" ]; then
BUILD_DIR="build"
PROFILE_BUILD="x86_64_Linux"
PROFILE_HOST="x86_64_Linux"
elif [ "$TARGET" == "Windows" ]; then
BUILD_DIR="buildwin"
PROFILE_BUILD="x86_64_Linux"
PROFILE_HOST="x86_64_Cross_Windows"
else
echo "Target not supported: $TARGET"
exit 1
fi

if [ "$LIB_MODE" == "Static" ]; then
BUILD_DIR="${BUILD_DIR}_static"
fi

FULL_BUILD_DIR="$PROJECT_ROOT_DIR/$BUILD_DIR"
FULL_PROFILE_BUILD="$CONAN_PROFILES_DIR/$PROFILE_BUILD"
FULL_PROFILE_HOST="$CONAN_PROFILES_DIR/$PROFILE_HOST"

echo "Configuration:"
echo " Target : $TARGET"
echo " Lib Mode : $LIB_MODE"
echo " Build Mode : $BUILD_MODE"

mkdir -p $FULL_BUILD_DIR
cd $FULL_BUILD_DIR
conan install \
-s build_type=$BUILD_MODE \
-o shared=$( [ "$LIB_MODE" == "Shared" ] && echo "True" || echo "False" ) \
--build=missing \
--profile:b $FULL_PROFILE_BUILD \
--profile:h $FULL_PROFILE_HOST \
--install-folder=$FULL_BUILD_DIR \
$PROJECT_ROOT_DIR

0 comments on commit 354e95f

Please sign in to comment.