Here’s how src/CMakeLists.txt looks: add_executable(example_exe main.cpp) It’s actually a bit more complex, but it’s okay to think about it as “include” at the beginning.įor example, if you have an examples directory, it’s good to have a examples/CMakeLists.txt which will just be a bunch of add_subdirectory calls for each sub-directory and example/some_example/CMakeLists.txt will be a build script which contains information on how to build some_example. ![]() I’ve seen a lot of people getting VERSION from a current Git tag or some changelog file, but we’ll not go here in this tutorial.Īdd_subdirectory() is like an “include” and can be thought of as an inclusion of /CMakeLists.txt into another CMake file. It can be used to generate “version” headers (see Generate Export Header), write some output in a terminal and so on. VERSION option specifies a current version of your project. ![]() If you’re doing C or C++ project, it’s optional to specify it, but it’s still useful as a “meta-data” for people who’re reading your CMake build. By default it’s C and CXX, but there are a lot of other options available for you (like CUDA or Fortran). LANGUAGES option in a project call defines a language which your project uses so that CMake knows what kind of builds to generate. it can run unit tests, linters and so on). The target can be an executable, a library or even something which doesn’t produce any files after it’s built (e.g. One project can have multiple “targets” (which roughly correspond to “projects” in VS). The project is similar to a concept of “solution” in Visual Studio terminology. 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.Īfter cmake_minimum_required, we have a project declaration: project(example Another way of choosing is to look at other popular libraries and choose the same version.įor example, JSON for modern C++ and fmt use CMake 3.1. You can find the version of CMake that is available for various distros here. If you’re writing a library, it’s better to stick to the lowest version of CMake that makes sense for you. 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. The first line sets up a required minimal version of CMake which can be used to build the project. It’s simple: cmake_minimum_required(VERSION 3.15) Let’s start with a CMakeLists.txt from a root directory. ![]() Some notes about libraries which don’t behave wellįirst, let’s create a bunch of files and directories so that we have a structure like this.Using FetchContent with local source directories.Adding Dear ImGui and ImGui-SFML as dependencies.
3 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |