We will start with a file called VERSION, containing the following:
2.0.1-rc-2
This time, we will choose to go for more type safety, and will define PROGRAM_VERSION as a string constant in version.hpp.in:
#pragma once #include <string>const std::string PROGRAM_VERSION = "@PROGRAM_VERSION@";
We will include the generated version.hpp in the following example source code (example.cpp):
// provides PROGRAM_VERSION#include "version.hpp"#include <iostream>int main() { std::cout << "This is output from code v" << PROGRAM_VERSION << std::endl; std::cout << "Hello CMake world!" << std::endl;}