Binary Directory and Source Directory in CMake ( In source builds and out-of-tree builds – OpenCV )

CMake is quite extensively used for building cross platform libraries and packages like opencv etc. When using CMake we usually come across terms as in-source and out-of-tree builds.

When we call a cmake build command we do so by giving source directory and optionally the build directory as configuration parameter.

here we give the cmake the parameter of source directory which is the parent directory ( ” .. ” ). So the current directly is the build directory and the .. directory is the source directory.

if we add a line like

in the CMakeLists.txt file. we can see the the status message printed as below.

Now the current directory is build directory and supplied ( .. ) is different than current directory and is the source directory.

If both these BUILD and SOURCE directories are same in a build environment its referred to as in-source builds. These type of builds are not allowed in OpenCV. If the two of these dirs refer to different folders you are building it out of the source tree directory. (referred to as out-of-tree build)

Leave a Reply