Creating utilities for CMake projects
In this recipe, we will see how CMake is used to configure all the code examples in this book and learn some small tricks along the way.
Note
For those who are just starting with CMake, we recommend reading the books CMake Cookbook (Radovan Bast and Roberto Di Remigio), Packt Publishing and Mastering CMake (Ken Martin and Bill Hoffman), Kitware.
Getting ready
For a starter, let's create a minimalistic C++ application with a trivial main()
function and build it using CMake:
int main() { Â Â return 0; }
How to do it...
Let's introduce two helper macros for CMake. You can find them in the CMake/CommonMacros.txt
file of our source code bundle:
- The
SETUP_GROUPS
macro iterates over a space-delimited list of C and C++ files, whether it is a header or source file, and assigns each file into a separate group. The group name is constructed based on the path of each individual file. This way we end up with a...