I have a big C++ application which we are compiling through Jenkins and generating zipped artifacts containing binaries, headers, config and other relevant files. The build is deployed in the form of services on the client. The problem is how can apply version on those binaries to keep a tract of which build is deployed on which client?
Like with earlier C# application we used make changes to AssemblyVersion file with the tags that we apply on GIT and then compile and we could see the executable have the version applied. Is there a way to do the same in C++?
We are using CMakeLists.txt file for generating builds. We have linux based environment (CentOS 7.5) the application is developed in C++.
Thanks in advances!
Since you're using CMake, what you can do is use the configure_file()
function in your CMakeLists.txt to create a C++ source file which includes your Git version information as a string, then include the created file into your target.
You can get the Git version information into a CMake variable by calling the git executable from CMake, although there are prewritten modules out there to do the heavy lifting.
You can then use the command-line strings
and grep
tools to find the version string in the binary, or some other method to get it programmatically, depending on if you're making an executable or library.