[IE Sample Scripts] Use cmake to build samples (#8442)

* Use cmake to build samples

* Add the option to set custom build output folder
This commit is contained in:
Dmitry Pigasin 2021-11-10 17:31:28 +03:00 committed by GitHub
parent 852dd93803
commit 331372e7ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 144 deletions

View File

@ -4,12 +4,18 @@
@echo off @echo off
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set ROOT_DIR=%~dp0
set TARGET=CPU set TARGET=CPU
set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO
:: command line arguments parsing :: command line arguments parsing
:input_arguments_loop :input_arguments_loop
if not "%1"=="" ( if not "%1"=="" (
if "%1"=="-b" (
set BUILD_FOLDER=%2
shift
)
if "%1"=="-d" ( if "%1"=="-d" (
set TARGET=%2 set TARGET=%2
echo target = !TARGET! echo target = !TARGET!
@ -25,6 +31,7 @@ if not "%1"=="" (
echo. echo.
echo Options: echo Options:
echo -help Print help message echo -help Print help message
echo -b BUILD_FOLDER Specify the sample build directory
echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified
echo -sample-options OPTIONS Specify command line arguments for the sample echo -sample-options OPTIONS Specify command line arguments for the sample
exit /b exit /b
@ -33,12 +40,12 @@ if not "%1"=="" (
goto :input_arguments_loop goto :input_arguments_loop
) )
set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build"
IF "%SAMPLE_OPTIONS%"=="" ( IF "%SAMPLE_OPTIONS%"=="" (
set SAMPLE_OPTIONS=-niter 1000 set SAMPLE_OPTIONS=-niter 1000
) )
set ROOT_DIR=%~dp0
set TARGET_PRECISION=FP16 set TARGET_PRECISION=FP16
echo target_precision = !TARGET_PRECISION! echo target_precision = !TARGET_PRECISION!
@ -158,81 +165,21 @@ if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
set "PLATFORM=Win32" set "PLATFORM=Win32"
) )
set VSWHERE="false"
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
set VSWHERE="true"
cd /d "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
set VSWHERE="true"
cd /d "%ProgramFiles%\Microsoft Visual Studio\Installer"
) else (
echo "vswhere tool is not found"
)
if !VSWHERE! == "true" (
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set VS_PATH=%%i
)
if exist "!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe"
)
if exist "!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe"
)
if exist "!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe"
)
for /f "usebackq tokens=1 delims=." %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationVersion`) do (
set VS_MAJOR_VER=%%i
)
if "!VS_MAJOR_VER!"=="16" set "MSBUILD_VERSION=16 2019"
if "!VS_MAJOR_VER!"=="15" set "MSBUILD_VERSION=15 2017"
)
if "!MSBUILD_BIN!" == "" (
if exist "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=14 2015"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
) else (
if not "!MSBUILD_BIN:2019=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=16 2019"
if not "!MSBUILD_BIN:2017=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=15 2017"
if not "!MSBUILD_BIN:2015=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=14 2015"
)
if "!MSBUILD_BIN!" == "" (
echo Build tools for Visual Studio 2015 / 2017 / 2019 cannot be found. If you use Visual Studio 2017, please download and install build tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
GOTO errorHandling
)
set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build"
echo Creating Visual Studio !MSBUILD_VERSION! %PLATFORM% files in %SOLUTION_DIR64%... && ^
if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt" if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt"
cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp"
cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio 16 2019" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp"
if ERRORLEVEL 1 GOTO errorHandling if ERRORLEVEL 1 GOTO errorHandling
CALL :delay 7 CALL :delay 7
echo. echo.
echo ###############^|^| Build Inference Engine samples using MS Visual Studio (MSBuild.exe) ^|^|############### echo ###############^|^| Build Inference Engine samples using cmake ^|^|###############
echo. echo.
CALL :delay 3
echo "!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\benchmark_app /clp:ErrorsOnly /m
"!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\benchmark_app /clp:ErrorsOnly /m
CALL :delay 3
echo cmake --build . --config Release --target benchmark_app
cmake --build . --config Release --target benchmark_app
if ERRORLEVEL 1 GOTO errorHandling if ERRORLEVEL 1 GOTO errorHandling
CALL :delay 7 CALL :delay 7

View File

@ -6,6 +6,7 @@
echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n" echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )" ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )"
build_dir="$HOME/inference_engine_cpp_samples_build"
. "$ROOT_DIR/utils.sh" . "$ROOT_DIR/utils.sh"
@ -14,6 +15,7 @@ usage() {
echo echo
echo "Options:" echo "Options:"
echo " -help Print help message" echo " -help Print help message"
echo " -b BUILD_DIR Specify the sample build directory"
echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified" echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified"
echo " -sample-options OPTIONS Specify command line arguments for the sample" echo " -sample-options OPTIONS Specify command line arguments for the sample"
echo echo
@ -30,6 +32,10 @@ do
key="$1" key="$1"
case $key in case $key in
-b | --build_dir)
build_dir="$2/inference_engine_cpp_samples_build"
shift
;;
-h | -help | --help) -h | -help | --help)
usage usage
;; ;;
@ -58,9 +64,9 @@ target_precision="FP16"
echo -ne "target_precision = ${target_precision}\n" echo -ne "target_precision = ${target_precision}\n"
models_path="$HOME/openvino_models/models" models_path="$build_dir/../openvino_models/models"
models_cache="$HOME/openvino_models/cache" models_cache="$build_dir/../openvino_models/cache"
irs_path="$HOME/openvino_models/ir" irs_path="$build_dir/../openvino_models/ir"
model_name="squeezenet1.1" model_name="squeezenet1.1"
@ -163,7 +169,6 @@ if [ "$OS_PATH" == "x86_64" ]; then
fi fi
samples_path="${INTEL_OPENVINO_DIR}/samples/cpp" samples_path="${INTEL_OPENVINO_DIR}/samples/cpp"
build_dir="$HOME/inference_engine_cpp_samples_build"
binaries_dir="${build_dir}/${OS_PATH}/Release" binaries_dir="${build_dir}/${OS_PATH}/Release"
if [ -e "$build_dir/CMakeCache.txt" ]; then if [ -e "$build_dir/CMakeCache.txt" ]; then

View File

@ -4,12 +4,18 @@
@echo off @echo off
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set ROOT_DIR=%~dp0
set TARGET=CPU set TARGET=CPU
set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO
:: command line arguments parsing :: command line arguments parsing
:input_arguments_loop :input_arguments_loop
if not "%1"=="" ( if not "%1"=="" (
if "%1"=="-b" (
set BUILD_FOLDER=%2
shift
)
if "%1"=="-d" ( if "%1"=="-d" (
set TARGET=%2 set TARGET=%2
echo target = !TARGET! echo target = !TARGET!
@ -25,6 +31,7 @@ if not "%1"=="" (
echo. echo.
echo Options: echo Options:
echo -help Print help message echo -help Print help message
echo -b BUILD_FOLDER Specify the sample build directory
echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified echo -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified
echo -sample-options OPTIONS Specify command line arguments for the sample echo -sample-options OPTIONS Specify command line arguments for the sample
exit /b exit /b
@ -33,7 +40,7 @@ if not "%1"=="" (
goto :input_arguments_loop goto :input_arguments_loop
) )
set ROOT_DIR=%~dp0 set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build"
set TARGET_PRECISION=FP16 set TARGET_PRECISION=FP16
@ -154,81 +161,21 @@ if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
set "PLATFORM=Win32" set "PLATFORM=Win32"
) )
set VSWHERE="false"
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
set VSWHERE="true"
cd /d "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
set VSWHERE="true"
cd /d "%ProgramFiles%\Microsoft Visual Studio\Installer"
) else (
echo "vswhere tool is not found"
)
if !VSWHERE! == "true" (
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set VS_PATH=%%i
)
if exist "!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe"
)
if exist "!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe"
)
if exist "!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" (
set "MSBUILD_BIN=!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe"
)
for /f "usebackq tokens=1 delims=." %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationVersion`) do (
set VS_MAJOR_VER=%%i
)
if "!VS_MAJOR_VER!"=="16" set "MSBUILD_VERSION=16 2019"
if "!VS_MAJOR_VER!"=="15" set "MSBUILD_VERSION=15 2017"
)
if "!MSBUILD_BIN!" == "" (
if exist "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=14 2015"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" (
set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBUILD_VERSION=15 2017"
)
) else (
if not "!MSBUILD_BIN:2019=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=16 2019"
if not "!MSBUILD_BIN:2017=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=15 2017"
if not "!MSBUILD_BIN:2015=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=14 2015"
)
if "!MSBUILD_BIN!" == "" (
echo Build tools for Visual Studio 2015 / 2017 / 2019 cannot be found. If you use Visual Studio 2017, please download and install build tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
GOTO errorHandling
)
set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_cpp_samples_build"
echo Creating Visual Studio !MSBUILD_VERSION! %PLATFORM% files in %SOLUTION_DIR64%... && ^
if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt" if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt"
cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp"
cd /d "%INTEL_OPENVINO_DIR%\samples\cpp" && cmake -E make_directory "%SOLUTION_DIR64%" && cd /d "%SOLUTION_DIR64%" && cmake -G "Visual Studio 16 2019" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\samples\cpp"
if ERRORLEVEL 1 GOTO errorHandling if ERRORLEVEL 1 GOTO errorHandling
CALL :delay 7 CALL :delay 7
echo. echo.
echo ###############^|^| Build Inference Engine samples using MS Visual Studio (MSBuild.exe) ^|^|############### echo ###############^|^| Build Inference Engine samples using cmake ^|^|###############
echo. echo.
CALL :delay 3
echo "!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\classification_sample_async /clp:ErrorsOnly /m
"!MSBUILD_BIN!" Samples.sln /p:Configuration=Release /t:cpp_samples\classification_sample_async /clp:ErrorsOnly /m
CALL :delay 3
echo cmake --build . --config Release --target classification_sample_async
cmake --build . --config Release --target classification_sample_async
if ERRORLEVEL 1 GOTO errorHandling if ERRORLEVEL 1 GOTO errorHandling
CALL :delay 7 CALL :delay 7

