Why are there two buttons in the Configure and Generate GUI when the CLI does everything in one command

I understand cmake is a build generator. This means that it can create appropriate assemblies (make files, Visual Studio project, etc.) based on the instructions of CMakeLists.txt. But I do not understand two things that, I think, are related:

  • Why are there two “Configure” and “Create” buttons in cmake-gui? In the command line tutorials that I read (like this one ), the normal process was done with a single cmake command.

  • What is cache in the cmake world? AFAIK is the state when the "Configure" button was pressed, but the "Create" button was not pressed. But why is this useful? What do all the variables that appear after clicking "Settings" mean? Why should I edit them? Is allowed configuration allowed through CMakeLists.txt?

thanks

+5
source share
1 answer

There are two steps to starting CMake, which is reflected by two buttons in the CMake GUI. The first stage is the configuration stage, where the CMakeLists.txt file is read. CMake creates an internal representation of the project at this point. After this, the second stage is called generation, where project files are written based on this internal representation.

In the CMake GUI, two steps can be run separately. When you run the configuration step, the graphical interface displays all cache variables (see below) that have changed their values ​​since the last configuration was launched or from the moment the CMake GUI started, if this is the first run of configure. A common practice is to restart the setup phase until the variables are highlighted in red. After configure will not contain any variables in red, you can click the generate button, and the files of the source assembly file are created, and you can start creating your assemblies, etc.

The cmake command-line tool does not allow you to separately configure and generate steps individually. Rather, it always runs configure and then generates.

For simple projects, the distinction between configuration and generation is not so important. Simple tutorials often simply combine them together, as the reader can leave without understanding the differences for the main projects. However, there are some CMake features that rely on this difference. In particular, expressions are a function of the generation time in which decisions about some aspects of the assembly are delayed by the generation time, and are not completely processed when the time is set. One example of this is configuration-specific content such as compiler flags, source files compiled for only certain configurations, etc. The assembly configuration is not always known at the CMake setup stage (for example, Xcode and Visual Studio are tools for creating several configurations, so there can be more than one, and it is selected by the user during assembly). The generation step will process the generator expressions for each type of assembly, and the result may be different for each configuration. You can also find this answer regarding this particular example. For a more advanced example of a method using the distinction between the setup and generation steps, see this post , but keep in mind that this is not a common technique.

As for your other question about what a cache is, CMake writes information between starts in a variable cache. At the end of the run, it updates the file named CMakeCache.txt in the assembly directory. When you start CMake, it reads in this cache to pre-fill various things, so it does not need to compromise them (for example, to find libraries and other packages), and you will not need to provide custom parameters that you want to override every time. Usually you did not edit CMakeCache.txt manually (although this is all right). Rather, you can change the variables you want in the CMake GUI, and then re-run the configuration step (remember to also run the generate to create updated project files). You can also define or change cache variables on the cmake command line with the -D option.

+6
source

All Articles