Using CMake and managing dependencies

submited by
Style Pass
2021-05-24 15:00:04

We’ll go step by step and create a simple project which will have SFML, Dear ImGui and ImGui-SFML as its dependencies. The project will clone these dependencies’ source code from Github and build them. You won’t need to use prebuilt libraries ever again.

I’ll try to explain everything as I go on down to a “basic” things. It’s good to understand everything you do and be able to do it from scratch without any guides. This article will also be a good starting point if you’ve never used CMake before.

If you just want to learn how to manage dependencies with CMake with FetchContent, you can just jump straight to Adding SFML as a dependency section.

The first line sets up a required minimal version of CMake which can be used to build the project. CMake constantly evolves and it’s better to use the latest version for your project as each one brings handy new features, better compiler integration and bug fixes.

If you're writing a library, it's better to stick to the lowest version of CMake that makes sense for you. You can find the version of CMake that is available for various distros here. Another way of choosing is to look at other popular libraries and choose the same version. For example, JSON for modern C++ and fmt use CMake 3.1. I'd recommend using something like CMake 3.8.2 or newer, unless you want to support very old distributions and users who don't want to upgrade to newer versions for some reason.

Leave a Comment