Coding Literature A Blog about C++ and everything.

CMake

CMake is an open source cross platform tool to build software projects. CMake generates build pipeline for the platform, which is then used to build the project. In simpler language, CMake generates files required to build the project. For a C++ project, the output of CMake is a build pipeline which can be anything from a Visual Studio Project to Linux Makefiles, based on the selected generator.

CMake introduces a lot of complexity into the build system but fear not as this complexity is abstracted from the user. A user is never expected to modify the generated build pipeline.

To use CMake, a CMakeLists.txt file is required in the source directory of the project. This file contains all the build instructions. A recommended way to build a project is to create a new directory named build, which is different from the source directory. From the build directory, execute cmake <Source Directory>

This will generate a build pipeline. For the sake of simplicity, let’s assume we are on a linux machine, and the build pipeline generated is a Makefile. Generating build pipeline in a seperate build directory have the advantage of seperating the build files from project source files. All the build artifacts are in this directory, and can be deleted for cleanup.

The most basic CMake for a project is:

cmake_minimum_required(VERSION 2.9)
project(BasicProject)
add_executable(BasicProject, main.cpp)

Some Interesting Cmake Command Arguments

  • cmake <source directory> -p runs the script but don’t generate a pipeline.
  • cmake <source directory> -j n, runs the build process on n threads in parallel, if possible.

CMake is more like a scripting language and is very flexible. Let’s go over the basic building blocks of CMake Scripting.

message

message("Building Core library.") message prints the message. Very useful for printing status messages.

Variables

Every varible in CMake is a string. A variable is reference by specifying the name of variable in ${}. This is also known as variable reference. Variables can be set by:

  • Set command set (Number, 42) This sets the variable Number to 42. The statement message("The Ultimate Answer is ${Number}") prints The Ultimate Answer is 42.
  • Varibles can be defined on command line $ cmake -DNumber 42 Quotes around arguments are optional as long as there are no spaces or reference variable.

Flow Control

Cmake supports if statement and while loop.

    if(Linux)
      message("Building on Linux")
    endif()
    while(num LESS 42)
      message("Number is still less than 42.")
   endwhile()

Including Scripts

include ( <FileName.cmake> ) command is used to load and execute CMake from other the file provided. This is generally used to find third party packages. For example, a project using Boost, may have include (Boost.cmake) which can be used to find boost installation before building.

add_subdirectory ( <source subdirectory> ) creates a new scope and executes the CMakeLists.txt from the subdirectory.

Include Directories

To set up the include directories include_directories ( <directoryName> ) is used.

Libraries

To set up the link library directories (just like LD_LIBRARY_PATH) link_directories ( <directoryName> ) is used.
And to link libraries, target_link_libraries( <target> PRIVATE "lib1.a lib2.a")

Targets

add_executable, add_library, add_custom_target commands defines targets. For example,

  add_executable (MyBinary, MyBinary.cpp)         \\Creates binary named MyBinary
  add_executable (CoolStuffBinary, CoolStuff.cpp) \\Creates binary named MyBinary
  add_library (MySharedLib, SHARED, SharedLibCode.cpp)  \\Creates Shared library named MySharedLib.so
  add_library (MyStaticLib, STATIC, SharedLibCode.cpp)  \\Creates Shared library named MyStaticLib.a

Here CMake creates build targets for each executable. By default an all target is also created is executed if no specific target is specified.

pending stuff about custom_target

Custom Commands

pending explanation

A self-explanatory CMakeLists.txt Example


Scratching the Surface

There is so much more in CMake, that this post can barely scratch the surface. Some other interesting features in cmake include generators, regular expressions etc.

Future of Information Technology

Future Technologies will put this world on the tip of a pen - small, precise and in the access of everyone, anywhere, anytime. In a few not years but days, Cloud Computing and Virtual Reality will change the way we use computing resources and will give rise to new ways to interact with and use machines. Cloud Computing will led to cloud (internet) based synchronized computing and Virtual Reality will give rise to virtual worlds – world of imaginations. Virtual meetings will led us to pass emotions and shake hands while on a phone call. Semantic Web, Machine Vision, Exocortices, Memristor, 3D Display would give machines their individual identity. On the other side evolution of Information Technology will be led to human evolution mostly characterized by Brain Technologies that will supplement a human in every aspect. Intelligent embedded systems would supplement human memory. Use of Nanotechnology for trans-humanism will evolutionize a Homo-Sapiens to a Homo-Technicus hoping the Future predictions not to be dystopian.

Nobody Really Uses an Operating System

The title looks quite contriversial. But in my life, I have never seen anbody using an Operating System.

As wikipedia says,”An operating system (OS) is a software, consisting of programs and data, that runs on computers and manages the computer hardware and provides common services for efficient execution of various application programs”.

People uses programs and the only mission of an operating system is to provide a platform and help those programs to run. So here comes the Kernel. An operating system never does anything on its own. It’s always waiting for the programs to ask for certain resources, certain services, certain files or for programs to connect to the outside world and then steps in to make it easy for people to write programs.

God

God is Omnipresent.
God is Eternal.
God is Omnipotent.
God is Immense.
God is the Creator and the Destructor.

Very obviously. This list will never end.

Except for a few atheist, everyone will agree that nothing exists in this universe that is beyond God.

But being a computer science student(we study mathematics too), always felt a need for a complete mathematical, logical and unambiguous definition of God. The definition being taught by my mother doesn’t seem to be accepted by the Turing Machine.

Study of the dimensions gave me a definition of God that can be treated mathematically in the form of equations.

We live in a beautiful world. Every object we see is perceived as a three dimensional object. But are you sure it’s actually a 3-dimensional? Well, I don’t think so.

Flatland: A Romance of Many Dimensions (a short novel) can take you to a world where you can’t jump, you don’t have a food-pipe. In fact everything there is two dimensional. The only allowed movements there are left right, forward, backward. But we are God for them. We can look there whole world at a time. We can lift there world. We can remove money from there safes without opening. This is all because the flatlanders being 2-dimensional creatures can see and visualize only 2-dimensional objects. They can only see a shadow like structure of us that too in their two dimensional world.

So there exists infinite number of two dimensional worlds in a 3d world.

Copying the analogy to our world we can think of 4d creatures that can see the whole earth at a time. And we can only see the 3-d shadow of the supernatural 4d. Visualization of 4d will give you supernatural powers we always want to. Invisibility, time travel, passing through walls..everything is possible there..

So an nth dimensional creature would have supernatural powers in (n-1)th dimensional world.

Using the principle of mathematical induction..we can have an infinite-dimensional being who can control, construct, destruct all other dimensions and worlds unvisualized by all other dimensions. The ∞-dimensional being is no one but God. The dimensions let Him to be omnipresent, supernatural, unrealizable, shapeless and the rest you can get from any priest.

I’ve heard that understanding God is to understand yourself. God lies within you. God is above all.And God may be definitionless because God may be dimensionless.

May God bless you all.