[IE Samples] Enable a custom build output folder (#8263)
* Enable a custom build output folder * Add the option to set a sample install directory * Fix code style issues * Exclude samples_bin from default build * Make an installation directory dependent on a build type Co-authored-by: Vladimir Dudnik <vladimir.dudnik@intel.com> * Remove old msbuild version support * Use cmake to build samples * Use targets to install samples * Use targets to install dlls: `format_reader` and `opencv_c_wrapper` * Add `LIBRARY DESTINATION` for `format_reader` and `opencv_c_wrapper` install commands Co-authored-by: Vladimir Dudnik <vladimir.dudnik@intel.com>
This commit is contained in:
parent
5dacaa386f
commit
763859d082
@ -227,6 +227,13 @@ macro(ie_add_sample)
|
||||
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE gflags)
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS ${IE_SAMPLE_NAME}
|
||||
RUNTIME DESTINATION samples_bin/
|
||||
COMPONENT samples_bin
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
# create global target with all samples / demo apps
|
||||
if(NOT TARGET ie_samples)
|
||||
add_custom_target(ie_samples ALL)
|
||||
|
@ -3,6 +3,44 @@
|
||||
# Copyright (C) 2018-2021 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
usage() {
|
||||
echo "Build inference engine samples"
|
||||
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
|
||||
}
|
||||
|
||||
samples_type=$(basename "$PWD")
|
||||
build_dir="$HOME/inference_engine_${samples_type}_samples_build"
|
||||
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
|
||||
|
||||
error() {
|
||||
local code="${3:-1}"
|
||||
if [[ -n "$2" ]];then
|
||||
@ -39,9 +77,6 @@ if ! command -v cmake &>/dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
samples_type=$(basename "$PWD")
|
||||
build_dir="$HOME/inference_engine_${samples_type}_samples_build"
|
||||
|
||||
OS_PATH=$(uname -m)
|
||||
NUM_THREADS="-j2"
|
||||
|
||||
@ -53,9 +88,16 @@ fi
|
||||
if [ -e "$build_dir/CMakeCache.txt" ]; then
|
||||
rm -rf "$build_dir/CMakeCache.txt"
|
||||
fi
|
||||
|
||||
mkdir -p "$build_dir"
|
||||
cd "$build_dir"
|
||||
cmake -DCMAKE_BUILD_TYPE=Release "$SAMPLES_PATH"
|
||||
make $NUM_THREADS
|
||||
|
||||
printf "\nBuild completed, you can find binaries for all samples in the $build_dir/%s/Release subfolder.\n\n" "$OS_PATH"
|
||||
if [ "$sample_install_dir" != "" ]; then
|
||||
cmake -DCMAKE_INSTALL_PREFIX="$sample_install_dir" -DCOMPONENT=samples_bin -P cmake_install.cmake
|
||||
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
|
||||
|
||||
|
@ -8,24 +8,26 @@ SETLOCAL EnableDelayedExpansion
|
||||
set "ROOT_DIR=%~dp0"
|
||||
FOR /F "delims=\" %%i IN ("%ROOT_DIR%") DO set SAMPLES_TYPE=%%~nxi
|
||||
|
||||
set "SOLUTION_DIR64=%USERPROFILE%\Documents\Intel\OpenVINO\inference_engine_%SAMPLES_TYPE%_samples_build"
|
||||
set "SAMPLE_BUILD_DIR=%USERPROFILE%\Documents\Intel\OpenVINO\inference_engine_%SAMPLES_TYPE%_samples_build"
|
||||
set SAMPLE_INSTALL_DIR=
|
||||
|
||||
set MSBUILD_BIN=
|
||||
set VS_PATH=
|
||||
set VS_VERSION=
|
||||
|
||||
if not "%1" == "" (
|
||||
if "%1"=="VS2015" (
|
||||
set "VS_VERSION=2015"
|
||||
) else if "%1"=="VS2017" (
|
||||
set "VS_VERSION=2017"
|
||||
) else if "%1"=="VS2019" (
|
||||
set "VS_VERSION=2019"
|
||||
) else (
|
||||
echo Unrecognized option specified "%1"
|
||||
echo Supported command line options: VS2015, VS2017, VS2019
|
||||
goto errorHandling
|
||||
)
|
||||
:: command line arguments parsing
|
||||
:input_arguments_loop
|
||||
if not "%1"=="" (
|
||||
if "%1"=="-b" (
|
||||
set SAMPLE_BUILD_DIR=%2
|
||||
shift
|
||||
) else if "%1"=="-i" (
|
||||
set SAMPLE_INSTALL_DIR=%2
|
||||
shift
|
||||
) else if "%1"=="-h" (
|
||||
goto usage
|
||||
) else (
|
||||
echo Unrecognized option specified "%1"
|
||||
goto usage
|
||||
)
|
||||
shift
|
||||
goto :input_arguments_loop
|
||||
)
|
||||
|
||||
if "%INTEL_OPENVINO_DIR%"=="" (
|
||||
@ -36,7 +38,6 @@ if "%INTEL_OPENVINO_DIR%"=="" (
|
||||
echo To fix, run the following command: ^<INSTALL_DIR^>\setupvars.bat
|
||||
echo where INSTALL_DIR is the OpenVINO installation directory.
|
||||
GOTO errorHandling
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@ -46,87 +47,31 @@ if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
|
||||
set "PLATFORM=Win32"
|
||||
)
|
||||
|
||||
set VSWHERE="false"
|
||||
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
|
||||
set VSWHERE="true"
|
||||
cd "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
|
||||
) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
|
||||
set VSWHERE="true"
|
||||
cd "%ProgramFiles%\Microsoft Visual Studio\Installer"
|
||||
) else (
|
||||
echo "vswhere tool is not found"
|
||||
)
|
||||
if exist "%SAMPLE_BUILD_DIR%\CMakeCache.txt" del "%SAMPLE_BUILD_DIR%\CMakeCache.txt"
|
||||
|
||||
if !VSWHERE! == "true" (
|
||||
if "!VS_VERSION!"=="" (
|
||||
echo Searching the latest Visual Studio...
|
||||
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
|
||||
set VS_PATH=%%i
|
||||
)
|
||||
) else (
|
||||
echo Searching Visual Studio !VS_VERSION!...
|
||||
for /f "usebackq tokens=*" %%i in (`vswhere -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
|
||||
set CUR_VS=%%i
|
||||
if not "!CUR_VS:%VS_VERSION%=!"=="!CUR_VS!" (
|
||||
set VS_PATH=!CUR_VS!
|
||||
)
|
||||
)
|
||||
)
|
||||
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 "!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"
|
||||
)
|
||||
)
|
||||
|
||||
if "!MSBUILD_BIN!" == "" (
|
||||
if "!VS_VERSION!"=="2015" (
|
||||
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"
|
||||
)
|
||||
) else if "!VS_VERSION!"=="2017" (
|
||||
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"
|
||||
) else 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"
|
||||
) else 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 Microsoft Visual Studio !VS_VERSION! 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
|
||||
)
|
||||
|
||||
if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt"
|
||||
|
||||
echo Creating Visual Studio %MSBUILD_VERSION% %PLATFORM% files in %SOLUTION_DIR64%... && ^
|
||||
cd "%ROOT_DIR%" && cmake -E make_directory "%SOLUTION_DIR64%" && cd "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%ROOT_DIR%"
|
||||
cd "%ROOT_DIR%" && cmake -E make_directory "%SAMPLE_BUILD_DIR%" && cd "%SAMPLE_BUILD_DIR%" && cmake -G "Visual Studio 16 2019" -A %PLATFORM% "%ROOT_DIR%"
|
||||
|
||||
echo.
|
||||
echo ###############^|^| Build Inference Engine samples using MS Visual Studio (MSBuild.exe) ^|^|###############
|
||||
echo.
|
||||
echo "!MSBUILD_BIN!" Samples.sln /p:Configuration=Release
|
||||
"!MSBUILD_BIN!" Samples.sln /p:Configuration=Release
|
||||
|
||||
echo cmake --build . --config Release
|
||||
cmake --build . --config Release
|
||||
if ERRORLEVEL 1 GOTO errorHandling
|
||||
|
||||
if NOT "%SAMPLE_INSTALL_DIR%"=="" cmake -DCMAKE_INSTALL_PREFIX="%SAMPLE_INSTALL_DIR%" -DCOMPONENT=samples_bin -P cmake_install.cmake
|
||||
|
||||
echo Done.
|
||||
goto :eof
|
||||
exit /b
|
||||
|
||||
:usage
|
||||
echo Build inference engine samples
|
||||
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
|
||||
exit /b
|
||||
|
||||
:errorHandling
|
||||
echo Error
|
||||
|
@ -40,3 +40,9 @@ set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME}
|
||||
if(COMMAND add_clang_format_target)
|
||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}
|
||||
RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL
|
||||
LIBRARY DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
@ -28,3 +28,9 @@ set_target_properties(${TARGET_NAME} PROPERTIES FOLDER c_samples)
|
||||
if(COMMAND add_clang_format_target AND NOT IE_SAMPLE_EXCLUDE_CLANG_FORMAT)
|
||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
install(
|
||||
TARGETS ${TARGET_NAME}
|
||||
RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL
|
||||
LIBRARY DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user