Month: August 2016

Beginning with CMake

I and Gagan was trying to make program in CMake. We have done it in three ways.

The basic purpose of doing it in 3 ways was to familiar more with CMake.

First Method(Single cpp file)

I have created two files “test.cpp” and “CMakeLists.txt”



Syntax of cmake:-

command(variable value)

project command gives the name to the project.

include_directories command will include the directories in the project.

Execute commands in the source directory.

cmake .


./bin/hello #executable file(i.e hello) is in the  bin directory.

First method is done.

In real world programming, in order to hide our algorithm we abstract our code by making set of files. It also provides reusability of code.

Second method(independent of first method)

In this, I have created four files overall. they are “hello.h”, “hello.cpp”, “test.cpp”, “CMakeLists.txt”.





means commenting the statement. You all might know.

Third Method

In the third method there are three directories i.e. source directory and two subdirectories(sub and test). Sub directory contain the files “hello.cpp” and “hello.h”.

There is a file named “CMakeLists.txt” in each directory.


Executable file is in the test directory.



Basics of Programming Language

Basics of Programming Language

Initially, I was confused between the terms build and compile. Today, I understood the exact meaning of it.

Compiling is the act of turning source code into object code or it simply converts cpp files to .0(object) files.

Linking is the act of combining object code with libraries into a raw executable.

Building is the sequence composed of compiling, linking and execute the code

The executable is loaded from the disk to memory and the computer’s processing unit (Central Processing Unit) executes the program one instruction at a time.

For learning cmake you should know the meaning of above terms. So if not got yet read it again. I am waiting.

Done?  Now let’s move to the preamble part of cmake.

What is cmake?

cmake means cross-platform make.

cmake takes information on how to build programs generates makefiles that build the program. Hence cmake is a language with abstract build rules and gnu make is a dependency resolves that executes programs on a directed acyclic graph traversal

Therefore whenever you’re writing cmake files, you have to think whether a command should apply during generation time, or during build time not same case in make. Think it Why?  You may reply to me also;)

CMake is a language(for generator of build systems) with abstract build rules and gnu make is a dependency resolves that executes programs on a directed acyclic graph traversal.

CMake itself also provides some nice features like dependency detection, library interface management, or integration with CTest, CDash and CPack.


sudo apt-get install cmake

Done. Very easy installation.

Few Commands

cmake <source_directory>

The above command basically setup your build environment. This creates a makefile  depending on the build system of your choice. The build system can be passed to CMake as a parameter. However, CMake makes reasonable default choices depending on your system configuration. Second, you perform the actual build in the selected build system.”

set(<variable> <value1> ... <valueN>)

set command set the variable with the given  values.


pdf on cmake