...

/

Navigate the Project Files: Configuration Files and Presets

Navigate the Project Files: Configuration Files and Presets

Let's learn about the configuration files and presets of a typical CMake project.

The config-files for packages

A big part of the CMake ecosystem includes the external packages that projects can depend on. They allow developers to use libraries and tools in a seamless, cross-platform way. Packages that support CMake should provide a configuration file so that CMake understands how to use them.

Here are a few interesting details to bear in mind:

  • Config-files (original spelling) contain information regarding how to use the library binaries, headers, and helper tools. Sometimes, they expose CMake macros to use in our project.

  • Use the find_package() command to include packages.

  • CMake files describing packages are named <PackageName>-config.cmake and <PackageName>Config.cmake.

  • When using packages, we can specify which version of the package we need. CMake will check this in the associated <Config>Version.cmake file.

  • Config-files are provided by package vendors supporting the CMake ecosystem. If a vendor doesn't provide such a config-file, it can be replaced with a find-module (original spelling).

  • CMake provides a package registry to store packages system-wide and for each user.

The cmake_install.cmake, CTestTestfile.cmake, and CPackConfig.cmake files

These files are generated in the build tree by the cmake executable in the generation stage. As such, they shouldn't be edited manually. CMake uses them as a configuration for the cmake install action, CTest, and CPack. If we're implementing an in-source build (not recommended), it's probably a good idea to add them to the VCS ignore file.

...