-
Notifications
You must be signed in to change notification settings - Fork 18
Adding a Version Number from a Configured Header File
Felipe Torrezan edited this page Oct 6, 2025
·
6 revisions
This interactive example describes how to consume the project()'s version in your source code. This example will print out the project version.
A CMake project example is provided at examples/version:
| Project files |
|---|
CMakeLists.txt |
version.h.in |
main.c |
The main() function will print out the project version taken from version.h, provided by CMake at configure-time.
- Perform the following tasks on
CMakeLists.txt(click to show/hide answers):
TODO 1: Add the project()'s VERSION and set it to 2.7.1
project(Project LANGUAGES C VERSION 2.7.1)TODO 2: Configure version.h.in to generate version.h
configure_file(version.h.in version.h)TODO 3: Add the Project Binary Directory to the target's include directories
target_include_directories(version PUBLIC "${PROJECT_BINARY_DIR}")- Perform the following task on
version.h.in(click to show/hide answers):
TODO 4: Define the C macros with the CMake placeholders for version
#define Project_VERSION_MAJOR @Project_VERSION_MAJOR@
#define Project_VERSION_MINOR @Project_VERSION_MINOR@
#define Project_VERSION_PATCH @Project_VERSION_PATCH@- Finally build and test the project. Refer to the tutorial for more information.
This is the cmake-tutorial wiki. Back to Wiki Home
- IAR Compiler options in a CMake project
- IAR ILINK options in a CMake project
- Language-specific target options
- Selecting build types
- Using Ninja Multi-Config
- Filing a build log
- Multi-file compilation
- Invoking IAR binary utilities
- Use the IAR ELF Tool to convert executable targets to their binary formats