Nominate our 2022 Qt Champions!

qmake with a custom pre build target does not compile

  • 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. = customtarget
    build.commands = $$PWD/version.bat
    PRE_TARGETDEPS += customtarget
    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?


  • Lifetime Qt Champion


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

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

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


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

    File=`ls *.pro`
    Project=`echo $(basename $File .pro)`
    Date=`date +%Y`
    # generate git infos
    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 "    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

  • Lifetime Qt Champion

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

  • @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.

  • Lifetime Qt Champion

    @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)

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

Log in to reply