Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Running command when building app and using output in a DEFINE
Forum Updated to NodeBB v4.3 + New Features

Running command when building app and using output in a DEFINE

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 426 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    I am trying to run a git command to get our build information. I would like to use this in a DEFINE.

    This is what I tried:

    GITVERSIONCOM = $$system("git describe --abbrev=5 --dirty=-t")
    DEFINES += GITVERSION = $${GITVERSIONCOM}
    

    This seems property create the GITVERSION define somewhere as the IDE seems to see it. However, it gives a strange errors:
    "no macro names in #define directive" file not found <command-line>
    "macro names must be identifiers"

    My guess is I am doing this completely wrong from the getgo.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #3

      Here is a working example of exactly what you need :-) https://github.com/milosolutions/mwizardtemplate/blob/master/version.pri

      MIT-licensed so you are free to use / adapt / expand it. Works on all platforms.

      Your approach is good, you just need to add this insane amount of escape sequences (and remove the spaces around = sign.

      GITVERSIONCOM = $$system("git describe --abbrev=5 --dirty=-t")
      DEFINES += GITVERSION=\\\\\\"$$GITVERSIONCOM\\\\\\"
      

      (Z(:^

      fcarneyF 1 Reply Last reply
      4
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #2

        @fcarney said in Running command when building app and using output in a DEFINE:

        DEFINES += GITVERSION = $${GITVERSIONCOM}

        Part way there:

        DEFINES += GITVERSION=$${GITVERSIONCOM}
        

        The spacing around the equals was causing issues.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #3

          Here is a working example of exactly what you need :-) https://github.com/milosolutions/mwizardtemplate/blob/master/version.pri

          MIT-licensed so you are free to use / adapt / expand it. Works on all platforms.

          Your approach is good, you just need to add this insane amount of escape sequences (and remove the spaces around = sign.

          GITVERSIONCOM = $$system("git describe --abbrev=5 --dirty=-t")
          DEFINES += GITVERSION=\\\\\\"$$GITVERSIONCOM\\\\\\"
          

          (Z(:^

          fcarneyF 1 Reply Last reply
          4
          • sierdzioS sierdzio

            Here is a working example of exactly what you need :-) https://github.com/milosolutions/mwizardtemplate/blob/master/version.pri

            MIT-licensed so you are free to use / adapt / expand it. Works on all platforms.

            Your approach is good, you just need to add this insane amount of escape sequences (and remove the spaces around = sign.

            GITVERSIONCOM = $$system("git describe --abbrev=5 --dirty=-t")
            DEFINES += GITVERSION=\\\\\\"$$GITVERSIONCOM\\\\\\"
            
            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #4

            @sierdzio I got it working. Interestingly enough, if I used the 6 slashes on each side it would eat the "s out of the Makefile. I ended up doing this:

            GITVERSIONCOM = $$system(git describe --abbrev=5 --dirty=-t)
            COMPILETIMECOM = $$system(date +%s%3N)
            DEFINES += GITVERSION=\\\"$$GITVERSIONCOM\\\"
            DEFINES += COMPILETIME=$$COMPILETIMECOM
            

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Hi,

              You might want to consider an alternative, you could generate a header based on a template that you fill with the variables you want. That would avoid these escaping that can change for different platform.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              fcarneyF 1 Reply Last reply
              2
              • SGaistS SGaist

                Hi,

                You might want to consider an alternative, you could generate a header based on a template that you fill with the variables you want. That would avoid these escaping that can change for different platform.

                fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #6

                @SGaist
                I decided to go that route and have it build based upon platform:

                versiondata.target = buildinfo.h
                unix:versiondata.commands = $$PWD/create_buildinfo
                versiondata.depends = FORCE
                QMAKE_EXTRA_TARGETS += versiondata
                PRE_TARGETDEPS += buildinfo.h
                

                I have a command called create_buildinfo that makes buildinfo.h.
                To add platforms I just add win32: or whatever and create different commands.

                C++ is a perfectly valid school of magic.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved