CMake is a cross platform, open-source build system consists of tools designed to build, test, and packaging software. It used to control the software compilation process using simple platform and compiler independent configuration files.
In general, CMake generates native makefiles and workspaces that can be used in the chosen compiler environment.
In this article, we will discuss about how to install CMake, either binary or from sources. The method we use here is generic way, which means, it can be applied to any Operating System. However, for demonstration I will use following machine:
- Slackware64 14.0 Linux
- GCC (Compiler)
At least you have privileges for installing the files later.
Obtain the Materials
As I use Linux I would download source code (http://www.cmake.org/files/v2.8/cmake-22.214.171.124.tar.gz) and unfortunately no binary for Linux x64 so we download this binary (http://www.cmake.org/files/v2.8/cmake-126.96.36.199-Linux-i386.sh). If you want to download for Windows version, go grab source code (http://www.cmake.org/files/v2.8/cmake-188.8.131.52.zip) and binary (http://www.cmake.org/files/v2.8/cmake-184.108.40.206-win32-x86.exe)
Assuming we download shell archive cmake-220.127.116.11-Linux-i386.sh.
Make sure the file is executable (having +x permission). Do following if you want to set the permission:
chmod +x cmake-18.104.22.168-Linux-i386.sh
Then execute it from terminal
Make sure you have privileges to do installation.
Binary installation for Windows system is similar. Just execute the application to initiated installation.
Source Code Compilation & Installation
There are two case for compilation, whether you have CMake or not installed in your system. If you have CMake, we can use CMake to build CMake. However, we can also build it from scratch. Either way we should extract the sourcecode from. A simple way is using command:
tar -xf cmake-22.214.171.124-Linux-i386.tar.gz cd cmake-126.96.36.199
This case will describe compilation from scratch and suitable for us who either don’t have CMake installed before or just want to compile it from scratch.
We need a compiler and a make utility and running UNIX/Mac OSX/MinGW/MSYS/Cygwin.
Run the bootstrap script in the source directory of CMake. If CMake is going to be installed on particular path, use –prefix. For this example I use /usr/local as my base path.
./bootstrap --prefix=/usr/local make make install
Unfortunately for Windows user who didn’t use Cygwin, you can’t do this method. Instead, you should download the binary version of CMake.
Build With CMake
Building CMake with CMake is like building any CMake-based project. Run CMake to the root of cmake directory (e.x: ~/cmake-188.8.131.52).
cd ~/cmake-184.108.40.206 cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local . make make install
Notice the “.” (dot) in the trail, that’s part of command.
At this point, we have successfully install CMakeunix