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

Search for a command to run...

No comments yet. Be the first to comment.
Remember my post about switching to VSCode? Well, plot twist: the very next day after publishing it, I switched to WebStorm. And guess what? I've been on JetBrains IDEs ever since. I know, I know. Another "why I switched editors" post. But hear me ou...

I had been doing some basic interpreter work in Go and wanted to redo it in another language to solidify my understanding. Naturally, I chose Odin, it’s another great language, with a Go-like, easy-to-approach syntax and no unnecessary complexity. I ...

Why Emacs Keybindings? I've always preferred Emacs-style editing, especially the way it handles cursor movement and text manipulation. Even though I have switched to using VSCode for most of my development work, I often found myself missing the intui...

In my previous post about building C/C++ projects with CMake, I shared a simple CMakeLists.txt setup for compiling a basic project. Today, I’ll dive into a specific need that many developers encounter: linking libraries directly from project folders ...

Some time ago, I wrote a post about using Vim to look cool and why that’s not a good idea. Now, funny enough, here I am—having switched to VSCode after years of hopping between Vim and Emacs. This isn’t one of those "Vim sucks, I'm going back to VSCo...

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
project(Game)
# list all the source files next to the executable name
add_executable(Game main.c)
# Add this line if cmake complains about not being able to find your library (in this case raylib)
find_package(raylib)
# 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