Add build date/time (and maybe repository revision) information to compiled binary

Hi,

I want to add some build information (hard coded) into my binary. Is there any way how I can access the current date/time and maybe the revision number of a SVN repository during the build process and use this information to initialize a constant variable/string in flash memory?

If I remember correctly, one of our old projects, using IAR Embedded Workbench, auto-generated an include file which provided macros for variable initialization during compilation (before compilation started). Can Visual Studio Code and the nRF Connect plugin do this, too?

Best regards,
Michael

  • Hi Einar,

    I agree when it comes to official releases. But sometimes, we just work with developer builds, and a pristine build on my project needs about three minutes on my notebook (even though I have an "expensive" DELL SSD in it...)

    While I can understand the issue with the time/date macros being related to a pristine build (even though I believe it would be possible to update them in a non-pristine build, too), I think it is a problem if a pre-build action does not affect the code being compiled in the same build process: Let us just assume that instead of some svn information, the pre-build action would execute a code generation script that provides some header files with updated code. If this information is not included in the generated binary, and I have to perform one more build step (and I'm talking about one more non-pristine build), I think this should be considered a bug.

    Are there probably more options to use the add_custom_target() and add_dependencies() calls, to better define during which build step the action is performed? So that it can be considered a 100% pre-build action, just like in other development environments? Or could it be an issue that in CMakeLists.txt, only the .c files are tracked explicitly, so that header files are not tracked as well for changes?

    Best regards,
    Michael

  • Hi Michael,

    The build system detects if header files have changed, but it seems you are right that the operation that updates your header file happens too late. I have not been able to find a way aroudn this  directly. In this case, perhaps it would be better to wrap your own script around this that first updates the version header file, and then calls west to build the project? You can bind this to build in nRF Connect for VS code so that the IDE experience remains the same.

    Einar

Related