Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

A simple CMake script to implement automatic build number incrementation.

License

Notifications You must be signed in to change notification settings

nandee95/Auto_Build_Number_Increment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description:

This script generates a header file contains the recent build build number as a macro. This is a platform and compiler independent solution The code also contains basic error checking and provides feedback at the build console.

Supported languages:

Language Header extension Default header filename
CChbuild_number.h
C++CXXhppbuild_number.hpp
/Pull requests for extending the language support are welcome/

Basic usage:

Using the default values... Note that the following is a minimal C/C++ example. You can find more complete examples in the examples directory.

1. Setting up CMake

Copy build_number.cmake to your source directory and add this code to your CMakeLists.txt (don't forget to specify the target)
add_custom_command(
	TARGET project_name_goes_here
	PRE_BUILD
	COMMAND ${CMAKE_COMMAND}
		-DLANGUAGE:STRING="C"
		-DHEADER_DIR:PATH="${CMAKE_SOURCE_DIR}"
		-DCACHE_DIR:PATH="${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"
		-P "${MASTER_DIR}/build_number.cmake"
)
Add build_number.h to your target. And create a blank build_number.h in your source directory otherwise CMake wont configure.

2. Adding build number to the project

Include the generated header in your source:
#include "build_number.h"
Use the BUILD_NUMBER macro in your code.

Altering default values:

Possible inputs

NameTypeRequiredDefault valueDescription
LANGUAGESTRINGYes-Defines the used language. (This information is used to determine the header's extension.)
HEADER_DIRPATHYes-Specifies a path for the header.
HEADER_FILENAMESTRINGNobuildnumberAlters the default filename for the header.
The extension depends on the determined language. No extension needed here.
HEADER_MACROSTRINGNoBUILD_NUMBERAlters the default macro's name in the header.
CACHE_DIRPATHYes-Specifies the path for the cache file.
CACHE_FILENAMESTRINGNoCMakeBuildNumber.txtAlters the default filename for the cache file.

Altering values

Warning: -P always has to be on the last place!

You can define them by adding more parameters to the command. For more information check the documentation of add_custom_command. The following is an example where all of the possible parameters are defined/altered:

add_custom_command(
	TARGET project_name_goes_here
	PRE_BUILD
	COMMAND ${CMAKE_COMMAND}
		-DLANGUAGE:STRING="CXX"
		-DHEADER_DIR:PATH="${CMAKE_SOURCE_DIR}/Build"
		-DCACHE_DIR:PATH="${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/Caches"
		-DHEADER_FILENAME:STRING="BuildNo"
		-DCACHE_FILENAME:STRING="BuildNo.cache"
		-DHEADER_MACRO:STRING="BUILDNO"
		-P "${CMAKE_SOURCE_DIR}/build_number.cmake"
)

License:

MIT license

About

A simple CMake script to implement automatic build number incrementation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages