I am learning CMake and I am having problems in understanding its multi-step workflow. So far, my understanding is that you:
CMakeLists.txt
cmake
from a subdirectory to generate a build file (a Makefile, in my case)make
However, I don't understand how you should handle different targets (Release vs Debug). By running CMake in two different subdirectories?
Also, I don't understand why you would edit CMakeCache.txt
(there is also a GUI tool for that). To emulate what you would accomplish with ./configure
by passing different options?
CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.
CMake is a build generator while Ninja is a build tool. CMake can use any build tool like Make or Ninja while Ninja has to use CMake as its build generator which is compulsory. CMake was developed in 2000 by Kitware. On the other hand, Ninja was developed by Google in 2012 that is 12 years after CMake.
Running CMake from the command line From the command line, cmake can be run as an interactive question and answer session or as a non-interactive program. To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.
CMake is a better build system than Visual Studio projects and solutions. It is compact and much more easier to maintain even for Windows only projects. See CMake for Visual Studio Developers for some reasons.
You got it pretty much right. The write CMakeLists.txt
> cmake
> make
sequence is correct.
Regarding different configurations (Debug vs. Release), you have to differentiate between multi-config generators (Visual Studio, XCode), and single-config generators (everything else). With the multi-config generators, you generate one buildsystem (e.g. solution file) which contains all configurations, and choosing between them happens at build time.
With single-config generators, different configurations are obtained by generating different buildsystems, that is, by running CMake multiple times in different directories (and with a different value of the CMAKE_BUILD_TYPE
CMake variable).
So you'd do something like this:
> cd my_project/bld/debug
> cmake ../../src -DCMAKE_BUILD_TYPE=Debug
> cd ../release
> cmake ../../src -DCMAKE_BUILD_TYPE=Release
Regarding editing the cache (usually through CMake GUI or ccmake
): you're right again, this largely corresponds to passing options to ./configure
from AutoMake world. This would be the typical workflow with a freshly downloaded project (using CMake GUI):
What @Angew said. Plus here's an image of the cmake-gui
:
Also note that you install it (the CMake GUI) on Ubuntu with sudo apt install cmake-qt-gui
, and you run it with cmake-gui
.
Source: Where is the CMake GUI for Linux?
Here's my cmake-gui
image:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With