Skip to content

Seamlessly integrate git version tags into your CMake project

License

Notifications You must be signed in to change notification settings

sethrj/cmake-git-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake Git Version

Seamlessly integrate git version tags into your CMake project. Inspired by Versioneer for Python projects.

This small CMake script ensures that your project's internal version metadata is always up-to-date with Git version data, whether your repository is cloned or exported as a source tarball via the GitHub release mechanism.

Installation

A tiny installation script copies the files in the cmake directory to your project's CMake directory and configures the gitattributes file.

$ ./install.sh /path/to/myproject/cmake
-- Copied script to /path/to/myproject/cmake/CgvFindVersion.cmake
-- Updated /path/to/myproject/cmake/.gitattributes

Usage

Typically you will want to use the exported version metadata from CGV to inform CMake of your project's version:

include("${CMAKE_CURRENT_LIST_DIR}/cmake/CgvFindVersion.cmake")
cgv_find_version(MyProject)

project(MyProject VERSION "${MyProject_VERSION}" LANGUAGES CXX)

CMake will parse the supplied version number into major/minor/patch versions that can be used by a config.h.in file:

static const char myproject_version[] = "@MyProject_VERSION_STRING@";
static const int myproject_version_major = @PROJECT_VERSION_MAJOR@;
static const int myproject_version_minor = @PROJECT_VERSION_MINOR@;
static const int myproject_version_patch = @PROJECT_VERSION_PATCH@;

which will let CMake generate a header file:

configure_file("config.h.in" "MyProject_config.h" @ONLY)

You can test the version information by running CMake from the command line:

cmake -P cmake/CgvFindVersion.cmake

About

Seamlessly integrate git version tags into your CMake project

Resources

License

Stars

Watchers

Forks

Packages

No packages published