Unverified Commit a4b21d9e authored by Alexander Alekhin's avatar Alexander Alekhin Committed by GitHub

Merge pull request #13177 from alalek:update_win32_scripts

parents b321851e 5cf84c37
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET "SCRIPT_DIR=%~dp0"
IF NOT DEFINED OPENCV_QUIET ( ECHO Setting vars for OpenCV @OPENCV_VERSION@ )
SET "PATH=!SCRIPT_DIR!\@OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG@;%PATH%"
SET "PATH=%SCRIPT_DIR%\@OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG@;%PATH%"
IF NOT DEFINED OPENCV_SKIP_PYTHON (
SET "PYTHONPATH_OPENCV=!SCRIPT_DIR!\@OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG@"
IF NOT DEFINED OPENCV_QUIET ( ECHO Append PYTHONPATH: !PYTHONPATH_OPENCV! )
SET "PYTHONPATH=!PYTHONPATH_OPENCV!;%PYTHONPATH%"
)
IF NOT DEFINED OPENCV_SKIP_PYTHON CALL :SET_PYTHON
SET SCRIPT_DIR=
IF NOT [%1] == [] GOTO :RUN_COMMAND
GOTO :EOF
IF NOT [%1] == [] (
%*
EXIT /B !errorlevel!
:RUN_COMMAND
SET RUN_INTERACTIVE=1
echo %CMDCMDLINE% | find /i "%~0" >nul
IF NOT errorlevel 1 set RUN_INTERACTIVE=0
%*
SET RESULT=%ERRORLEVEL%
IF %RESULT% NEQ 0 (
IF _%RUN_INTERACTIVE%_==_0_ ( IF NOT DEFINED OPENCV_BATCH_MODE ( pause ) )
)
EXIT /B %RESULT%
:SET_PYTHON
SET "PYTHONPATH_OPENCV=%SCRIPT_DIR%\@OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG@"
IF NOT DEFINED OPENCV_QUIET ( ECHO Append PYTHONPATH: %PYTHONPATH_OPENCV% )
SET "PYTHONPATH=%PYTHONPATH_OPENCV%;%PYTHONPATH%"
SET PYTHONPATH_OPENCV=
EXIT /B
:EOF
......@@ -7,7 +7,7 @@
:: - MSVS 2015/2017
:: (tools are searched on default paths or environment should be pre-configured)
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
setlocal
set SCRIPTDIR=%~dp0
if NOT exist "%SCRIPTDIR%\..\..\build" (
......@@ -28,20 +28,20 @@ if NOT "%~x1" == ".cpp" (
goto die
)
set SRC_FILENAME=%~dpnx1
echo SRC_FILENAME=!SRC_FILENAME!
call :dirname "!SRC_FILENAME!" SRC_DIR
echo SRC_DIR=!SRC_DIR!
echo SRC_FILENAME=%SRC_FILENAME%
call :dirname "%SRC_FILENAME%" SRC_DIR
echo SRC_DIR=%SRC_DIR%
set "SRC_NAME=%~n1"
echo SRC_NAME=!SRC_NAME!
echo SRC_NAME=%SRC_NAME%
echo ================================================================================
:: Path to FFMPEG binary files
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\bin\"
set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\bin\"
:: Detect compiler
cl /? >NUL 2>NUL <NUL
if !ERRORLEVEL! NEQ 0 (
PUSHD !CD!
if %ERRORLEVEL% NEQ 0 (
PUSHD %CD%
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"
goto check_msvc
......@@ -61,7 +61,7 @@ if !ERRORLEVEL! NEQ 0 (
:check_msvc
POPD
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"
goto die
)
......@@ -69,88 +69,85 @@ if !ERRORLEVEL! NEQ 0 (
:: Detect CMake
cmake --version >NUL 2>NUL
if !ERRORLEVEL! EQU 0 (
set CMAKE_FOUND=1
) else (
if exist "C:\Program Files\CMake\bin" (
set "PATH=!PATH!;C:\Program Files\CMake\bin"
cmake --version >NUL 2>NUL
if !ERRORLEVEL! EQU 0 (
set CMAKE_FOUND=1
)
)
)
if NOT DEFINED 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'"
goto die
) else (
call :execute cmake --version
echo CMake is detected
)
if %ERRORLEVEL% EQU 0 GOTO :CMAKE_FOUND
if NOT exist "C:\Program Files\CMake\bin" GOTO CMAKE_NOT_FOUND
set "PATH=%PATH%;C:\Program Files\CMake\bin"
cmake --version >NUL 2>NUL
if %ERRORLEVEL% EQU 0 GOTO :CMAKE_FOUND
: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
:CMAKE_FOUND
set CMAKE_FOUND=1
call :execute cmake --version
echo CMake is detected
:: Detect available MSVS version
if NOT DEFINED VisualStudioVersion (
set "MSG=Can't determine MSVS version. 'VisualStudioVersion' is not defined"
goto die
)
if "!VisualStudioVersion!" == "14.0" (
if "%VisualStudioVersion%" == "14.0" (
set CMAKE_GENERATOR="Visual Studio 14 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc14\bin\"
set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\x64\vc14\bin\"
) else (
if "!VisualStudioVersion!" == "15.0" (
if "%VisualStudioVersion%" == "15.0" (
set CMAKE_GENERATOR="Visual Studio 15 Win64"
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc15\bin\"
set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\x64\vc15\bin\"
) else (
set "MSG=Unsupported MSVS version. VisualStudioVersion=!VisualStudioVersion!"
set "MSG=Unsupported MSVS version. VisualStudioVersion=%VisualStudioVersion%"
goto die
)
)
set "BUILD_DIR=!SRC_DIR!\build_!SRC_NAME!"
set "BUILD_DIR=%SRC_DIR%\build_%SRC_NAME%"
call :set_title Create build directory
if NOT exist "!BUILD_DIR!" ( call :execute md "!BUILD_DIR!" )
PUSHD "!BUILD_DIR!"
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"
if NOT exist "%BUILD_DIR%" ( call :execute md "%BUILD_DIR%" )
PUSHD "%BUILD_DIR%"
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 :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"
if !ERRORLEVEL! NEQ 0 (
set "MSG=CMake configuration step failed: !BUILD_DIR!"
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 (
set "MSG=CMake configuration step failed: %BUILD_DIR%"
goto die
)
call :set_title Build sample project via CMake
call :execute cmake --build . --config Release
if !ERRORLEVEL! NEQ 0 (
set "MSG=Build step failed: !BUILD_DIR!"
if %ERRORLEVEL% NEQ 0 (
set "MSG=Build step failed: %BUILD_DIR%"
goto die
)
call :set_title Launch !SRC_NAME!
if NOT exist "!BUILD_DIR!\Release\!SRC_NAME!.exe" (
echo. "ERROR: Can't find executable file (build seems broken): !SRC_NAME!.exe"
call :set_title Launch %SRC_NAME%
if NOT exist "%BUILD_DIR%\Release\%SRC_NAME%.exe" (
echo. "ERROR: Can't find executable file (build seems broken): %SRC_NAME%.exe"
) else (
cd "!BUILD_DIR!\Release"
call :execute "!SRC_NAME!.exe" --help
cd "%BUILD_DIR%\Release"
call :execute "%SRC_NAME%.exe" --help
echo ================================================================================
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 'start ..\!SRC_NAME!.sln' to launch MSVS IDE
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 'start ..\%SRC_NAME%.sln' to launch MSVS IDE
echo ** Type 'cmake --build .. --config Release' to rebuild sample
echo ** Type 'exit' to exit from interactive shell and open the build directory
echo ================================================================================
)
call :set_title Hands-on: !SRC_NAME!
cmd /k echo Current directory: !CD!
call :set_title Hands-on: %SRC_NAME%
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...
explorer "!BUILD_DIR!"
explorer "%BUILD_DIR%"
POPD
echo Done!
echo Done%
pause
exit /B 0
......@@ -166,7 +163,7 @@ exit /B 0
:execute
echo =================================================================================
setlocal enableextensions disabledelayedexpansion
setlocal
echo %*
call %*
endlocal
......
@ECHO OFF
SETLOCAL
SET SCRIPT_DIR=%~dp0
IF NOT EXIST "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd" (
ECHO ERROR: OpenCV Winpack installation is required
pause
exit
)
:: Detect Python binary
python -V 2>nul
IF %ERRORLEVEL% EQU 0 (
SET PYTHON=python
GOTO :PYTHON_FOUND
)
CALL :QUERY_PYTHON 3.7
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 3.6
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 3.5
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 3.4
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
CALL :QUERY_PYTHON 2.7
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND
GOTO :PYTHON_NOT_FOUND
:QUERY_PYTHON
SETLOCAL
SET PY_VERSION=%1
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKCU\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" /reg:64 /ve 2^>NUL ^| FIND "REG_SZ"') DO SET PYTHON_DIR=%%B
IF EXIST "%PYTHON_DIR%\python.exe" (
SET "PYTHON=%PYTHON_DIR%\python.exe"
GOTO :QUERY_PYTHON_FOUND
)
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKLM\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" /reg:64 /ve 2^>NUL ^| FIND "REG_SZ"') DO SET PYTHON_DIR=%%B
IF EXIST "%PYTHON_DIR%\python.exe" (
SET "PYTHON=%PYTHON_DIR%\python.exe"
GOTO :QUERY_PYTHON_FOUND
)
::echo Python %PY_VERSION% is not detected
ENDLOCAL
EXIT /B 1
:QUERY_PYTHON_FOUND
ECHO Found Python %PY_VERSION% from Windows Registry
ENDLOCAL & SET PYTHON=%PYTHON%
EXIT /B 0
IF exist C:\Python27-x64\python.exe (
SET PYTHON=C:\Python27-x64\python.exe
GOTO :PYTHON_FOUND
)
IF exist C:\Python27\python.exe (
SET PYTHON=C:\Python27\python.exe
GOTO :PYTHON_FOUND
)
:PYTHON_NOT_FOUND
ECHO ERROR: Python not found
IF NOT DEFINED OPENCV_BATCH_MODE ( pause )
EXIT /B
:PYTHON_FOUND
ECHO Using Python: %PYTHON%
:: Don't generate unnecessary .pyc cache files
SET PYTHONDONTWRITEBYTECODE=1
IF [%1]==[] goto rundemo
set SRC_FILENAME=%~dpnx1
echo SRC_FILENAME=%SRC_FILENAME%
call :dirname "%SRC_FILENAME%" SRC_DIR
call :dirname "%PYTHON%" PYTHON_DIR
PUSHD %SRC_DIR%
CALL "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd"
ECHO Run: %*
%PYTHON% %*
SET result=%errorlevel%
IF %result% NEQ 0 (
IF NOT DEFINED OPENCV_BATCH_MODE (
SET "PATH=%PYTHON_DIR%;%PATH%"
echo ================================================================================
echo ** Type 'python sample_name.py' to run sample
echo ** Type 'exit' to exit from interactive shell and open the build directory
echo ================================================================================
cmd /k echo Current directory: %CD%
)
)
POPD
EXIT /B %result%
:rundemo
PUSHD "%SCRIPT_DIR%\python"
CALL "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd"
%PYTHON% demo.py
SET result=%errorlevel%
IF %result% NEQ 0 (
IF NOT DEFINED OPENCV_BATCH_MODE ( pause )
)
POPD
EXIT /B %result%
:dirname file resultVar
setlocal
set _dir=%~dp1
set _dir=%_dir:~0,-1%
endlocal & set %2=%_dir%
EXIT /B 0
@echo off
call ..\_winpack_run_python_sample.cmd %*
exit /B
@echo off
setlocal enableDelayedExpansion
set SCRIPTDIR=%~dp0
if NOT exist %SCRIPTDIR%\..\..\..\build (
echo ERROR: OpenCV Winpack installation is required
pause
exit
)
:: Path to FFMPEG binary files
set PATH=%PATH%;%SCRIPTDIR%\..\..\..\build\bin\
:: Detect Python binary
python -V
if %ERRORLEVEL% EQU 0 (
set PYTHON=python
) else (
if exist C:\Python27-x64\python.exe (
set PYTHON=C:\Python27-x64\python.exe
) else (
if exist C:\Python27\python.exe (
set PYTHON=C:\Python27\python.exe
) else (
echo ERROR: Python not found
pause
exit
)
)
)
echo Using python: %PYTHON%
:: Detect python architecture
%PYTHON% -c "import platform; exit(64 if platform.architecture()[0] == '64bit' else 32)"
if %ERRORLEVEL% EQU 32 (
echo Detected: Python 32-bit
set PYTHONPATH=%CD%\..\..\..\build\python\2.7\x86
) else (
if %ERRORLEVEL% EQU 64 (
echo Detected: Python 64-bit
set PYTHONPATH=%CD%\..\..\..\build\python\2.7\x64
) else (
echo ERROR: Unknown python arch
pause
exit
)
)
:: Don't generate unnecessary .pyc cache files
set PYTHONDONTWRITEBYTECODE=1
if [%1]==[] goto rundemo
%PYTHON% %*
set result=%errorlevel%
IF %result% NEQ 0 (pause)
EXIT /B %result%
:rundemo
%PYTHON% demo.py
set result=%errorlevel%
IF %result% NEQ 0 (pause)
EXIT /B %result%
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