ADD_LIBRARY of cmake

In case you are having warning related to ADD_LIBRARY from cmake:

ADD_LIBRARY called with SHARED option but the target platform does not
 support dynamic linking. Building a STATIC library instead. This may lead
 to problems.
This warning is for project developers. Use -Wno-dev to suppress it.
To fix this warning, add following line to CMakeList.txt of the project:
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS "TRUE")
Advertisements

Build/Install OpenCV 3.3.0

Following are instructions of how to build/install OpenCV 3.3.0 on Ubuntu (14.04.5 LTS) based Linux machine.

Installation

Make sure that following packages are installed:

sudo apt-get install build-essential pkg-config checkinstall
sudo apt-get install libjpeg-dev libpng-dev zlib1g-dev libtiff4-dev
sudo apt-get install libtbb-dev libeigen3-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install libv4l-dev v4l-utils
sudo apt-get install python-dev python-numpy python-tk
sudo apt-get install libfreetype6-dev libharfbuzz-dev
sudo apt-get install qt5-default
Make sure that CMake is installed too and it can work with SSL. If you don’t know, you should be using Install cmake with SSL.
sudo apt-get install cmake

Download

mkdir opencv-3.3.0
cd opencv-3.3.0

# Download
wget https://github.com/opencv/opencv/archive/3.3.0.tar.gz -O opencv-3.3.0.tar.gz
wget https://github.com/opencv/opencv_contrib/archive/3.3.0.tar.gz -O opencv_contrib-3.3.0.tar.gz

# Extract source
tar zxvf opencv-3.3.0.tar.gz
tar zxvf opencv_contrib-3.3.0.tar.gz

For ease of development, let’s export some env variables. You should pay attention to OPENCV_INSTALL_DIR. This is a directory where OpenCV will be installed:

export CURRENT_DIR=`pwd`
export OPENCV_SOURCE_DIR=$CURRENT_DIR/opencv-3.3.0
export OPENCV_EXTRA_DIR=$CURRENT_DIR/opencv_contrib-3.3.0
export OPENCV_BUILD_DIR=$CURRENT_DIR/build
export OPENCV_INSTALL_DIR=/usr/local/OpenCV/3.3.0

Build

Setup build directory

mkdir -p $OPENCV_BUILD_DIR

Configure OpenCV

cd $OPENCV_BUILD_DIR

cmake \
 -D CMAKE_BUILD_TYPE=DEBUG \
 -D CMAKE_INSTALL_PREFIX=$OPENCV_INSTALL_DIR \
 -D OpenCV_DIR=$OPENCV_INSTALL_DIR \
 -D INSTALL_C_EXAMPLES=ON \
 -D INSTALL_PYTHON_EXAMPLES=ON \
 -D INSTALL_TESTS=ON \
 -D BUILD_EXAMPLES=ON \
 -D BUILD_TESTS=ON \
 -D WITH_QT=ON \
 -D WITH_OPENGL=ON \
 -D WITH_EIGEN=ON \
 -D WITH_V4L=ON \
 -D BUILD_TBB=ON \
 -D WITH_TBB=ON \
 -D WITH_IPP=ON \
 -D BUILD_opencv_dnn=ON \
 -D BUILD_opencv_python2=ON \
 -D OPENCV_EXTRA_MODULES_PATH=$OPENCV_EXTRA_DIR/modules \
$OPENCV_SOURCE_DIR

Let the CMake to configure OpenCV. Once CMake is done issue

make -j6

Installation

cd $OPENCV_BUILD_DIR
sudo make -j2 install

Configure host machine

Update ldconfig and pkgconfig on the host machine to be aware of the OpenCV 3.3.0

sudo ln -s /usr/local/OpenCV/3.3.0/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig/opencv-3.3.0.pc
sudo ldconfig $OPENCV_INSTALL_DIR/lib

 

Build/Install OpenCV 3.2.0

Following are instructions of how to build/install OpenCV 3.2.0 on Ubuntu (14.04.5 LTS) based Linux machine.

Installation

Make sure that following packages are installed:

