CMake - Hello World

 

Key Concepts:

First let's look at how to set up a simple Hello World program.

Hello World

To set up a Hello World program setup 2 files in a clean directory somewhere on your computer. CMakeLists.txt and main.cpp. We will be leaving main.cpp blank for now. CMakeLists.txt will contain 3 simple lines of code to start: 

cmake_minimum_required(VERSION 2.8.9)

project (Hello)

add_executable(helloworld main.cpp)

These lines set up a Hello Solution with one executable project named helloworld. This executable project contains a single source file: main.cpp.  You can now Configure and Generate your project.

I normally set up a build directory so that all the project files go to a particular directory away from my source code. This is highlighted below.

Now you can browse for the hello.sln file in your directory and open it.

cmake.png