Installing CMake

Let's learn about installing CMake on different platforms

CMake is a cross-platform, open-source software written in C++. That means you can, of course, compile it yourself; however, the most likely scenario is that you won't have to. This is because precompiled binaries are available for you to download from the official web page.

Unix-based systems provide ready-to-install packages directly from the command line.

Note: Remember that CMake doesn't come with compilers. If your system doesn't have them installed yet, you'll need to provide them before using CMake. Make sure to add the paths to their executables to the PATH environment variable so that CMake can find them.

To avoid solving tooling and dependency problems while learning from this course, we recommend choosing the first installation method: Docker.

Let's go through different environments in which CMake can be used.

Docker

Docker is a cross-platform tool that provides OS-level virtualization, allowing applications to be shipped in complete packages called containers. These are self-sufficient bundles that contain a piece of software with all of its libraries, dependencies, and tools required to run it. Docker executes its containers in lightweight environments that are isolated from one another.

This concept makes it extremely convenient to share whole toolchains, which are necessary for a given process, configured and ready to go. We can't stress enough how easy things become when you don't need to worry about minuscule environmental differences.

The Docker platform has a public repository of container images that provides millions of ready-to-use images. For your convenience, the author has published two Docker repositories:

  • swidzinski/cmake:toolchain: This contains the curated tools and dependencies that are necessary to build with CMake.

  • swidzinski/cmake:examples: This contains the preceding toolchain and all of the projects and examples from this book.

The first option is for readers who simply want a clean-slate image ready to build their own projects, and the second option is for hands-on practice with examples as we go through the chapters.

You can install Docker by following the instructions from its official documentation. Then, execute the following commands in your terminal to download the image and start the container:

Get hands-on with 1200+ tech skills courses.