What Is CMake?

CMake is an open-source application that allows you to build, test, and package software written in C and C++. It uses scripts called CMakeLists to generate build files on both Unix and Windows systems. This differs from GNU make, which is limited in the platforms it runs on, can be complicated to work with on large projects and doesn’t have a GUI.

How to Install CMake

Installing CMake is easy. However, the method is scattered. Here you will find all the information compiled concisely.

Prerequisites

You need a C++ compiler, and Clang and GCC are both great options. You can even build your own compiler if you’re skilled enough. The commands to install the compilers mentioned are as follows: Clang: GCC: The three application sets for Clang should install the Clang application set, LLVM debugger (lldb) and LLVM linker (lld). Build essential is the GCC set of tools.

1. VS Code Integration

VS Code (Visual studio code) is the primary IDE for many programmers. The add-ons and terminal make it easy to install additional languages and tools. Integrating CMake into VS code is ideal and one of the best ways to use this tool. First, install VS code if you haven’t already. The application is available in the snap store and on the website. Next, install the C/C++, CMake and CMake tool add-ons. Access the extensions using the keyboard shortcut Ctrl + Shift + X or by clicking the extensions tab on the left toolbar. Check whether CMake or any other tools are installed using the –version command in the terminal.

2. Standalone Application

If you prefer using a different text editor, CMake can be installed as a standalone application as well. It is available in the Snap store and on the CMake website. You will find the shell script and the source code if you want to build and contribute on the website. To install via the shell script, you need to allow it to execute as a program. You can do this by changing the permissions in the file manager or using the following command: You should be able to input the file path in the terminal and execute the script. The script will extract the CMake files to the location you select. You’ll find the CMake application in the bin folder.

How to Configure CMake

The lack of documentation can make CMake difficult to use for people new to programming or even senior software engineers. Configuring CMake depends on your project at the time, but generally, select your C++ compiler and linker in the GUI. You can also configure it in the terminal using the following command: Once you’ve set up your configuration, you can generate build files with the GUI or the cmake –build command. This will build the source code binaries. Next, make these files accessible to the user with header files, libraries, and executables by using the terminal command, cmake –install. If you’re working within VS code, you can use the –target install command. Depending on what you’ve written in the makefile, organize the files into one or more executables. If you’re using an older version of CMake, you should use make install. Image credit: Needpix. All screenshots by Nathan Meyer.