23:07
:05
2019
Update define BUILD_NUMBER inside c++ source code
- Resume:
Small script to easily update BUILD_NUMBER inside a file send as parameter (Qt creator example furnished, you can also use it with VS - Pre-Build Event or others).
- Version:
1.0.0
- Size:
3kb
- Download:
[ cmd + script ]
- License:
MIT License
- Copyrights:
Renan Lavarec
I wanted to have a build number, I made a script for it :)

Update BUILDNUMBER inside VersionInfos.h

Small script to easily update BUILD_NUMBER inside a file send as parameter (Qt creator example furnished, you can also use it with VS - Pre-Build Event or others)

Requires

  • Python 3

How to use it with Qt

  • Edit your .pro file and add thoses lines.

This will update your file where the define var BUILD_NUMBER lies.

You can edit PRE_BUILD_FILE to add your file name and the path to the script.


# Example is provided with a modified version of the post of Michael Soukup added a comment - 23 Apr '14 4:47 PM 
# url: https://bugreports.qt.io/browse/QTBUG-30224

## Update VersionInfos.h ##
PRE_BUILD_FILE = $$shell_quote($$shell_path("$$PWD/../../_tools/python_utils/tr.update_build_number/tr.update_build_number.cmd")) --versionFile $$shell_quote($$shell_path("$$PWD/VersionInfos.h"))

# Debug
#message(PRE_BUILD_FILE: $$PRE_BUILD_FILE)

    # must use variable as input, not file list
    PHONY_DEPS = .
    PreBuildEvent.input = PHONY_DEPS
    # use non-existing file here to execute every time
    PreBuildEvent.output = phony.txt
    # the system call to the batch file
    PreBuildEvent.commands = call $$PRE_BUILD_FILE
    # some name that displays during execution
    PreBuildEvent.name = running Pre-Build steps...
    # no_link tells qmake we don�t need to add the output to the object files for linking, and no clean means there is no clean step for them.
    # target_predeps tells qmake that the output of this needs to exist before we can do the rest of our compilation.
    PreBuildEvent.CONFIG += no_link no_clean target_predeps
    # Add the compiler to the list of 'extra compilers'.
    QMAKE_EXTRA_COMPILERS += PreBuildEvent