Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. qmake with a custom pre build target does not compile
Forum Updated to NodeBB v4.3 + New Features

qmake with a custom pre build target does not compile

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 4 Posters 2.3k Views 2 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.
  • S Offline
    S Offline
    stvokr
    wrote on 25 Sept 2017, 10:29 last edited by
    #1

    Hi,

    I am using Qt 5.9 with msvc2015 on Windows 10.
    I am also using git.

    For my application I want to read out the current git hash ID to generate a custom version.rc file, which includes some basic information about my application. This is doing my batch script version.bat. So I have added the following lines into my pro file.

    build.target = customtarget
    build.commands = $$PWD/version.bat
    PRE_TARGETDEPS += customtarget
    QMAKE_EXTRA_TARGETS += build
    
    RC_FILE += $$PWD/version.rc
    

    Now when I want to build my app, everything works fine and the script is also doing its job, when file version.rc exist.
    But it produces an error, if the file does not exists. But this shouldn't matter, because the script will create it.
    When I call it manually and the version.rc does not exists, it is also working and the file will be created.

    dependent 'version.rc' does not exist.
    

    I also checked the working dir, everthing is fine. And I remember this has been working with qt 5.3 and below.
    What am I doing wrong?

    regards
    Oliver

    A 1 Reply Last reply 26 Sept 2017, 03:32
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Sept 2017, 11:26 last edited by
      #2

      Hi,

      Can you share the content of your version.bat script ?

      Note that RC_FILE being a qmake variable, its handling might have changed.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stvokr
        wrote on 25 Sept 2017, 12:10 last edited by
        #3

        Due to the fact that I am using the git environment I have also a verison.sh which is called by the version.bat.

        version.bat

        "C:\Program Files\Git\bin\sh.exe" --login version.sh
        

        version.sh

        #!/bin/sh
        
        File=`ls *.pro`
        Project=`echo $(basename $File .pro)`
        Date=`date +%Y`
        
        Version=0.6.0.0
        BIFile=./version.xml
        RCFile=./version.rc
        
        # generate git infos
        Dir='./'
        RevNum=`git rev-list HEAD | wc -l | tr -d ' '`
        HashID=`git log --max-count=1 | grep '^commit' | sed -e 's/commit //'`
        
        echo "<?xml version=\"1.0\"?>" > $BIFile
        echo "<BuildInfo>" >> $BIFile
        echo "	<Name>"$Project"</Name>" >> $BIFile
        echo "	<BuildVersion>"$Version"</BuildVersion>" >> $BIFile
        echo "	<BuildNumber>"$RevNum"</BuildNumber>" >> $BIFile
        echo "	<BuildID>"$HashID"</BuildID>" >> $BIFile
        echo "</BuildInfo>" >> $BIFile
        
        VersionID=`echo $Version | tr . ,`
        
        # Product Version enthält nur 2 Stellen, und die ID mit Nullen auffüllen
        Product=`expr match "$Version" "\([0-9]*.[0-9]*\)"`
        ProductID=`echo $Product | tr . ,`,0,0
        
        echo "/* This file is generated. Any changes will be discarded. */" > $RCFile
        echo "#include <windows.h>" >> $RCFile
        echo >> $RCFile
        echo "// version string for windows" >> $RCFile
        echo "#ifdef WIN32" >> $RCFile
        echo "    IDI_ICON1       ICON    DISCARDABLE     \"icon.ico\"" >> $RCFile
        echo "    VS_VERSION_INFO VERSIONINFO" >> $RCFile
        echo "    FILEVERSION     "$VersionID >> $RCFile
        echo "    PRODUCTVERSION  "$VersionID >> $RCFile
        echo "    BEGIN" >> $RCFile
        echo "        BLOCK \"StringFileInfo\"" >> $RCFile
        echo "        BEGIN" >> $RCFile
        echo "            BLOCK \"040704E4\"" >> $RCFile
        echo "            BEGIN" >> $RCFile
        echo "                VALUE \"CompanyName\",        \"xxx\"" >> $RCFile
        echo "                VALUE \"FileDescription\",    \"$Project\"" >> $RCFile
        echo "                VALUE \"FileVersion\",        \"$Version\"" >> $RCFile
        echo "                VALUE \"LegalCopyright\",     \"$Date, xxx\"" >> $RCFile
        echo "                VALUE \"OriginalFilename\",   \"$Project.exe\"" >> $RCFile
        echo "                VALUE \"ProductName\",        \"$Project\"" >> $RCFile
        echo "                VALUE \"ProductVersion\",     \"$Version\"" >> $RCFile
        echo "            END" >> $RCFile
        echo "        END" >> $RCFile
        echo >> $RCFile
        echo "        BLOCK \"VarFileInfo\"" >> $RCFile
        echo "        BEGIN" >> $RCFile
        echo "            VALUE \"Translation\", 0x0407, 0x04E4" >> $RCFile
        echo "        END" >> $RCFile
        echo "    END" >> $RCFile
        echo "#endif" >> $RCFile
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 25 Sept 2017, 22:19 last edited by
          #4

          What if you put a dummy version.rc file in your sources ?

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

          1 Reply Last reply
          1
          • S stvokr
            25 Sept 2017, 10:29

            Hi,

            I am using Qt 5.9 with msvc2015 on Windows 10.
            I am also using git.

            For my application I want to read out the current git hash ID to generate a custom version.rc file, which includes some basic information about my application. This is doing my batch script version.bat. So I have added the following lines into my pro file.

            build.target = customtarget
            build.commands = $$PWD/version.bat
            PRE_TARGETDEPS += customtarget
            QMAKE_EXTRA_TARGETS += build
            
            RC_FILE += $$PWD/version.rc
            

            Now when I want to build my app, everything works fine and the script is also doing its job, when file version.rc exist.
            But it produces an error, if the file does not exists. But this shouldn't matter, because the script will create it.
            When I call it manually and the version.rc does not exists, it is also working and the file will be created.

            dependent 'version.rc' does not exist.
            

            I also checked the working dir, everthing is fine. And I remember this has been working with qt 5.3 and below.
            What am I doing wrong?

            regards
            Oliver

            A Offline
            A Offline
            ambershark
            wrote on 26 Sept 2017, 03:32 last edited by
            #5

            @stvokr This is happening because at the point that qmake is run the version.rc file does not exist.

            I don't have a solution for you since I stopped using qmake in favor of cmake a long time ago. If you wanna switch your project to cmake I can help you. ;)

            What you need to do basically is either have qmake ignore that it is missing a file or you can generate the file before your run qmake, or lastly you can use a dummy file like @SGaist suggested.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 26 Sept 2017, 06:13 last edited by aha_1980
              #6

              @stvokr: Have you thought about a template RC file, where you just replace the Git SHA-1 with a small sed script? This should solve your problem (and maybe is a bit faster)

              Qt has to stay free or it will die.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stvokr
                wrote on 26 Sept 2017, 11:09 last edited by
                #7

                Thanks for the hints. I'll think about them.

                1 Reply Last reply
                0

                1/7

                25 Sept 2017, 10:29

                • Login

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