.. _cmake_config: Configuring CMake to build OpenCV on Windows ============================================ General procedure ----------------- #. Start the GUI version of CMake (cmake-gui). #. Select the folder :file:`C:\\OpenCV\\sources` as the source directory. #. Select the folder :file:`C:\\OpenCV\\builds` as the build directory. #. Enable the **Grouped** and **Advanced** checkboxes just below the build directory name. These will impact the way the packages information will be displayed in the CMake GUI in the following steps. .. image:: images/cmake_sources_builds.png :alt: CMake sources builds :align: center #. Press the "Configure" button. A window pops up, letting you specify the compiler (and IDE) you want to use. Pick Visual Studio 10, 32-bit or 64-bit according to your **Matlab** version. Select also "Use default native compilers" and click Finish. .. image:: images/cmake_select_generator.png :alt: CMake select generator :align: center .. note:: In case you would like to redo all the steps from the beginning (if you made a mistake somewhere, for instance), you can clear CMake cache in the menu option "File > Delete Cache". #. CMake will start out and based on your system variables will try to automatically locate as many packages as possible. You can modify the packages to use for the build in the WITH > WITH_X menu points (where X is the package abbreviation). #. Configure CMake until all the elements are found. Follow the instructions below. .. note:: If you don't need it, you might want to deactivate the Python module both in 32-bit and 64-bit versions since it might not build correctly. #. Once you are comfortable with your CMake configuration, press Generate and close CMake. Here is an alternate version of those instructions, but it does not goes as deep in the details as this tutorial: http://seevisionc.blogspot.co.uk/2014/03/compiling-opencv-30-with-matlab-support.html. Configuration details --------------------- BUILD group ^^^^^^^^^^^ Activate everything **except**: * BUILD_CUDA_STUBS * BUILD_DOCS * BUILD_OPENEXR * BUILD_TBB * BUILD_WITH_DYNAMIC_IPP * BUILD_opencv_apps * BUILD_opencv_python2 * BUILD_opencv_python3 * BUILD_opencv_ts * BUILD_opencv_world .. note:: For more info about what each OpenCV module does, please visit http://docs.opencv.org/. .. note:: To build the doc, Doxygen must be installed. This is why I disabled it, because the doc is easily accessible online anyway. .. note:: The Python interface does not build properly on my machine, this is why I have disabled both items about Python. However, feel free to enable the one corresponding to your Python installation (python2 or python3). ENABLE group ^^^^^^^^^^^^ Make sure to check ENABLE_SOLUTION_FOLDERS. INSTALL group ^^^^^^^^^^^^^ Check INSTALL_C_EXAMPLES and INSTALL_TESTS. MATLAB group ^^^^^^^^^^^^^ Make sure every field is populated here (should be the case automatically). OPENCV group ^^^^^^^^^^^^ Complete the entry OPENCV_EXTRA_MODULES_PATH with the path to the extra modules: :file:`C:\\OpenCV\\contrib\\modules`. WITH group ^^^^^^^^^^ Activate the following items (15 in total): * WITH_DIRECTX * WITH_DSHOW * WITH_EIGEN * WITH_FFMPEG * WITH_IPP * WITH_JASPER * WITH_JPEG * WITH_OPENCL * WITH_OPENCLAMDBLAS * WITH_OPENCLAMDFFT * WITH_PNG * WITH_TBB * WITH_TIFF * WITH_VFW * WITH_WIN32UI Intel TBB ^^^^^^^^^ Here are instructions adapted from http://stackoverflow.com/questions/16767464/how-to-install-opencv-with-tbb-enabled-using-mingw. #. From CMake, configure one time OpenCV (should already be done). #. Enable "WITH_TBB". .. note:: Be careful NOT enabling BUILD_TBB: the automatic downloading and building of OpenCV failed miserably for me despite many efforts. If you had previously enabled BUILD_TBB, my suggestion is to restart from the beginnning, clearing cmake cache. #. Configure a second time OpenCV. #. Then a new group should appear (in red), named "Ungrouped Entries". If the TBB include directory is not found, this group will have the option "TBB_INCLUDE_DIRS" with the value "TBB_INCLUDE_DIRS-NOTFOUND". #. Click on the value and then on the tiny button "..." appearing on the right-side of the field. Provide the path to the TBB headers, which should be :file:`C:\\OpenCV\\tbb\\include`. #. When done, press the "Configure" button again. #. Now, CMake should have been able to locate the TBB headers (include dir). Therefore, a new group "TBB" should appear in the interface. If it is not the case, then retry to locate the TBB headers. They should lie in some ``include`` directory within the ``tbb`` folder. #. In the "TBB" group, there are two new variables whose default values are correct. Note that the value of TBB_LIB_DIR depends on your compiler. #. The "TBB" group is now complete. Here are the three variables it contains with their values: * TBB_INCLUDE_DIRS: :file:`C:\\OpenCV\\tbb\\include` * TBB_LIB_DIR: :file:`C:\\OpenCV\\tbb\\lib\\intel64\\vc10` * TBB_STDDEF_PATH: :file:`C:\\OpenCV\\tbb\\include\\tbb\\tbb_stddef.h`