sudo apt-get install build-essential pkg-config checkinstall
sudo apt-get install libjpeg-dev libpng-dev zlib1g-dev libtiff4-dev
sudo apt-get install libtbb-dev libeigen3-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install libv4l-dev v4l-utils
sudo apt-get install python-dev python-numpy python-tk
sudo apt-get install libfreetype6-dev libharfbuzz-dev
sudo apt-get install qt5-default
Make sure that CMake is installed too and it can work with SSL. If you don’t know, you should be using Install cmake with SSL.
sudo apt-get install cmake

Download

mkdir opencv-3.2.0
cd opencv-3.2.0

# Download
wget https://github.com/opencv/opencv/archive/3.2.0.tar.gz -O opencv-3.2.0.tar.gz
wget https://github.com/opencv/opencv_contrib/archive/3.2.0.tar.gz -O opencv_contrib-3.2.0.tar.gz

# Extract source
tar zxvf opencv-3.2.0.tar.gz
tar zxvf opencv_contrib-3.2.0.tar.gz

For ease of development, let’s export some env variables. You should pay attention to OPENCV_INSTALL_DIR. This is a directory where OpenCV will be installed:

export CURRENT_DIR=`pwd`
export OPENCV_SOURCE_DIR=$CURRENT_DIR/opencv-3.2.0
export OPENCV_EXTRA_DIR=$CURRENT_DIR/opencv_contrib-3.2.0
export OPENCV_BUILD_DIR=$CURRENT_DIR/build
export OPENCV_INSTALL_DIR=/usr/local/OpenCV/3.2.0

Build

Setup build directory

mkdir -p $OPENCV_BUILD_DIR

Configure OpenCV

cd $OPENCV_BUILD_DIR

cmake \
 -D CMAKE_BUILD_TYPE=DEBUG \
 -D CMAKE_INSTALL_PREFIX=$OPENCV_INSTALL_DIR \
 -D OpenCV_DIR=$OPENCV_INSTALL_DIR \
 -D INSTALL_C_EXAMPLES=ON \
 -D INSTALL_PYTHON_EXAMPLES=ON \
 -D INSTALL_TESTS=ON \
 -D BUILD_EXAMPLES=ON \
 -D BUILD_TESTS=ON \
 -D WITH_QT=ON \
 -D WITH_OPENGL=ON \
 -D WITH_EIGEN=ON \
 -D WITH_V4L=ON \
 -D BUILD_TBB=ON \
 -D WITH_TBB=ON \
 -D WITH_IPP=ON \
 -D BUILD_opencv_python2=ON \
 -D OPENCV_EXTRA_MODULES_PATH=$OPENCV_EXTRA_DIR/modules \
$OPENCV_SOURCE_DIR

Let the CMake to configure OpenCV. Once CMake is done issue

make -j6

Installation

cd $OPENCV_BUILD_DIR
sudo make -j2 install

Configure host machine

Update ldconfig and pkgconfig on the host machine to be aware of the OpenCV 3.2.0

sudo ln -s /usr/local/OpenCV/3.2.0/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig/opencv-3.2.0.pc
sudo ldconfig $OPENCV_INSTALL_DIR/lib

Install cmake with SSL

I was working with CMake and found that pre-built setup was not working with secure websites. After looking into issue, I concluded that I have to build it from source with SSL option.

Here it goes instructions of how to build & install cmake after enabling SSL option. These instructions are tested on Ubuntu (14.04.5 LTS) based Linux machine.

Installation

Make sure that following packages are installed:

sudo apt-get install openssl libssl-dev qt5-default

Download CMake

wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz -O cmake-3.8.2.tar.gz
tar zxvf cmake-3.8.2.tar.gz

Configure

issue following command to enable OpenSSL

cd cmake-3.8.2
sed -i '/cmake_options="-DCMAKE_BOOTSTRAP=1"/c\cmake_options="-DCMAKE_BOOTSTRAP=1 -DCMAKE_USE_OPENSSL=ON"' bootstrap

Build

./configure --qt-gui
make -j6
sudo make install

Installation verification

cmake --version

It should print

cmake version 3.8.2

Tip: cmake-gui should open CMake Qt based Configuration dialog.