Add a section of how to link IE with CMake project (#99)
[platform/upstream/dldt.git] / inference-engine / samples / build_samples.sh
1 #!/bin/bash
2
3 # Copyright (c) 2018 Intel Corporation
4
5 #  Licensed under the Apache License, Version 2.0 (the "License");
6 #  you may not use this file except in compliance with the License.
7 #  You may obtain a copy of the License at
8
9 #       http://www.apache.org/licenses/LICENSE-2.0
10
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16
17 error() {
18     local code="${3:-1}"
19     if [[ -n "$2" ]];then
20         echo "Error on or near line $1: $2; exiting with status ${code}"
21     else
22         echo "Error on or near line $1; exiting with status ${code}"
23     fi
24     exit "${code}" 
25 }
26 trap 'error ${LINENO}' ERR
27
28 SAMPLES_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
29
30 if [[ -z "${InferenceEngine_DIR}" ]]; then
31     printf "\nInferenceEngine_DIR environment variable is not set. Trying to find setupvars.sh to set it. \n"
32     
33     setvars_path=$SAMPLES_PATH/../..
34     if [ -e "$setvars_path/inference_engine/bin/setvars.sh" ]; then # for Intel Deep Learning Deployment Toolkit package
35         setvars_path="$setvars_path/inference_engine/bin/setvars.sh"
36     elif [ -e "$setvars_path/../bin/setupvars.sh" ]; then # for OpenVINO package
37         setvars_path="$setvars_path/../bin/setupvars.sh"
38     elif [ -e "$setvars_path/../setupvars.sh" ]; then
39         setvars_path="$setvars_path/../setupvars.sh"
40     else
41         printf "Error: setupvars.sh is not found in hardcoded paths. \n\n"
42         exit 1
43     fi 
44     if ! source $setvars_path ; then
45         printf "Unable to run ./setupvars.sh. Please check its presence. \n\n"
46         exit 1
47     fi
48 fi
49
50 if ! command -v cmake &>/dev/null; then
51     printf "\n\nCMAKE is not installed. It is required to build Inference Engine samples. Please install it. \n\n"
52     exit 1
53 fi
54
55 build_dir=$HOME/inference_engine_samples_build
56 mkdir -p $build_dir
57 cd $build_dir
58 cmake -DCMAKE_BUILD_TYPE=Release $SAMPLES_PATH
59 make -j8
60
61 printf "\nBuild completed, you can find binaries for all samples in the $HOME/inference_engine_samples_build/intel64/Release subfolder.\n\n"