Navigate the Project Files: Directory Structure and Cache Variable
Let's learn about the directory structure and cache variables of a typical CMake project.
We'll cover the following
CMake uses quite a few files to manage its projects. Let's attempt to get a general idea of what each file does before tinkering with the contents. It's important to realize that even though a file contains CMake language commands, it's not certain that it's meant for developers to edit:
Some files are generated to be used by subsequent tools, and any changes made to those files will be written over at some stage.
Other files are meant for advanced users to adjust the project according to their individual needs.
Finally, there are some temporary files that provide valuable information in specific contexts.
This lesson will also specify which of them should be in the ignore file of our version control system.
The source tree
This is the directory where our project will live (it is also called the project root). It contains all of the C++ sources and CMake project files.
Here are the key takeaways of this directory:
It is required that we provide a
CMakeLists.txt
configuration file in its top directory.It should be managed with a
such as git.VCS Version Control Software (VCS) is a tool that enables developers to manage and track changes to source code and files, facilitating collaboration, history tracking, and the ability to revert to previous versions when needed. The path to this directory is given by the user with a
-S
argument of thecmake
command.Avoid hardcoding any absolute paths to the source tree in the CMake code—users of our software can store the project under a different path.
The build tree
CMake uses this directory to store everything that gets generated during the build, including:
Get hands-on with 1400+ tech skills courses.