0

How to have an auto incrementing build version number in KDevelop?

I would like to set up a semi-automatic versioning for my local projects in .

Something like:

int MajorVersion = 1;  // this manual 
int MinorVersion = 2;  // this manual
int Revision = 42;     // this automatically increased each time I compile

When I compile, it would auto-increment just the Revision field.

Is this feature hidden somewhere in the settings and are those value maybe accessible from the system (mainly Linux, but all in general) or have they to be user implemented?

Note that I'm searching for solution inside , or in case not yet allowed for a simple method usable from commandline compiling and then importable in KDevelop.
I'm not searching solution for VisualStudio, as many answers offer from some similar questions [1],[2]....

Community
  • 1
  • 1
Hastur
  • 2,470
  • 27
  • 36
  • That's not a question for the IDE, that's a question for the build system in use. Which build system are you using? – kfunk Feb 17 '17 at 08:56
  • @kfunk `cmake`. It seems kdevelop with c++ uses by default CMake... BTW I remember many years ago that with Visual Studio this was a feature integrated in the IDE (at the time of VB6, even if I cannot recall if was self-updating). Then it was possible to rescue those information in the executable file (right click, information)... so I was thinking that nowadays it was possible to find a similar feature in kdevelop too. Is there any standard in this direction? – Hastur Feb 17 '17 at 09:19

1 Answers1

3

This has little to do with IDE you are using. It is rather buildsystem thing. If you are using CMake, I imagine something like this:

if(NOT BUILD_REVISION)
  set(BUILD_REVISION 0 CACHE STRING "")
else()
  math(EXPR BUILD_REVISION "${BUILD_REVISION} + 1")
endif()

add_definitions(-DBUILD_REVISION=${BUILD_REVISION})

And then in the code

int Revision = BUILD_REVISION;
arrowd
  • 33,231
  • 8
  • 79
  • 110
  • Thanks for the hints. I will try to use with Kdevelop. – Hastur Feb 17 '17 at 08:58
  • 1
    Note: This will recompile all your code whenever BUILD_REVISION changes -- better use a dedicated file (let's call it version.h) which contains the version string. See this how to: http://brianmilco.blogspot.de/2012/11/cmake-automatically-use-git-tags-as.html -- just include version.h where you need it then – kfunk Feb 20 '17 at 13:33