Important: Please read the Qt Code of Conduct -

Impossible to add custom build step in Qt Creator?

  • Hello,

    I want to add a custom build step: before running qmake, I expect Qt Creator to delete the old build directory.

    I tried adding a custom build step at the first build step, with the following settings:

    command: rmdir
    arguments: /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"
    working directory: c:\

    but I get the error:
    Could not start process "rmdir" /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"
    Error while building/deploying project Test_Nano (kit: Desktop Qt 5.8.0 MSVC2015_64bit)
    When executing step "Custom Process Step"

    I tried all sorts of combinations: with/without quotes, moving the arguments to the command field, changing the working directory, ... i just won't work.

    When I use the Windows command prompt, I can successfully execute:
    C:> rmdir /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"

    so I expect to parse this by putting c:\ as working directory, rmdir as command and the rest as arguments. Why am I wrong?

  • @Gmember Maybe rmdir can't be found outside the command prompt? Is it an internal shell command or a standalone program? If it's a shell command you may have to for example create a .bat file and execute that.

  • Hi, thank you for your reply. I think you are right, I created a batch with the code:

    if exist "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug" ^
    rmdir /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"

    and it works almost fine: if the build folder doesn't exist, it creates it and it builds the project. However, if the folder does exist, the script deletes it but the compilation fails:

    14:08:07: Running steps for project Test_Nano...
    14:08:07: Starting: "C:\Users\Valerio G\Documents\Tests\Test_Nano\scripts\clean_Qt_5_8_0_MSVC2015_64bit-Debug.bat"
    C:\Users\Valerio G\Documents\Tests\Test_Nano\scripts>if exist "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug" rmdir /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug"
    14:08:07: The process "C:\Users\Valerio G\Documents\Tests\Test_Nano\scripts\clean_Qt_5_8_0_MSVC2015_64bit-Debug.bat" exited normally.
    14:08:07: Configuration unchanged, skipping qmake step.
    14:08:07: Cannot find Makefile. Check your build settings.
    Error while building/deploying project Test_Nano (kit: Desktop Qt 5.8.0 MSVC2015_64bit)
    When executing step "Make"
    14:08:07: Elapsed time: 00:01.

    For some reason it skips the qmake step, so it won't find the makefile. How can I skip the check that returns "Configuration unchanged" and force it to run qmake every time?

  • Lifetime Qt Champion

    the generated make file also lives in build folder so i think that is why it fails.

    Can I ask why u cannot just use clean from the menu?

    Also , why you want to clean it each time you build ( if i may ask)?

    Maybe you can fix it with change folder for the files and kill that instead so makefile survives

  • @mrjj Of course you can ask :) The reason is that sometimes, ater adding or removing library header files from my C++ sources I get link errors. This is due to leftovers in the build folder from the previous build, since if I delete the build directory and execute the build command again, then the project is built correctly.

    Using the clean command from the Build menu doesn't help, I guess that I have to modify the cleaning steps to make that work. But then, I would have to do both clean and build each time. I think it's better to just remove the whole build directory as a preliminary build step. My project is not very big, it builds in less than 30 seconds so I can live with that.

    Of course, I welcome suggestions from people that are more experienced than me :)

  • Lifetime Qt Champion

    super :)
    Well i like your idea but sadly i think it will kill the
    MakeFile also and then it cannot build.
    Also, the pro file is not always parsed ( again) when u press build so its not
    enough to try to clean from there.

    So you must make it create the makefile in another place so u can just nuke folder
    or simply make a bat file that kills what u want and just call that. and leave the makefile.
    The pro file becomes a make file in same folder and then you kill it :) so
    just wiping the whole folder might not work.

  • @mrjj
    I found a solution by following your advice! Now my bat script spares the makefile by only deleting the contents of the debug subdirectory:

    if exist "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\debug" ^
    erase /s /q "C:\Users\Valerio G\Documents\Tests\Test_Nano\build-Test_Nano-Desktop_Qt_5_8_0_MSVC2015_64bit-Debug\debug\*.*"

    I will make a similar script for the release build. It is sad to be forced to do this, but sometimes I found myself searching for a non existent bug in my code, all because of leftovers from previous builds, so I started using Clean all the times before building. Check my old question about this behaviour, that arose when I was trying to configure OpenCV:

    Then I discovered that in a few cases even that wasn't enough, so I started deleting the build folder every time I included a new header. This is frustrating, I want to be sure that when I get compile errors, it is because I made a mistake somewhere, not because something in the toolchain failed to detect that the build structure of the program has changed.

    Thank you very much to you and to @Eeli-K for your help :D

  • Lifetime Qt Champion

    When inside the pro file, you can ask about build mode but not sure for build steps

    (in pro)
    CONFIG(release, debug|release): DESTDIR = $$OUT_PWD/release
    CONFIG(debug, debug|release): DESTDIR = $$OUT_PWD/debug

    contains path to the build folder

Log in to reply