Skip to content

Getting Started With CMake

Are you convinced yet? Well, if you are, that's great! If not, that's understandable. Hopefully you'll stick around because we're getting to the good part now :)

Installation

As mentioned before, CMake is usable on Windows, Mac, and most Linux distributions. Just to keep things brief, we shall link to the offcial downloads page and allow the user to select the right package.

CMake Official Release/Downloads Page

NOTE: At the time of writing, the current CMake version is 3.31.5.

Development Environment Setup

You do not need a specific development environment for CMake. Everything can be done from the command line. With that said, there are some nice features we can take advantage of by using a text editor or IDE. For the most part, the Penn Embedded Group uses VScode but CLion has recently been becoming more popular with out members.

VScode

VScode is an open source text-editor developed by Microsoft that is popular for how customizable it is. It has a staggering amount of language support and thanks to the community support for features and gimmicks outside of software development. Unsurprisingly, theere are extensions for integrating CMake projects with vscode that you may want to take advantage of.

Extensions: - CMake Tools - C/C++

Alternatively, you can install the C/C++ Extension Pack which includes the recommneded CMake tools and some quality of life improvements for working with C/C++ files.

CLion

  • CLion is a cross-platform C/C++ IDE developed by JetBrains. It is not a free tooll but students can get an academic license to allow them to download all the JetBrains tools for free. CLion integrates CMake natively so no configuration is required for the user in order to get started. That said, the interface might take some time to get used to when first using it.

  • Jetbarins Educational Licenses

  • CLion homepage

NOTE: CLion has historically been somewhat CPU and memory intensive. The newest release (CLion Nova) aims to reduce memory footprint and overall CPU usage.

Hello World Project

  • Regardless of what development environment you choose, one of the best ways of learning a tool is actually using it. We'll walk through a simple hello world project and as we progress, we'll introduce and explain more and new CMake concepts and constructs.

  • Using your preferred IDE of choice create a new project

  • In VSCode this can be an empty folder
  • In CLion, this will likely be a C (or C++) executable project

  • If a CmakeLists.txt file does not already exist, add one at the top level of your directory.

Variables

Targets

Libraries

Building

Cmake Cache