hello.cpp
#include <iostream>
#include "hello.h"
int main(int argc, char** argv)
{
if (argc < 2) {
// report version
std::cout << argv[0] << " Version " << HELLO_VERSION_MAJOR << "."
<< HELLO_VERSION_MINOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(helloworld VERSION 1.0)
configure_file(hello.h.in hello.h)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(helloworld hello.cpp)
target_include_directories(helloworld PUBLIC
"${PROJECT_BINARY_DIR}"
)
hello.h.in
#define HELLO_VERSION_MAJOR @helloworld_VERSION_MAJOR@
#define HELLO_VERSION_MINOR @helloworld_VERSION_MINOR@