Commit 3d68b5ba authored by Alexander Alekhin's avatar Alexander Alekhin

samples: update build script (winpack)

- drop EnableDelayedExpansion
parent 8792bddb
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
:: - MSVS 2015/2017 :: - MSVS 2015/2017
:: (tools are searched on default paths or environment should be pre-configured) :: (tools are searched on default paths or environment should be pre-configured)
@echo off @echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION setlocal
set SCRIPTDIR=%~dp0 set SCRIPTDIR=%~dp0
if NOT exist "%SCRIPTDIR%\..\..\build" ( if NOT exist "%SCRIPTDIR%\..\..\build" (
...@@ -28,20 +28,20 @@ if NOT "%~x1" == ".cpp" ( ...@@ -28,20 +28,20 @@ if NOT "%~x1" == ".cpp" (
goto die goto die
) )
set SRC_FILENAME=%~dpnx1 set SRC_FILENAME=%~dpnx1
echo SRC_FILENAME=!SRC_FILENAME! echo SRC_FILENAME=%SRC_FILENAME%
call :dirname "!SRC_FILENAME!" SRC_DIR call :dirname "%SRC_FILENAME%" SRC_DIR
echo SRC_DIR=!SRC_DIR! echo SRC_DIR=%SRC_DIR%
set "SRC_NAME=%~n1" set "SRC_NAME=%~n1"
echo SRC_NAME=!SRC_NAME! echo SRC_NAME=%SRC_NAME%
echo ================================================================================ echo ================================================================================
:: Path to FFMPEG binary files :: Path to FFMPEG binary files
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\bin\" set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\bin\"
:: Detect compiler :: Detect compiler
cl /? >NUL 2>NUL <NUL cl /? >NUL 2>NUL <NUL
if !ERRORLEVEL! NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
PUSHD !CD! PUSHD %CD%
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" ( if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" (
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat"
goto check_msvc goto check_msvc
...@@ -61,7 +61,7 @@ if !ERRORLEVEL! NEQ 0 ( ...@@ -61,7 +61,7 @@ if !ERRORLEVEL! NEQ 0 (
:check_msvc :check_msvc
POPD POPD
cl /? >NUL 2>NUL <NUL cl /? >NUL 2>NUL <NUL
if !ERRORLEVEL! NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
set "MSG=Can't detect Microsoft Visial Studio C++ compiler (cl.exe). MSVS 2015/2017 are supported only from standard locations" set "MSG=Can't detect Microsoft Visial Studio C++ compiler (cl.exe). MSVS 2015/2017 are supported only from standard locations"
goto die goto die
) )
...@@ -69,88 +69,85 @@ if !ERRORLEVEL! NEQ 0 ( ...@@ -69,88 +69,85 @@ if !ERRORLEVEL! NEQ 0 (
:: Detect CMake :: Detect CMake
cmake --version >NUL 2>NUL cmake --version >NUL 2>NUL
if !ERRORLEVEL! EQU 0 ( if %ERRORLEVEL% EQU 0 GOTO :CMAKE_FOUND
set CMAKE_FOUND=1
) else ( if NOT exist "C:\Program Files\CMake\bin" GOTO CMAKE_NOT_FOUND
if exist "C:\Program Files\CMake\bin" ( set "PATH=%PATH%;C:\Program Files\CMake\bin"
set "PATH=!PATH!;C:\Program Files\CMake\bin" cmake --version >NUL 2>NUL
cmake --version >NUL 2>NUL if %ERRORLEVEL% EQU 0 GOTO :CMAKE_FOUND
if !ERRORLEVEL! EQU 0 (
set CMAKE_FOUND=1 :CMAKE_NOT_FOUND
) set "MSG=CMake is required to build OpenCV samples. Download it from here: https://cmake.org/download/ and install into 'C:\Program Files\CMake'"
) goto die
)
if NOT DEFINED CMAKE_FOUND ( :CMAKE_FOUND
set "MSG=CMake is required to build OpenCV samples. Download it from here: https://cmake.org/download/ and install into 'C:\Program Files\CMake'" set CMAKE_FOUND=1
goto die call :execute cmake --version
) else ( echo CMake is detected
call :execute cmake --version
echo CMake is detected
)
:: Detect available MSVS version :: Detect available MSVS version
if NOT DEFINED VisualStudioVersion ( if NOT DEFINED VisualStudioVersion (
set "MSG=Can't determine MSVS version. 'VisualStudioVersion' is not defined" set "MSG=Can't determine MSVS version. 'VisualStudioVersion' is not defined"
goto die goto die
) )
if "!VisualStudioVersion!" == "14.0" ( if "%VisualStudioVersion%" == "14.0" (
set CMAKE_GENERATOR="Visual Studio 14 Win64" set CMAKE_GENERATOR="Visual Studio 14 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc14\bin\" set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\x64\vc14\bin\"
) else ( ) else (
if "!VisualStudioVersion!" == "15.0" ( if "%VisualStudioVersion%" == "15.0" (
set CMAKE_GENERATOR="Visual Studio 15 Win64" set CMAKE_GENERATOR="Visual Studio 15 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc15\bin\" set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\x64\vc15\bin\"
) else ( ) else (
set "MSG=Unsupported MSVS version. VisualStudioVersion=!VisualStudioVersion!" set "MSG=Unsupported MSVS version. VisualStudioVersion=%VisualStudioVersion%"
goto die goto die
) )
) )
set "BUILD_DIR=!SRC_DIR!\build_!SRC_NAME!" set "BUILD_DIR=%SRC_DIR%\build_%SRC_NAME%"
call :set_title Create build directory call :set_title Create build directory
if NOT exist "!BUILD_DIR!" ( call :execute md "!BUILD_DIR!" ) if NOT exist "%BUILD_DIR%" ( call :execute md "%BUILD_DIR%" )
PUSHD "!BUILD_DIR!" PUSHD "%BUILD_DIR%"
if NOT exist "!BUILD_DIR!/sample" ( call :execute md "!BUILD_DIR!/sample" ) if NOT exist "%BUILD_DIR%/sample" ( call :execute md "%BUILD_DIR%/sample" )
call :execute copy /Y "!SCRIPTDIR!/CMakeLists.example.in" "!BUILD_DIR!/sample/CMakeLists.txt" call :execute copy /Y "%SCRIPTDIR%/CMakeLists.example.in" "%BUILD_DIR%/sample/CMakeLists.txt"
call :set_title Configuring via CMake call :set_title Configuring via CMake
call :execute cmake -G!CMAKE_GENERATOR! "!BUILD_DIR!\sample" -DEXAMPLE_NAME=!SRC_NAME! "-DEXAMPLE_FILE=!SRC_FILENAME!" "-DOpenCV_DIR=!SCRIPTDIR!\..\..\build" call :execute cmake -G%CMAKE_GENERATOR% "%BUILD_DIR%\sample" -DEXAMPLE_NAME=%SRC_NAME% "-DEXAMPLE_FILE=%SRC_FILENAME%" "-DOpenCV_DIR=%SCRIPTDIR%\..\..\build"
if !ERRORLEVEL! NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
set "MSG=CMake configuration step failed: !BUILD_DIR!" set "MSG=CMake configuration step failed: %BUILD_DIR%"
goto die goto die
) )
call :set_title Build sample project via CMake call :set_title Build sample project via CMake
call :execute cmake --build . --config Release call :execute cmake --build . --config Release
if !ERRORLEVEL! NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
set "MSG=Build step failed: !BUILD_DIR!" set "MSG=Build step failed: %BUILD_DIR%"
goto die goto die
) )
call :set_title Launch !SRC_NAME! call :set_title Launch %SRC_NAME%
if NOT exist "!BUILD_DIR!\Release\!SRC_NAME!.exe" ( if NOT exist "%BUILD_DIR%\Release\%SRC_NAME%.exe" (
echo. "ERROR: Can't find executable file (build seems broken): !SRC_NAME!.exe" echo. "ERROR: Can't find executable file (build seems broken): %SRC_NAME%.exe"
) else ( ) else (
cd "!BUILD_DIR!\Release" cd "%BUILD_DIR%\Release"
call :execute "!SRC_NAME!.exe" --help call :execute "%SRC_NAME%.exe" --help
echo ================================================================================ echo ================================================================================
echo ** Type '!SRC_NAME!.exe' to run sample application echo ** Type '%SRC_NAME%.exe' to run sample application
echo ** Type '!SRC_NAME!.exe --help' to get list of available options (if available) echo ** Type '%SRC_NAME%.exe --help' to get list of available options (if available)
echo ** Type 'start ..\!SRC_NAME!.sln' to launch MSVS IDE echo ** Type 'start ..\%SRC_NAME%.sln' to launch MSVS IDE
echo ** Type 'cmake --build .. --config Release' to rebuild sample echo ** Type 'cmake --build .. --config Release' to rebuild sample
echo ** Type 'exit' to exit from interactive shell and open the build directory echo ** Type 'exit' to exit from interactive shell and open the build directory
echo ================================================================================ echo ================================================================================
) )
call :set_title Hands-on: !SRC_NAME! call :set_title Hands-on: %SRC_NAME%
cmd /k echo Current directory: !CD! cmd /k echo Current directory: %CD%
call :set_title Done: !SRC_NAME! call :set_title Done: %SRC_NAME%
echo Opening build directory with project files... echo Opening build directory with project files...
explorer "!BUILD_DIR!" explorer "%BUILD_DIR%"
POPD POPD
echo Done! echo Done%
pause pause
exit /B 0 exit /B 0
...@@ -166,7 +163,7 @@ exit /B 0 ...@@ -166,7 +163,7 @@ exit /B 0
:execute :execute
echo ================================================================================= echo =================================================================================
setlocal enableextensions disabledelayedexpansion setlocal
echo %* echo %*
call %* call %*
endlocal endlocal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment