Reusing CMake Code
Writing build system code for a project is no easy task. Project maintainers and developers spend a lot of effort 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 these details could be reused between 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 straightforward: separate CMake code...