Repository: opencv
Issue: ocv_download() "optional" behavior leads to different unclear error messages
Labels: bug,category: build/install

It should "fail fast" by default providing clear messages.
Optional mode doesn't properly work anyway (including xfeatures2d issues).

[Example](http://pullrequest.opencv.org/buildbot/builders/precommit_opencl/builds/19333/steps/cmake/logs/stdio):
```
-- The CXX compiler identification is MSVC 19.0.24215.1
-- The C compiler identification is MSVC 19.0.24215.1
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- AVX_512F is not supported by C++ compiler
-- AVX512_SKX is not supported by C++ compiler
-- Dispatch optimization AVX512_SKX is not available, skipped
-- libjpeg-turbo: VERSION = 1.5.3, BUILD = opencv-4.0.1-dev-libjpeg-turbo
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- A library with BLAS API not found. Please specify library location.
-- LAPACK requires BLAS
-- A library with LAPACK API not found. Please specify library location.
-- Found apache ant: C:/utils/soft/apache-ant-1.9.7/bin/ant.bat (1.9.7)
-- Could NOT find Pylint (missing:  PYLINT_EXECUTABLE) 
-- Could NOT find Flake8 (missing:  FLAKE8_EXECUTABLE) 
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- OpenCV Python: during development append to PYTHONPATH: C:/build/precommit_opencl/build/python_loader
You have called ADD_LIBRARY for library ade without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16 (include):
  include could not find load file:

    C:/build/precommit_opencl/build/3rdparty/ffmpeg/ffmpeg_version.cmake
Call Stack (most recent call first):
  modules/videoio/cmake/init.cmake:3 (include)
  modules/videoio/cmake/init.cmake:22 (add_backend)
  cmake/OpenCVModule.cmake:312 (include)
  cmake/OpenCVModule.cmake:375 (_add_modules_1)
  modules/CMakeLists.txt:7 (ocv_glob_modules)


-- Caffe:   NO
-- Protobuf:   NO
-- Glog:   NO
-- freetype2:   NO
-- harfbuzz:    NO
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
-- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
-- Excluding from source files list: modules/imgproc/src/sumpixels.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
Error copying file (if different) from "C:/build/precommit_opencl/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll" to "C:/build/precommit_opencl/build/bin/Debug/opencv_ffmpeg401_64.dll".

Error copying file (if different) from "C:/build/precommit_opencl/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll" to "C:/build/precommit_opencl/build/bin/Release/opencv_ffmpeg401_64.dll".

-- Tesseract:   NO
CMake Warning at C:/build/precommit_opencl/opencv/cmake/OpenCVModule.cmake:679 (message):
  Unexpected include: C:/build/precommit_opencl/build/downloads/xfeatures2d
  (module=opencv_xfeatures2d)
Call Stack (most recent call first):
  C:/build/precommit_opencl/opencv/cmake/OpenCVModule.cmake:710 (ocv_target_include_modules)
  C:/build/precommit_opencl/opencv_contrib/modules/xfeatures2d/CMakeLists.txt:14 (ocv_module_include_directories)


-- OpenCL samples are skipped: OpenCL SDK is required
-- 
-- General configuration for OpenCV 4.0.1-dev =====================================
--   Version control:               4.0.1-250-g11e367a
-- 
--   Extra modules:
--     Location (extra):            C:/build/precommit_opencl/opencv_contrib/modules
--     Version control (extra):     4.0.1-35-gca7cb77
-- 
--   Platform:
--     Timestamp:                   2019-02-25T17:08:40Z
--     Host:                        Windows 10.0.17134 AMD64
--     CMake:                       3.7.0
--     CMake generator:             Visual Studio 14 2015 Win64
--     CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
--     MSVC:                        1900
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (7 files):          + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (18 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.24215.1)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /MD /O2 /Ob2 /DNDEBUG 
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 
--     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4    /MD /O2 /Ob2 /DNDEBUG 
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4  /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO 
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc java java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 python_bindings_generator quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf js matlab ovis sfm viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         YES
-- 
--   Windows RT support:            NO
-- 
--   GUI: 
--     Win32 UI:                    YES
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        build-libjpeg-turbo (ver 1.5.3-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         build (ver 1.6.36)
--     TIFF:                        build (ver 42 - 4.0.10)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      NO
-- 
--   Parallel framework:            Concurrency
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                C:/build/precommit_opencl/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 2:
--     Interpreter:                 C:/utils/soft/python27-x64/python.exe (ver 2.7.12)
--     Libraries:                   C:/utils/soft/python27-x64/Libs/python27.lib (ver 2.7.12)
--     numpy:                       C:/utils/soft/python27-x64/lib/site-packages/numpy/core/include (ver 1.12.0)
--     install path:                python/cv2/python-2.7
-- 
--   Python 3:
--     Interpreter:                 C:/utils/soft/python35-x64/python.exe (ver 3.5.2)
--     Libraries:                   C:/utils/soft/python35-x64/Libs/python35.lib (ver 3.5.2)
--     numpy:                       C:/utils/soft/python35-x64/lib/site-packages/numpy/core/include (ver 1.12.0)
--     install path:                python/cv2/python-3.5
-- 
--   Python (for build):            C:/utils/soft/python27-x64/python.exe
-- 
--   Java:                          
--     ant:                         C:/utils/soft/apache-ant-1.9.7/bin/ant.bat (ver 1.9.7)
--     JNI:                         C:/Program Files/Java/jdk1.8.0_112/include C:/Program Files/Java/jdk1.8.0_112/include/win32 C:/Program Files/Java/jdk1.8.0_112/include
--     Java wrappers:               YES
--     Java tests:                  YES
-- 
--   Install to:                    C:/build/precommit_opencl/build/install
-- -----------------------------------------------------------------
-- 
-- Configuring incomplete, errors occurred!
See also "C:/build/precommit_opencl/build/CMakeFiles/CMakeOutput.log".
See also "C:/build/precommit_opencl/build/CMakeFiles/CMakeError.log".
```