View File

@ -6,6 +6,7 @@
echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n" echo -ne "\e[0;33mWARNING: If you get an error when running the sample in the Docker container, you may need to install additional packages. To do this, run the container as root (-u 0) and run install_openvino_dependencies.sh script. If you get a package-independent error, try setting additional parameters using -sample-options.\e[0m\n"
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )" ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]-$0}" )" && pwd )"
build_dir="$HOME/inference_engine_cpp_samples_build"
. "$ROOT_DIR/utils.sh" . "$ROOT_DIR/utils.sh"
@ -14,6 +15,7 @@ usage() {
echo echo
echo "Options:" echo "Options:"
echo " -help Print help message" echo " -help Print help message"
echo " -b BUILD_DIR Specify the sample build directory"
echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified" echo " -d DEVICE Specify the target device to infer on; CPU, GPU, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified"
echo " -sample-options OPTIONS Specify command line arguments for the sample" echo " -sample-options OPTIONS Specify command line arguments for the sample"
echo echo
@ -30,6 +32,10 @@ do
key="$1" key="$1"
case $key in case $key in
-b | --build_dir)
build_dir="$2/inference_engine_cpp_samples_build"
shift
;;
-h | -help | --help) -h | -help | --help)
usage usage
;; ;;
@ -54,9 +60,9 @@ target_precision="FP16"
echo -ne "target_precision = ${target_precision}\n" echo -ne "target_precision = ${target_precision}\n"
models_path="$HOME/openvino_models/models" models_path="$build_dir/../openvino_models/models"
models_cache="$HOME/openvino_models/cache" models_cache="$build_dir/../openvino_models/cache"
irs_path="$HOME/openvino_models/ir" irs_path="$build_dir/../openvino_models/ir"
model_name="squeezenet1.1" model_name="squeezenet1.1"