Umang Mukesh Mehta Umang Mukesh Mehta - 3 months ago 14
Linux Question

How to find the application version for both windows and linux from within application

I am familiar with

for windows. I am looking for a solution which is platform independent .I am using boost so preferably something in boost that can be used for both the platforms.
I have read a similar question which was windows focused.


Since you're trying to get the executable's own version, why not just add a #define? For example:


// include guards etc.
#define MY_PROGRAM_VERSION "1.2.3"

To pull the version from your CMakeLists.txt rather than hardcoding, try this:


// include guards etc.


cmake_minimum_required(VERSION 3.0) # Use higher if you need, lower won't work.

project(test VERSION 1.2.3) # The one and only place where you define your version!

configure_file(version.h.template version.h)

I assume you have something like that project(...) line already, to configure the version. Among others, it sets a CMake variable named PROJECT_VERSION.

The configure_file call takes the template, fills in variables that CMake knows about, and writes the output to version.h, which you can #include normally. When either the version or the template changes, CMake will regenerate the file.