![]() Then open the CMakeLists.txt file with the editor of your choice and start editing it. Let's start off by creating the CMakeLists.txt file in the project directory, outside the src/ directory. In CMake you define targets and then add the necessary properties to them. Targets have properties: for example the source files required to compile the executable, the compiler options, the dependencies and so on. In our example, we want to build the source code into a binary executable: that's a target. A target is a job of the building process or, in other words, a desired outcome. Understanding the CMakeLists.txt fileĪ modern CMake's CMakeLists.txt is a collection of targets and properties. ![]() But first let's add a CMakeLists.txt file and write something meaningful in it. To make things more interesting, later on I will spice up the project with an external dependency and some parameters to pass at build stage to perform conditional compilation. ![]() A toy project to work withįor this introduction I will be using a dummy C++ project made up of few source files: myApp/ This prevents cluttering up the source directory and makes it easy to start over again: just remove the build directory and you are done. Any file required for the final build, executables included, will be stored in a separated build directory (usually called build/). This is done by the so-called generators, CMake components responsible for creating the build system files.Īnother nice CMake feature is the so-called out-of-source build. CMake will read the instructions in it and will produce the desired output. This special text file describes how the project is structured, the list of source files to compile, what CMake should generate out of it and so on. That's what the word meta stands for: CMake builds build systems.Ī project based on CMake always contains the CMakeLists.txt file. For example, CMake on Windows will produce a solution for Visual Studio CMake on Linux will produce a Makefile CMake on macOS will produce a project for XCode and so on. It doesn't actually build your source code: instead, it generates native project files for the target platform. ![]() What is CMake exactlyĬMake is known as a meta build system. Rather, just a practical, ongoing introduction to the tool for humble enthusiasts like me. Mind you, this won't be the definitive CMake bible. In the following paragraphs we will understand what CMake is exactly, its underlying philosophy and how to use it to build a demo application from scratch. In recent years it has become a de-facto standard for C and C++ applications, so the time has come for a lightweight introductory article on the subject. CMake is a collection of open-source and cross-platform tools used to build and distribute software. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |