Bhanuka Mallawaarachchi
bmax

Follow

bmax

Follow

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

Bhanuka Mallawaarachchi's photo
Bhanuka Mallawaarachchi
·May 21, 2023·

1 min read

Play this article

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.

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

# Specify the name of the executable
project(Game)

# 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
 
Share this