We will follow these steps to register the version in our template header file:
- To track the code version, we can define the project version when invoking the CMake project command in CMakeLists.txt:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(recipe-04 VERSION 2.0.1 LANGUAGES C)
- We then configure version.h, based on version.h.in:
configure_file( version.h.in generated/version.h @ONLY )
-
Finally, we define the executable and provide the target include path:
add_executable(example example.c)target_include_directories(example PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated )