2019-08-09 19:02:42 +03:00
#!/usr/bin/env bash
2022-01-19 01:07:49 +03:00
# Copyright (C) 2018-2022 Intel Corporation
2021-03-27 01:26:27 +03:00
# SPDX-License-Identifier: Apache-2.0
2019-08-09 19:02:42 +03:00
2021-11-08 14:15:30 +03:00
usage( ) {
2022-03-24 22:27:29 +03:00
echo "Build OpenVINO Runtime samples"
2021-11-08 14:15:30 +03:00
echo
echo "Options:"
echo " -h Print the help message"
echo " -b SAMPLE_BUILD_DIR Specify the sample build directory"
echo " -i SAMPLE_INSTALL_DIR Specify the sample install directory"
echo
exit 1
}
2022-10-20 10:01:55 +02:00
samples_type = " $( basename " $( dirname " $( realpath " ${ BASH_SOURCE [0] } " ) " ) " ) "
2022-08-17 12:46:07 +04:00
build_dir = " $HOME /openvino_ ${ samples_type } _samples_build "
2021-11-08 14:15:30 +03:00
sample_install_dir = ""
# parse command line options
while [ [ $# -gt 0 ] ]
do
case " $1 " in
-b | --build_dir)
build_dir = " $2 "
shift
; ;
-i | --install_dir)
sample_install_dir = " $2 "
shift
; ;
-h | --help)
usage
; ;
*)
echo " Unrecognized option specified $1 "
usage
; ;
esac
shift
done
2019-08-09 19:02:42 +03:00
error( ) {
local code = " ${ 3 :- 1 } "
if [ [ -n " $2 " ] ] ; then
echo " Error on or near line $1 : $2 ; exiting with status ${ code } "
else
echo " Error on or near line $1 ; exiting with status ${ code } "
fi
exit " ${ code } "
}
trap 'error ${LINENO}' ERR
2022-10-20 10:01:55 +02:00
SAMPLES_PATH = " $( cd " $( dirname " $( realpath " ${ BASH_SOURCE [0] } " ) " ) " && pwd ) "
2019-08-09 19:02:42 +03:00
printf "\nSetting environment variables for building samples...\n"
if [ -z " $INTEL_OPENVINO_DIR " ] ; then
2022-07-26 23:17:41 +04:00
if [ [ " $SAMPLES_PATH " = "/usr/share/openvino" * ] ] ; then
true
elif [ -e " $SAMPLES_PATH /../../setupvars.sh " ] ; then
2021-09-15 16:49:11 +03:00
setvars_path = " $SAMPLES_PATH /../../setupvars.sh "
2022-07-26 23:17:41 +04:00
source " $setvars_path " || true
2019-08-09 19:02:42 +03:00
else
2021-09-15 16:49:11 +03:00
printf "Error: Failed to set the environment variables automatically. To fix, run the following command:\n source <INSTALL_DIR>/setupvars.sh\n where INSTALL_DIR is the OpenVINO installation directory.\n\n"
2019-08-09 19:02:42 +03:00
exit 1
fi
else
2022-07-26 23:17:41 +04:00
# case for run with `sudo -E`
2022-01-17 21:54:05 +03:00
source " $INTEL_OPENVINO_DIR /setupvars.sh " || true
2019-08-09 19:02:42 +03:00
fi
if ! command -v cmake & >/dev/null; then
2022-03-24 22:27:29 +03:00
printf "\n\nCMAKE is not installed. It is required to build OpenVINO Runtime samples. Please install it. \n\n"
2019-08-09 19:02:42 +03:00
exit 1
fi
OS_PATH = $( uname -m)
2022-07-24 15:13:00 +04:00
NUM_THREADS = 2
2019-08-09 19:02:42 +03:00
2020-02-11 22:48:49 +03:00
if [ " $OS_PATH " = = "x86_64" ] ; then
2019-08-09 19:02:42 +03:00
OS_PATH = "intel64"
2022-07-24 15:13:00 +04:00
NUM_THREADS = 8
2019-08-09 19:02:42 +03:00
fi
2020-02-11 22:48:49 +03:00
if [ -e " $build_dir /CMakeCache.txt " ] ; then
2020-10-09 13:25:53 +03:00
rm -rf " $build_dir /CMakeCache.txt "
2019-08-09 19:02:42 +03:00
fi
2021-11-08 14:15:30 +03:00
2020-02-11 22:48:49 +03:00
mkdir -p " $build_dir "
2022-07-24 15:13:00 +04:00
cmake -DCMAKE_BUILD_TYPE= Release -S " $SAMPLES_PATH " -B " $build_dir "
cmake --build " $build_dir " --config Release --parallel $NUM_THREADS
2019-08-09 19:02:42 +03:00
2021-11-08 14:15:30 +03:00
if [ " $sample_install_dir " != "" ] ; then
2022-07-24 15:13:00 +04:00
cmake -DCMAKE_INSTALL_PREFIX= " $sample_install_dir " -DCOMPONENT= samples_bin -P " $build_dir /cmake_install.cmake "
2021-11-08 14:15:30 +03:00
printf "\nBuild completed, you can find binaries for all samples in the %s/samples_bin subfolder.\n\n" " $sample_install_dir "
else
printf " \nBuild completed, you can find binaries for all samples in the $build_dir /%s/Release subfolder.\n\n " " $OS_PATH "
fi