Building c or c++ projects is not that hard (with cmake)

Building c or c++ projects is not that hard (with cmake)

One of the main reasons for a lot of people to give up learning c or c++ is it's hard to figure out the build system. This is a problem that both new and experienced developer face alike.

I used to use gnu make by writing my Makefile(s) by hand, and I have tried a little bit of premake which is a build system written in Lua. I knew that cmake should be the easiest solution, but I always found it very intimidating to learn how to use cmake.

So here's the simplest cmake file you can create.

(this content should go into a file called CMakeLists.txt)

# Specify the minimum version of cmake to use
cmake_minimum_required(VERSION 3.0)

# Specify the name of the executable

# list all the source files next to the executable name
add_executable(Game main.c)

# Add any external dependencies
target_link_libraries(Game raylib)

you can build your project in a build folder by issuing the following commands in the terminal.

$ mkdir build
$ cd ./build
$ cmake ..
$ make