Chapter 13: Reusing CMake Code
Writing build system code for a project is no easy task. Project maintainers and developers are spending a lot of effort on writing CMake code for configuring compiler flags, project build variants, third-party libraries, and tool integrations. Writing CMake code for project-agnostic details from scratch may start to incur a significant burden when dealing with multiple CMake projects. Most of the CMake code written for a project to configure the aforementioned details could be reused between the projects. With that in mind, it is for our benefit to develop a strategy to make our CMake code reuse-friendly. The straightforward way to approach this problem is to treat CMake code as regular code and apply some of the most basic coding principles: the Don't Repeat Yourself (DRY) principle and the Single Responsibility Principle (SRP).
CMake code can be easily reused if structured with reusability in mind. Achieving essential reusability is pretty...