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:-
project command gives the name to the project.
include_directories command will include the directories in the project.
Execute commands in the source directory.
./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.
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.
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 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.
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