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.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s