The code for this recipe is available at https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-07/recipe-02. The recipe is valid with CMake version 3.5 (and higher) and has been tested on GNU/Linux, macOS, and Windows.
Projects typically start with a single CMakeLists.txt file, but over time this file grows and in this recipe we will demonstrate one mechanism for splitting CMakeLists.txt up into smaller units. There are several motivations for splitting up CMakeLists.txt into modules that can be included in the main CMakeLists.txt or other modules:
- The main CMakeLists.txt is easier to read.
- CMake modules can be reused in other projects.
- In combination with functions, modules can help us limit the scope of variables.
In this recipe, we will demonstrate how to define and include a macro that allows us to get colored CMake output (for...