mirror of https://github.com/opencv/opencv.git
commit
dada5a422d
32 changed files with 611 additions and 146 deletions
@ -1,6 +1,6 @@ |
||||
set(MIN_VER_CMAKE 3.5.1) |
||||
set(MIN_VER_CUDA 6.5) |
||||
set(MIN_VER_PYTHON2 2.6) |
||||
set(MIN_VER_PYTHON2 2.7) |
||||
set(MIN_VER_PYTHON3 3.2) |
||||
set(MIN_VER_ZLIB 1.2.3) |
||||
set(MIN_VER_GTK 2.18.0) |
||||
|
@ -0,0 +1,42 @@ |
||||
# cmake needs this line |
||||
cmake_minimum_required(VERSION 3.1) |
||||
|
||||
if(NOT DEFINED EXAMPLE_NAME) |
||||
message(FATAL_ERROR "Invalid build script: missing EXAMPLE_NAME") |
||||
endif() |
||||
if(NOT DEFINED EXAMPLE_FILE) |
||||
message(FATAL_ERROR "Invalid build script: missing EXAMPLE_FILE") |
||||
endif() |
||||
|
||||
file(TO_CMAKE_PATH "${EXAMPLE_FILE}" EXAMPLE_FILE) |
||||
message(STATUS "Project: ${EXAMPLE_NAME}") |
||||
message(STATUS "File : ${EXAMPLE_FILE}") |
||||
|
||||
# Enable C++11 |
||||
set(CMAKE_CXX_STANDARD 11) |
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
||||
|
||||
|
||||
# Define project name |
||||
project(${EXAMPLE_NAME}) |
||||
|
||||
# Find OpenCV, you may need to set OpenCV_DIR variable |
||||
# to the absolute path to the directory containing OpenCVConfig.cmake file |
||||
# via the command line or GUI |
||||
find_package(OpenCV REQUIRED) |
||||
|
||||
# If the package has been found, several variables will |
||||
# be set, you can find the full list with descriptions |
||||
# in the OpenCVConfig.cmake file. |
||||
# Print some message showing some of them |
||||
message(STATUS "OpenCV library status:") |
||||
message(STATUS " config: ${OpenCV_DIR}") |
||||
message(STATUS " version: ${OpenCV_VERSION}") |
||||
message(STATUS " libraries: ${OpenCV_LIBS}") |
||||
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") |
||||
|
||||
# Declare the executable target built from your sources |
||||
add_executable(${EXAMPLE_NAME} "${EXAMPLE_FILE}") |
||||
|
||||
# Link your application with OpenCV libraries |
||||
target_link_libraries(${EXAMPLE_NAME} ${OpenCV_LIBS}) |
@ -0,0 +1,180 @@ |
||||
:: Usage: |
||||
:: - Drag & drop .cpp file on this file from Windows explorer |
||||
:: - Run from cmd/powershell: |
||||
:: - > _winpack_build_sample.cmd cpp\opencv_version.cpp |
||||
:: Requires: |
||||
:: - CMake |
||||
:: - MSVS 2015/2017 |
||||
:: (tools are searched on default paths or environment should be pre-configured) |
||||
@echo off |
||||
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION |
||||
|
||||
set SCRIPTDIR=%~dp0 |
||||
if NOT exist "%SCRIPTDIR%\..\..\build" ( |
||||
set "MSG=OpenCV Winpack installation is required" |
||||
goto die |
||||
) |
||||
|
||||
if [%1]==[] ( |
||||
set "MSG=Sample path is required" |
||||
goto die |
||||
) |
||||
if exist %1\* ( |
||||
set "MSG=Only .cpp samples are allowed (not a directory): %1" |
||||
goto die |
||||
) |
||||
if NOT "%~x1" == ".cpp" ( |
||||
set "MSG=Only .cpp samples are allowed: %~x1" |
||||
goto die |
||||
) |
||||
set SRC_FILENAME=%~dpnx1 |
||||
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 ================================================================================ |
||||
|
||||
:: Path to FFMPEG binary files |
||||
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\bin\" |
||||
|
||||
:: 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 ( |
||||
echo CMake is detected |
||||
) |
||||
|
||||
:: Detect compiler |
||||
cl /? >NUL 2>NUL <NUL |
||||
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" |
||||
) else ( |
||||
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" ( |
||||
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" |
||||
) else ( |
||||
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" ( |
||||
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 |
||||
) |
||||
) |
||||
) |
||||
POPD |
||||
cl /? >NUL 2>NUL <NUL |
||||
if !ERRORLEVEL! NEQ 0 ( |
||||
set "MSG=ERROR: Can't detect Microsoft Visial Studio C++ compiler (cl.exe). MSVS 2015/2017 are supported only from standard locations" |
||||
goto die |
||||
) |
||||
) |
||||
|
||||
:: 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" ( |
||||
set CMAKE_GENERATOR="Visual Studio 14 Win64" |
||||
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc14\bin\" |
||||
) else ( |
||||
if "!VisualStudioVersion!" == "15.0" ( |
||||
set CMAKE_GENERATOR="Visual Studio 15 Win64" |
||||
set "PATH=!PATH!;!SCRIPTDIR!\..\..\build\x64\vc15\bin\" |
||||
) else ( |
||||
set "MSG=Unsupported MSVS version. VisualStudioVersion=!VisualStudioVersion!" |
||||
goto die |
||||
) |
||||
) |
||||
|
||||
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" |
||||
|
||||
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!" |
||||
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!" |
||||
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" |
||||
) else ( |
||||
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 '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 Done: !SRC_NAME! |
||||
echo Opening build directory with project files... |
||||
explorer "!BUILD_DIR!" |
||||
|
||||
POPD |
||||
echo Done! |
||||
|
||||
pause |
||||
exit /B 0 |
||||
|
||||
|
||||
:: |
||||
:: Helper routines |
||||
:: |
||||
|
||||
:set_title |
||||
title OpenCV sample: %* |
||||
EXIT /B 0 |
||||
|
||||
:execute |
||||
echo ================================================================================= |
||||
setlocal enableextensions disabledelayedexpansion |
||||
echo %* |
||||
call %* |
||||
endlocal |
||||
EXIT /B %ERRORLEVEL% |
||||
|
||||
:dirname file resultVar |
||||
setlocal |
||||
set _dir=%~dp1 |
||||
set _dir=%_dir:~0,-1% |
||||
endlocal & set %2=%_dir% |
||||
EXIT /B 0 |
||||
|
||||
:: 'goto die' instead of 'call' |
||||
:die |
||||
TITLE OpenCV sample: ERROR: %MSG% |
||||
echo ERROR: %MSG% |
||||
pause |
||||
EXIT /B 1 |
Loading…
Reference in new issue