Using CMake to build your software

You can use CMake to build your software. Inside the CVK demos zipfile, there is now a setup_opencv.cmake file which tells CMake where to find your OpenCV libraries and include files, as well as a CMakeLists.txt file, which defines what software should get built.

The CMakeLists.txt file for the CVK demos looks like this:
cmake_minimum_required(VERSION 2.6)

include(setup_opencv.cmake)

add_library(cvk cvk.cpp)

add_executable(cvkdemo cvkdemo.cpp)
target_link_libraries(cvkdemo cvk)
add_opencv_libs(cvkdemo)

# more executables, similar to cvkdemo, follow... 
The include line above tells CMake to execute the commands in setup_opencv.cmake. Then we add a target (an item to build) corresponding to the cvk library itself (which is used by cvkdemo and the other programs). Finally, we add each executable program as a separate target. For each one, we add the OpenCV library dependencies to the program, and also add the cvk dependency as well.

Building your software with CMake works differently in Windows and on Mac/Linux.

Windows

Install CMake by downloading and running the Win32 installer from this page. If prompted, make sure to add CMake to the system path for all users.

Open up a command prompt by typing "cmd.exe" into the Start menu. Navigate to the directory your project is located in, and type the following:
mkdir build
cd build
cmake -G "Visual Studio 10" ..
This will create a Visual Studio project file in the build directory called "Project.sln". You can open it by typing
start Project.sln
if prompted, choose the Visual Studio 2010 Express option when asked what application to use to open the file. You can then build all of the programs in the project by hitting F7 or selecting Build from the menu.

The example programs are best run from the command prompt since they require command line arguments. If you are still in the command prompt inside the build directory, you can type
cd ..
build\Debug\regions.exe screws_thresholded.png
to run the regions example. The programs will be placed in build/Debug, build/Release, etc., depending on the Visual Studio configuration.

You can create a new project by copying the cvk.h, cvk.cpp, and setup_opencv.cmake files into a new directory, and composing your own CMakeLists.txt file.

Mac OS/Linux

First install cmake. On Mac OS X, with Macports:
sudo port install cmake
Or, in Ubuntu:
sudo apt-get install cmake
Then you can make a build directory and build the software there. Open a terminal, navigate to the directory where CMakeLists.txt lives, and type
mkdir build
cd build
cmake ..
make
to build the software. To run the software, you can navigate back up a directory and execute the programs from the terminal.
cd ..
./regions screws_thresholded.png

You can create a new project by copying the cvk.h, cvk.cpp, and
setup_opencv.cmake files into a new directory, and composing your own
CMakeLists.txt file.

Last modified: Thursday, August 8, 2013, 8:01 PM