From 421fdc0e94c33e81f775e85202fd8a853cb6abbb Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 9 Oct 2018 19:01:29 +0300 Subject: [PATCH] Merge pull request #12636 from alalek:winpack_samples_cpp_build_script * samples: add winpack "drap & drop" build script * samples: add search for MSVS 2017 Enterprise --- samples/CMakeLists.example.in | 42 +++++++ samples/_winpack_build_sample.cmd | 180 ++++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 samples/CMakeLists.example.in create mode 100644 samples/_winpack_build_sample.cmd diff --git a/samples/CMakeLists.example.in b/samples/CMakeLists.example.in new file mode 100644 index 0000000000..1769d4d9cf --- /dev/null +++ b/samples/CMakeLists.example.in @@ -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}) diff --git a/samples/_winpack_build_sample.cmd b/samples/_winpack_build_sample.cmd new file mode 100644 index 0000000000..c671d140fa --- /dev/null +++ b/samples/_winpack_build_sample.cmd @@ -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 2>NUL