CMake, or Visual Studio projects? Which is easier? Which is better? Which should you use? Lets answer those questions by building some actual code
Here’s what I’m going to do:
- I’ll build the same code using both build systems
- And, I’ll try to get both build systems to do roughly the same thing, within reasonable limits
To be clear, I mean using Visual Studio Projects, and not the nmake build tool. That’s because most people use projects. And I’m not sure how many people even know that nmake exists.
Watch the video above to see how it went…
In Brief
The two small projects were:
- A simple project demonstrating how to build software from multiple source files (taken from The CMake Tutorial)
- Another “hello world” program that uses version 4.5.0 of the raylib library. The CMake script automatically fetches raylib from the internet and builds it if needed
NOTE: The code for these projects (and a lot more) can be downloaded from the Kea Campus (Creator and higher tiers).
Both projects were very easy to build with Visual Studio. Visual Studio projects are very beginner friendly because you use a GUI to create the project. That way you can focus on learning C/C++ instead of learning a build system scripting language.
However, Visual Studio projects also have their downsides:
- Firstly, you’re limited to Visual Studio, which is fine if you only want your software to run on Windows, but is a problem if you want to write software that works on multiple platforms. Yes, I’m aware that you *can* use Visual Studio to cross-compile code for other platforms, but that’s not as easy as building Windows apps. And why would you restrict yourself and your team like that? CMake allows you to use whatever editor and compiler you want. In fact, I used Visual Studio’s compiler to build the code even when I was using CMake
- Secondly, VS Projects aren’t as flexible as a build script. That’s probably why Visual C++ comes with NMake. We experienced this in a minor way when we couldn’t get the Raylib library that we wanted via NuGet. It didn’t matter in this case, but other times it can get frustrating
Visual Studio Projects are a great way to get started, but I recommend learning how to use a build system like CMake. At least, if you’re serious about writing C/C++ software. Writing a script like this one is pretty easy once you know how, and it’s way more flexible.
To help you with that, I wrote The CMake Tutorial. The tutorial takes you from zero CMake knowledge, through to everything you need to build large projects. It’s the book/course that I wish existed back when I was getting started. Head over to cmaketutorial.com, and get it there.
NOTE: This is part of a series comparing C/C++ build systems. Click here to compare more build systems.