PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 26, 2022

[FIXED] How can we apply versioning to executable/binaries in C++?

 September 26, 2022     binaries, c++, cmake     No comments   

Issue

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!


Solution

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.



Answered By - aiusepsi
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing