21

I'm in the process of writing a build script to automate build and release tasks. I have a Qt Creator project which has three configurations, two of which I want to completely rebuild from scratch without any precompiled headers and existing .o files to skip (release and release_production). The latter is the same except it has the PRODUCTION symbol #defined.

I'm using windows. How can I build these configurations from the command line?

Edit: Some clarification: The Qt Creator custom build steps are not stored in the qmake makefile but in the Qt Creator-specific .pro.user XML file. I would like to perform these from the command line without repeating them in the script.

Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
  • Not sure if you are interested in using 3rd party tools but I have successfully used CMake for this purpose. It allows out of directory builds so I build different configurations in separate directories. You can simply setup your script to delete the directories for the "release" and "release_production" directories to ensure they are rebuilt from scratch. – user258808 May 25 '11 at 16:55

3 Answers3

17

There are two steps involved here:

  1. Running qmake to generate Makefiles. The usual command is

    c:\qt\4.7.2\bin\qmake.exe" path\to\some\project.pro -r -spec win32-g++ CONFIG+=...
    

    The -spec switch is important. Make sure you supply a valid makespec file. CONFIG needs to be specified in this step.

  2. Running make to compile and link. This is easy

    C:\MinGW32\bin\mingw32-make -f Makefile.Debug
    

    Remember to point make to the correct makefile.

Nam Nguyen
  • 1,765
  • 9
  • 13
4

In the project tab of QtCreator you have the exact command, QtCreator runs on build for both debug and release. Just run those lines in a environment your project can be build (Qt console). But basically Qt projects are build with a qmake.exe then a nmake.exe or the Qt multi-thread make-like executable jom.exe.

For your "production" mode your can use CONFIG+=production argument in the qmake command, then in your .pro files :

CONFIG(production){
DEFINES+=PRODUCTION
}else{
}
Thomas Vincent
  • 2,214
  • 4
  • 17
  • 25
  • `QtCreator --help` don't show any arguments you can pass to directly build a project like you want ... It could be a good question for the QtCreator guys. – Thomas Vincent May 26 '11 at 13:24
  • 1
    I found your suggestion of adding a production mode very interesting for compiling on a different machine than the one I program on, where libraries etc. are not in the same place. But I can't seem to make it work. I'm trying to modify ´INCLUDEPATH´ and ´DEFINES´ in the ´CONFIG(production)´ block, but when I try to compile using the generated Makefile (generated using ´qmake´ with the argument ´CONFIG+=production´), the ´INCLUDEPATH´ and ´DEFINES´ are not as I defined them. Any ideas? – Filip S. May 15 '17 at 09:56
  • Nevermind, the issues are gone after deleting the build folder completely and rebuilding from scratch. – Filip S. May 15 '17 at 11:07
2

There are a few practical details that are necessary in order to make this work.

You have to tell where the compiler & resource processor are located. Ex:

:: CL.EXE
PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64
:: RC.EXE
PATH=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64

You have to define Include and Library paths:

SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include
SET LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64

Then you can do it:

CD C:\Foo\build-your-project-Desktop_Qt_5_13_0_MSVC2017_64bit-Release
C:\Qt\Tools\QtCreator\bin\jom.exe /S -f Makefile.Release clean

C:\Qt\5.13.0\msvc2017_64\bin\qmake.exe -o Makefile ..\your-project\your-project-file.pro -spec win32-msvc "CONFIG+=qtquickcompiler"

C:\Qt\Tools\QtCreator\bin\jom.exe /S /X Build.log -f Makefile.Release

If you get errors, search for the path where the header or lib file is located, and add it to the paths. Keep repeating until all errors are gone.

Pierre
  • 4,114
  • 2
  • 34
  • 39
  • I appreciate the answer, but this is not what I was looking for. Take a look at the edit: the custom build steps that are defined in the Qt Creator xml will not be executed this way (although this was many years ago and Qt Creator might be different now... it's been a while!) – Tamás Szelei Apr 30 '21 at 21:04
  • 3
    Sorry, I was also doing this for the benefit of other poor schlubs searching for "Building Qt Creator projects from command line". – Pierre May 01 '21 at 15:25