Getting ready

The code from Chapter 1, From a Simple Executable to Libraries, Recipe 3, Building and linking shared and static libraries, is used almost unaltered: we will only add a dependency on the UUID library. This dependency is conditional, and if the UUID library is not found, we will exclude the code using it via the preprocessor. The code is properly organized into its own src subdirectory. The layout of the project is as follows:

.├── CMakeLists.txt├── src│   ├── CMakeLists.txt│   ├── hello-world.cpp│   ├── Message.cpp│   └── Message.hpp└── tests    └── CMakeLists.txt

We can already see that we have a root CMakeLists.txt with one leaf under the src subdirectory and another under the tests subdirectory.

The Message.hpp header file contains ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.