Getting ready

Let us go back to our very first example. However, instead of having one single source file for the executable, we will now introduce a class to wrap the message to be printed out to screen. This is our updated hello-world.cpp:

#include "Message.hpp"  #include <cstdlib>#include <iostream>int main() {  Message say_hello("Hello, CMake World!");  std::cout << say_hello << std::endl;  Message say_goodbye("Goodbye, CMake World");  std::cout << say_goodbye << std::endl;  return EXIT_SUCCESS;}

The Message class wraps a string, provides an overload for the << operator, and consists of two source files: the Message.hpp header file and the corresponding Message.cpp source file. The Message.hpp interface file contains the following:

#pragma ...

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.