How to insert version number into C code AND generated filename

cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert version number into C code AND generated filename

149 Views
Contributor V

Our project has a standard version numbering system with major, minor and revision numbers.  For this discussion, assume they have values 1, 2 and 3 respectively.

I'd like to define the major, minor and revision number components in a single place but with the following twist: the version number components must be accessible to the C compiler (likely defined by the pre-processor) so I can do something like this:

    write_to_flash(make_version_number(VERS_MAJOR, VERS_MINOR, VERS_REVISION));

AND also accessible to KDS/Eclipse, so I can generate an output filename of the form:

    myproj-1-2-3.sbin

I already have a pre-processor script, so I could clearly use it to take build variables and create a .h file from them, so I'd end up with:

    #ifndef SOURCE_VERSION_H
    #define SOURCE_VERSION_H

    #define VERS_MAJOR 1
    #define VERS_MINOR 2
    #define VERS_REVISION 3

    #endif

This way, I only have to define the version numbers (once) in the project's Build Variables.   Is this the recommended way to do it?  Or is there another preferred technique?

Labels (1)
0 Kudos
2 Replies

5 Views
Contributor V

Update: Wait a minute!  I thought I'd be able to insert Build Variables into the Debug Configurations dialog in order to control the C/C++ application that it looks for:

Screen Shot 2018-09-24 at 04.41.08.png

... but clearly that's not the case.  Let me add a follow-on question: How do I tell the debugger to load the C/C++ application with the filename and version #?  Is there a way to expand a Build Variable in the Debug Configurations dialog?

0 Kudos

5 Views
NXP TechSupport
NXP TechSupport

Hello Robert,

Sorry I don't really know your meaning , do you want to rename file with version number ?

If yes, how about the post-build commend:

- Add Build Variable"Newname":

pastedImage_1.png

- In Post-build, input command:

pastedImage_2.png

- Build , the new name with version number appeares:

pastedImage_3.png


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos